From 1eb145d115478557c6711a399609a16b52c0fc75 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 9 Apr 2024 18:30:16 +0200 Subject: [PATCH] feat(sdk-trace): add option to opt-out from merging the resource with Resource.default() --- .../opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts | 6 +++++- packages/opentelemetry-sdk-trace-base/src/config.ts | 1 + packages/opentelemetry-sdk-trace-base/src/types.ts | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts b/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts index c06f5cdcb61..0b3174767a5 100644 --- a/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts +++ b/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts @@ -80,7 +80,11 @@ export class BasicTracerProvider implements TracerProvider { reconfigureLimits(config) ); this.resource = mergedConfig.resource ?? Resource.empty(); - this.resource = Resource.default().merge(this.resource); + + if (mergedConfig.mergeResourceWithDefaults) { + this.resource = Resource.default().merge(this.resource); + } + this._config = Object.assign({}, mergedConfig, { resource: this.resource, }); diff --git a/packages/opentelemetry-sdk-trace-base/src/config.ts b/packages/opentelemetry-sdk-trace-base/src/config.ts index 3448b793dad..7f06840e18c 100644 --- a/packages/opentelemetry-sdk-trace-base/src/config.ts +++ b/packages/opentelemetry-sdk-trace-base/src/config.ts @@ -54,6 +54,7 @@ export function loadDefaultConfig() { attributePerLinkCountLimit: getEnv().OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT, }, + mergeResourceWithDefaults: true, }; } diff --git a/packages/opentelemetry-sdk-trace-base/src/types.ts b/packages/opentelemetry-sdk-trace-base/src/types.ts index 99eeedbe817..64ae3b206bb 100644 --- a/packages/opentelemetry-sdk-trace-base/src/types.ts +++ b/packages/opentelemetry-sdk-trace-base/src/types.ts @@ -34,6 +34,12 @@ export interface TracerConfig { /** Span Limits */ spanLimits?: SpanLimits; + /** + * Merge resource with {@link Resource.default()}? + * Default: {@code true} + **/ + mergeResourceWithDefaults?: boolean; + /** Resource associated with trace telemetry */ resource?: IResource;