Skip to content

feat(nodejs): switch the layer to NodeSDK and OTel JS SDK 3 - #2749

Merged
tylerbenson merged 14 commits into
open-telemetry:mainfrom
adityareddy-dev:nodejs/node-sdk-v3
Nov 19, 2026
Merged

tylerbenson merged 14 commits into
open-telemetry:mainfrom
adityareddy-dev:nodejs/node-sdk-v3

Conversation

@adityareddy-dev

@adityareddy-dev adityareddy-dev commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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/protobuf with this, and wrapper.js goes from 157 KB to 653 KB since NodeSDK brings the grpc and protobuf exporters along.

I removed the deprecated configureMeterProvider and configureLoggerProvider hooks. NodeSDK now detects resources, so the remaining provider hooks no longer get the detected resource in their config. Hooks using config.resource.merge() need updating. A resource returned by configureTracer is merged with the detected one, with detected attributes winning on a clash. configureSdkRegistration stays, since ADOT sets it.

I added configureSdk for the full NodeSDK options, starting from the Lambda defaults. configureTracer, configureMeter, configureLogger and configureSdkRegistration still work but are deprecated. They run after configureSdk and can override only the options they return.

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 thompson-tomo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread nodejs/packages/layer/src/wrapper.ts Outdated
Comment on lines 331 to 334
@@ -401,147 +332,74 @@
if (!sdkRegistrationConfig.propagator) {
sdkRegistrationConfig.propagator = getPropagator();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I switched to the shared package and removed the layer's getPropagator.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we need this. Could we instead use the default for sdk-node? Or could we simply set it node-sdk

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it for existing configureSdkRegistration hooks. I pass the hook's contextManager to NodeSDK, otherwise NodeSDK uses its default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would there be an existing configureSdkRegistration hook given that we are not shipping a library?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I carried it over from the old setup. I removed the hook and left NodeSDK to use its default context manager.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread nodejs/packages/layer/src/wrapper.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 to http/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

Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
…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.
@thompson-tomo

thompson-tomo commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

I know the following is not very scientific but using the cloud watch performance reports as benchmarks we get the following:

Architecture OTEL Version Run Duration Billed Duration Memory Size Max Memory Used Init Duration
AMD64 2 431.60 ms 1289 ms 512 MB 179 MB 857.06 ms
ARM64 2 397.05 ms 1403 ms 512 MB 179 MB 1005.45 ms
AMD64 3 1 388.89 ms 1372 ms 512 MB 184 MB 982.56 ms
AMD64 3 2 390.64 ms 1219 ms 512 MB 185 MB 827.45 ms
AMD64 3 3 333.45 ms 1186 ms 512 MB 184 MB 852.49 ms
ARM64 3 1 418.55 ms 1462 ms 512 MB 190 MB 1042.90 ms
ARM64 3 2 438.97 ms 1451 ms 512 MB 191 MB 1011.97 ms
ARM64 3 3 429.90 ms 1466 ms 512 MB 187 MB 1035.63 ms

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 thompson-tomo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
…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.
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
Comment thread nodejs/packages/layer/src/wrapper.ts Resolved
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.
@thompson-tomo thompson-tomo moved this from Todo to In Progress in Lambda Triage Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +310 to +320
// 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 thompson-tomo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-project-automation github-project-automation Bot moved this from In Progress to Need more Approval in Lambda Triage Nov 19, 2026
@tylerbenson
tylerbenson merged commit f6c3789 into open-telemetry:main Nov 19, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Need more Approval to Done in Lambda Triage Nov 19, 2026
@tylerbenson

Copy link
Copy Markdown
Member

Nice work both of you to get this one done.

@thompson-tomo

thompson-tomo commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Note for changelog/release notes to document from clsude:

  • configureMeter behaves differently for existing users.
    The old default config passed to the hook already contained the OTLP PeriodicExportingMetricReader. The new one passes an empty readers array.A user who wrote config.readers.push(myReader) used to get OTLP export plus their reader. Now they get only their reader, and OTLP metrics export quietly stops.Either pass in a default OTLP reader, or call this out explicitly in the release notes.
  • The default OTLP protocol changes from http/json to http/protobuf.
  • configureMeterProvider and configureLoggerProvider are removed.
  • A resource returned from configureTracer is now merged with the detected one instead of replacing it.
  • OTEL_LOG_LEVEL=debug no longer adds the console span and log exporters.
  • Once a hook sets span processors, OTEL_TRACES_EXPORTER is ignored. Before, exporters from that variable were added on top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code

Projects

Status: Done

4 participants