opentelemetry-js
opentelemetry-js copied to clipboard
@opentelemetry/sdk-trace-base - Avoid merging Resource Attributes by default on BasicTracerProvider
- [x] This only affects the JavaScript OpenTelemetry library
Motivation
Hello, there!
On the past few months we've been working with OTel instrumentation on NodeJS and recently we've been into a more customized initialization, which led us to the creation of a NodeTracerProvider with a resource containing some custom values on its ResourceAttributes. It turns out that since NodeTracerProvider extends BasicTracerProvider, it's constructor has a behavior where our created resources are being merged with the so-called "default" resources, as it follows:
constructor(config: TracerConfig = {}) {
// [...]
this.resource = Resource.default().merge(this.resource);
// [...]
}
In this scenario, since we have developed a toolkit that is responsible for initializing the OTel instrumentation for all applications, the SDK attributes that are being set on the Resource.default() implementation are not that useful and just generates us more volume for traffic and storage, which and made us look for a solution where we could deactivate this behavior.
Other than that, the OTel documentation found on Zero-Code Instrumentation Configuration - SDK resource detector configuration provides us an environment variable (OTEL_NODE_RESOURCE_DETECTORS) where we can disable some Resource Detectors for NodeJS, however, this doesn't work with the SDK default Resource Attributes that we currently would like to remove:
- telemetry.sdk.version
- telemetry.sdk.name
- telemetry.sdk.language
Possible solutions
We've thought of two possible solutions:
Option 1
Through the TracerConfig, have an attribute which actually allows us to deactivate the default attributes when creating a new TracerProvider.
Option 2
Through the environment variable OTEL_NODE_RESOURCE_DETECTORS, allow the deactivation of default resource attributes, avoiding the merge behavior.