From 5d949bc00a0defb5c523aa4eede0cd84154b8c22 Mon Sep 17 00:00:00 2001 From: JamieDanielson Date: Thu, 19 Sep 2024 17:41:26 -0400 Subject: [PATCH] wip: add semconv stability opt-in logic --- .../src/instrumentation.ts | 59 ++++++++++++++++--- .../src/types.ts | 15 +++++ .../test/helper.ts | 2 + 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts index 139c83ee012..9a1aa048021 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts @@ -41,8 +41,10 @@ import type { metadataCaptureType, } from './internal-types'; import type { GrpcInstrumentationConfig } from './types'; +import { SemconvStability } from './types'; import { + Attributes, context, propagation, ROOT_CONTEXT, @@ -51,6 +53,7 @@ import { trace, Span, } from '@opentelemetry/api'; +import { getEnv } from '@opentelemetry/core'; import { InstrumentationNodeModuleDefinition, InstrumentationBase, @@ -92,9 +95,21 @@ import { VERSION } from './version'; export class GrpcInstrumentation extends InstrumentationBase { private _metadataCapture: metadataCaptureType; + private _semconvStability = SemconvStability.OLD; + constructor(config: GrpcInstrumentationConfig = {}) { super('@opentelemetry/instrumentation-grpc', VERSION, config); this._metadataCapture = this._createMetadataCapture(); + + for (const entry in getEnv().OTEL_SEMCONV_STABILITY_OPT_IN) { + if (entry.toLowerCase() === 'http/dup') { + // http/dup takes highest precedence. If it is found, there is no need to read the rest of the list + this._semconvStability = SemconvStability.DUPLICATE; + break; + } else if (entry.toLowerCase() === 'http') { + this._semconvStability = SemconvStability.STABLE; + } + } } init() { @@ -328,7 +343,11 @@ export class GrpcInstrumentation extends InstrumentationBase