From 21a27d2f3c6b238a6046dcbd2995a5e5f6e0424a Mon Sep 17 00:00:00 2001 From: Matt Stover Date: Wed, 10 Jan 2024 11:14:31 -0800 Subject: [PATCH] fix: use OTEL env vars for service name and namespace --- server/dev-server.js | 2 +- server/index.js | 2 +- server/util/tracer.js | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/dev-server.js b/server/dev-server.js index f73d729e72..2b1e5b051a 100644 --- a/server/dev-server.js +++ b/server/dev-server.js @@ -3,7 +3,7 @@ require('../build/check-versions')(); const { setupTracing } = require('./util/tracer'); -setupTracing('ui'); +setupTracing(); // dependencies require('dotenv').config({ path: '/etc/kiva-ui-server/config.env' }); diff --git a/server/index.js b/server/index.js index 0362debf9d..656c658303 100644 --- a/server/index.js +++ b/server/index.js @@ -3,7 +3,7 @@ require('dotenv').config({ path: '/etc/kiva-ui-server/config.env' }); // eslint-disable-next-line import/order const { setupTracing } = require('./util/tracer'); -setupTracing('ui'); +setupTracing(); const cluster = require('cluster'); const http = require('http'); diff --git a/server/util/tracer.js b/server/util/tracer.js index 441e8a4e6c..a2eba7e527 100644 --- a/server/util/tracer.js +++ b/server/util/tracer.js @@ -44,12 +44,13 @@ function ignoreTheseSpans(spanName, spanKind, attributes) { return spanKind !== opentelemetry.SpanKind.SERVER; } -function setupTracing(serviceName) { +function setupTracing() { + const serviceName = process.env?.OTEL_SERVICE_NAME || 'ui'; if (!otlpDisabled) { const provider = new NodeTracerProvider({ resource: new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: serviceName, - [SemanticResourceAttributes.SERVICE_NAMESPACE]: 'kiva', + [SemanticResourceAttributes.SERVICE_NAMESPACE]: process.env?.OTEL_SERVICE_NAMESPACE || 'kiva', }), sampler: filterSampler(ignoreTheseSpans, new AlwaysOnSampler()), });