fix(backend): use string resource attribute keys instead of semantic-conventions named exports
Run Tests on Branches / Detect Changes (push) Successful in 13s
Run Tests on Branches / Frontend Tests (push) Has been cancelled
Run Tests on Branches / Frontend Mobile Tests (push) Has been cancelled
Run Tests on Branches / Backend Tests (push) Has been cancelled

The resolved @opentelemetry/semantic-conventions version in CI does not
export ATTR_SERVICE_NAMESPACE/ATTR_SERVICE_NAME as named exports, breaking
the backend test import. Use plain 'service.name'/'service.namespace'
string keys so the code is independent of the semantic-conventions version.
This commit is contained in:
Antoni Nuñez Romeu
2026-07-13 16:35:45 +02:00
parent b8b8655634
commit 1318243841
+6 -5
View File
@@ -14,20 +14,21 @@ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentation
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import * as resources from '@opentelemetry/resources'; import * as resources from '@opentelemetry/resources';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_NAMESPACE } from '@opentelemetry/semantic-conventions';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino'; import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
const serviceName = process.env.OTEL_SERVICE_NAME || 'farmaclic-backend'; const serviceName = process.env.OTEL_SERVICE_NAME || 'farmaclic-backend';
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4317'; const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4317';
// Use plain string attribute keys (not the semantic-conventions named exports)
// so we don't depend on a specific @opentelemetry/semantic-conventions version.
const resource = typeof resources.resourceFromAttributes === 'function' const resource = typeof resources.resourceFromAttributes === 'function'
? resources.resourceFromAttributes({ ? resources.resourceFromAttributes({
[ATTR_SERVICE_NAME]: serviceName, 'service.name': serviceName,
[ATTR_SERVICE_NAMESPACE]: 'farmaclic', 'service.namespace': 'farmaclic',
}) })
: new resources.Resource({ : new resources.Resource({
[ATTR_SERVICE_NAME]: serviceName, 'service.name': serviceName,
[ATTR_SERVICE_NAMESPACE]: 'farmaclic', 'service.namespace': 'farmaclic',
}); });
// Metrics → OTLP → Alloy → Prometheus remote_write. The PeriodicExportingMetricReader // Metrics → OTLP → Alloy → Prometheus remote_write. The PeriodicExportingMetricReader