Repository navigation
feat(nodejs): switch the layer to NodeSDK and OTel JS SDK 3 - #2749
Conversation
Build the layer's providers with NodeSDK instead of creating NodeTracerProvider, MeterProvider and LoggerProvider by hand, and move the layer to OpenTelemetry JS SDK 3 (core/sdk 3.1, experimental 0.301, matching contrib instrumentations). The layer keeps what NodeSDK does not cover: the xray and xray-lambda propagators, the AWS Lambda resource detector, its instrumentation list and the configure* hooks. Instrumentations are registered again after sdk.start(), because start() registers them before it creates the providers and the Lambda instrumentation would otherwise bind the no-op tracer provider and skip the flush at invocation end. SDK 3 needs Node.js 22.15 or later, so this depends on nodejs20.x being dropped from the layer's runtimes.
thompson-tomo
left a comment
There was a problem hiding this comment.
Thanks very much for working on this. Overall it looks good, just a couple of questions & I just want to compare some performance stats before approving.
| @@ -401,147 +332,74 @@ | |||
| if (!sdkRegistrationConfig.propagator) { | |||
| sdkRegistrationConfig.propagator = getPropagator(); | |||
| } | |||
There was a problem hiding this comment.
Would it make sense to be using https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/auto-configuration-propagators/README.md instead?
There was a problem hiding this comment.
Yeah, I switched to the shared package and removed the layer's getPropagator.
There was a problem hiding this comment.
Thanks. I am still wondering if we could simplify it further
const sdk = new NodeSDK({
resource: sdkResource,
autoDetectResources: false,
textMapPropagator: sdkRegistrationConfig.propagator,
Becomes
const sdk = new NodeSDK({
resource: sdkResource,
autoDetectResources: false,
textMapPropagator: getPropagators,
and remove it the sdkRegistrationConfig?
There was a problem hiding this comment.
I removed sdkRegistrationConfig, getPropagator() now goes straight to NodeSDK. I kept the call before diag.disable() though, passing it inline runs after the layer drops its logger and before NodeSDK installs its own, so invalid-propagator warnings get lost when OTEL_LOG_LEVEL is set.
There was a problem hiding this comment.
Thanks, it is certainly looking simplier & more maintainable.
passing it inline runs after the layer drops its logger and before NodeSDK installs its own
Does that mean that the logging at https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/auto-configuration-propagators/src/utils.ts#L67-L73 would not produce anything hence why we are needing to add logging for invalid options in our wrapper? If so would it be more beneficial to upstream changes so that nodesdk installs its logger sooner?
There was a problem hiding this comment.
Yes, with OTEL_LOG_LEVEL set. The wrapper's warnings were for unsupported meter/logger hook options, I've removed those now. Propagator warnings come from contrib.
I'd have NodeSDK pass suppressOverrideMessage: true so we can keep the layer logger active for an inline call. Moving logger setup within the constructor still happens after getPropagator().
|
|
||
| export interface SDKRegistrationConfig { | ||
| propagator?: TextMapPropagator | null; | ||
| contextManager?: ContextManager | null; |
There was a problem hiding this comment.
Could you explain why we need this. Could we instead use the default for sdk-node? Or could we simply set it node-sdk
There was a problem hiding this comment.
I kept it for existing configureSdkRegistration hooks. I pass the hook's contextManager to NodeSDK, otherwise NodeSDK uses its default.
There was a problem hiding this comment.
When would there be an existing configureSdkRegistration hook given that we are not shipping a library?
There was a problem hiding this comment.
I carried it over from the old setup. I removed the hook and left NodeSDK to use its default context manager.
There was a problem hiding this comment.
Correction to my reply above: the ADOT layer builds on this one and sets configureSdkRegistration to pick its default propagators when OTEL_PROPAGATORS is unset. I've put the hook back in 756d66d.
There was a problem hiding this comment.
Looking at the ADOT example, would it make sense to define a createSdk hook which can then be used to create a nodesdk. That way if nodesdk adds functionality it is available without work here. We can then deprecate the redundant hooks and streamline the logic here?
There was a problem hiding this comment.
Yes, I called it configureSdk cause it returns options for NodeSDK. I kept start() and the instrumentation re-register in the layer so Lambda can still flush. The hook gets the config built from configureTracer, configureMeter, configureLogger and configureSdkRegistration, which still work but are now deprecated.
There was a problem hiding this comment.
Happy with the new hook, would it be better to:
- create sdkconfig needed for lambda (no hooks). Simplified version of what we have now
- call sdkconfig hook like now
- call deprecated hooks updating sdkconfig directly when possible
- create nodesdk using config & continue like now
That way when we drop the deprecated hooks it is purely removal and no possible changes to remaining implementation.
There was a problem hiding this comment.
Yes, I changed the order. The deprecated hooks run after configureSdk now and only override options they return. Each has its own block to remove later.
There was a problem hiding this comment.
🟡 Changes recommended
Configuration hook compatibility is broken: missing resources can prevent handler initialization, while discarded meter and logger options silently alter telemetry attribution or record limits.
2 open issues
1 file not reviewed
nodejs/package-lock.json: Generated file
What changed in this PR
Migrates the Node.js Lambda layer to OpenTelemetry JS SDK 3 and shared NodeSDK initialization, consolidating the core and contrib upgrades after the Node 20 retirement prerequisite.
Changes:
- Upgrades OpenTelemetry dependencies and requires Node.js 22.15.0 or later.
- Delegates provider and exporter setup to
NodeSDK, changing the default OTLP protocol tohttp/protobuf. - Adapts wrapper and handler tests to SDK 3 APIs and provider registration.
| File | Description |
|---|---|
nodejs/packages/layer/test/wrapper.spec.ts |
Updates provider inspection and explicitly selects HTTP/JSON for exporter tests. |
nodejs/packages/layer/test/handler.spec.ts |
Migrates trace imports and processor construction; disables unrelated exporters. |
nodejs/packages/layer/test/handler.spec.mjs |
Applies equivalent SDK 3 updates to ESM handler tests. |
nodejs/packages/layer/src/wrapper.ts |
Replaces separate provider initialization with NodeSDK and adapts configuration hooks. |
nodejs/packages/layer/package.json |
Updates dependencies and raises the minimum Node.js version. |
nodejs/package-lock.json |
Locks upgraded packages and additional exporter dependencies. |
Review effort: Balanced
…nfiguration-propagators The configureTracer, configureMeter and configureLogger hooks get the detected resource again, so hooks that call config.resource.merge() keep working. The layer detects it once and NodeSDK no longer runs detection. NodeSDK uses one resource for all signals and has no logRecordLimits option. When configureMeter or configureLogger return options it cannot take, the layer now logs a warning that says where to set them instead. OTEL_PROPAGATORS is now read by @opentelemetry/auto-configuration-propagators, which also supports b3, b3multi and ottrace.
|
I know the following is not very scientific but using the cloud watch performance reports as benchmarks we get the following:
My take away is that the performance after the changes is on par with the prior performance in terms of duration to complete what has increased across the board is memory consumption. I would attribute this increase to including protobuf and grpc. Overall from performance side i don't see an issue and if we wanted to improve performance we should look at the instrumentation setup/configuration. For reference my test rig is simply running the integration tests via ci (#2751) with logging to emit the lambda report log to console. |
…or to NodeSDK The layer is not a library, so the registration hook only carried the propagator and context manager into NodeSDK. The propagator now comes from OTEL_PROPAGATORS through getPropagator() and goes straight to NodeSDK. The context manager is NodeSDK's default, as it was when the hook was not defined. getPropagator() runs before the layer drops its diag logger, so a warning about an unknown OTEL_PROPAGATORS name is still printed when OTEL_LOG_LEVEL is set.
thompson-tomo
left a comment
There was a problem hiding this comment.
I appreciate your support in working through this @adityareddy-dev and it is already a big improvement. I am wondering if we cannot iterate this further to ensure that the layer is as slim as possible due to leveraging the reusable nodesdk.
…ly hooks NodeSDK now runs the Lambda, env and process detectors itself. A resource returned by configureTracer is merged with the detected one instead of replacing it, and the hooks no longer get the detected resource in their default config. Drop the TracerConfig alias, the deprecated configureMeterProvider and configureLoggerProvider hooks, and the warning about meter and logger options NodeSDK does not take.
The ADOT Lambda layer builds on this layer and sets configureSdkRegistration to pick its default propagator when OTEL_PROPAGATORS is unset. Its propagator and context manager go to NodeSDK. Without a propagator from the hook, it still comes from OTEL_PROPAGATORS.
A hook returning contextManager: null left the context manager unset under register(). Pass it to NodeSDK as is, which treats null the same.
The hook gets the options the layer built, including what the older hooks returned, and its result goes straight to NodeSDK. Options NodeSDK adds later need no change in the layer. configureTracer, configureMeter, configureLogger and configureSdkRegistration still work and are marked deprecated.
There was a problem hiding this comment.
🟡 Changes recommended
An explicitly empty reader list from the legacy configureMeter hook is converted to undefined, allowing NodeSDK defaults to export metrics the hook intended to disable; preserve the empty list and add regression coverage.
1 open issue
2 resolved since last review
1 file not reviewed
nodejs/package-lock.json: Generated file
Review effort: Balanced
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const meterConfig: any = | ||
| configureMeter({ | ||
| readers: sdkConfig.metricReaders ?? [], | ||
| views: sdkConfig.views, | ||
| }) ?? {}; | ||
| if (Object.hasOwn(meterConfig, 'readers')) { | ||
| sdkConfig.metricReaders = | ||
| sdkConfig.metricReaders === undefined | ||
| ? nonEmpty(meterConfig.readers) | ||
| : meterConfig.readers; |
Added configuration hooks section with details on available hooks and deprecated hooks.
Fix formatting issues in the README table.
thompson-tomo
left a comment
There was a problem hiding this comment.
Approving based on previous performance testing of the core. Appreciate the way i have been able to iterate it with @adityareddy-dev. @tylerbenson readme is updated
|
Nice work both of you to get this one done. |
|
Note for changelog/release notes to document from clsude:
|

Closes #2744
Moves the Node.js layer to NodeSDK and SDK 3, so the core and contrib renovate PRs can close. It needs the Node 20 drop first.
The OTLP default changes to
http/protobufwith this, andwrapper.jsgoes from 157 KB to 653 KB since NodeSDK brings the grpc and protobuf exporters along.I removed the deprecated
configureMeterProviderandconfigureLoggerProviderhooks. NodeSDK now detects resources, so the remaining provider hooks no longer get the detected resource in their config. Hooks usingconfig.resource.merge()need updating. A resource returned byconfigureTraceris merged with the detected one, with detected attributes winning on a clash.configureSdkRegistrationstays, since ADOT sets it.I added
configureSdkfor the full NodeSDK options, starting from the Lambda defaults.configureTracer,configureMeter,configureLoggerandconfigureSdkRegistrationstill work but are deprecated. They run afterconfigureSdkand can override only the options they return.