From 49f14889b83d83eacf07e972ab27301903e0542c Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 19 Nov 2022 17:39:35 +0000 Subject: [PATCH] Add service name for tracing --- package.json | 1 + src/tracing.ts | 7 +++++++ yarn.lock | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ccd9e55..ca7a7eb 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@opentelemetry/auto-instrumentations-node": "^0.35.0", "@opentelemetry/exporter-trace-otlp-grpc": "^0.34.0", "@opentelemetry/sdk-node": "^0.34.0", + "@opentelemetry/semantic-conventions": "^1.8.0", "@prisma/client": "^4.0.0", "@sentry/node": "^7.7.0", "@sentry/tracing": "^7.7.0", diff --git a/src/tracing.ts b/src/tracing.ts index beb2d23..e7a319a 100644 --- a/src/tracing.ts +++ b/src/tracing.ts @@ -4,6 +4,8 @@ import * as opentelemetry from '@opentelemetry/sdk-node'; import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'; +import { Resource } from '@opentelemetry/resources'; +import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import process from 'process'; diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); @@ -13,6 +15,11 @@ const sdk = new opentelemetry.NodeSDK({ url: process.env.OPENTELEMETRY_OTLP_URI, headers: {} }), + resource: new Resource({ + [SemanticResourceAttributes.SERVICE_NAME]: 'bayshore', + [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: + process.env.NODE_ENV !== undefined ? process.env.NODE_ENV : 'development', + }), instrumentations: [getNodeAutoInstrumentations()] }); diff --git a/yarn.lock b/yarn.lock index 3a84cb5..a523905 100644 --- a/yarn.lock +++ b/yarn.lock @@ -686,7 +686,7 @@ "@opentelemetry/sdk-trace-base" "1.8.0" semver "^7.3.5" -"@opentelemetry/semantic-conventions@1.8.0", "@opentelemetry/semantic-conventions@^1.0.0": +"@opentelemetry/semantic-conventions@1.8.0", "@opentelemetry/semantic-conventions@^1.0.0", "@opentelemetry/semantic-conventions@^1.8.0": version "1.8.0" resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.8.0.tgz#fe2aa90e6df050a11cd57f5c0f47b0641fd2cad3" integrity sha512-TYh1MRcm4JnvpqtqOwT9WYaBYY4KERHdToxs/suDTLviGRsQkIjS5yYROTYTSJQUnYLOn/TuOh5GoMwfLSU+Ew==