Skip to content

refactor(sdk-trace-base, sdk-node): add TracerProvider class and use BasicTracerProvider in Node SDK#6640

Open
david-luna wants to merge 12 commits into
open-telemetry:mainfrom
david-luna:sdk-node-basic-trace-provider
Open

refactor(sdk-trace-base, sdk-node): add TracerProvider class and use BasicTracerProvider in Node SDK#6640
david-luna wants to merge 12 commits into
open-telemetry:mainfrom
david-luna:sdk-node-basic-trace-provider

Conversation

@david-luna
Copy link
Copy Markdown
Contributor

@david-luna david-luna commented Apr 28, 2026

Which problem is this PR solving?

As mentioned in #5290 (comment) the Node SDK should resolve the tracer provider configuration from the SDK options or the environment if necessary. Also the register method from NodeTracerProvider is not used anymore because Node SDK already registers the propagators and the context manager using the api to register the globally.

If the SDK resolved the config then the following classes are not needed

  • BasicTracerProvider because it has logic to get configuration from environment vars
  • NodeTracerProvider because the only specific logic, register method, is unused.

This PR is the 1st one to make SDK Node free from these classes and get it ready for a simple TracerProvider class which doesn't have hidden logic rather than the tracer provider creation.

Refs: #5290
Refs: #6595

Short description of the changes

  • mark NodeTracerProvider and NodeTracerConfig as deprecated
  • mark BasicTracerProvider as deprecated
  • replace imports of NodeTracerProvider to BasicTracerProvider
  • replace other imports from @opentelemetry/sdk-trace-node to point to @opentelemetry/sdk-trace-base since they are just re-exports.
  • export a new TracerProvider class which expects the config options resolved falling back to defaults from spec
  • export TracerProviderOptions interface used in the constructor of the new TracerProvider class.
  • BasicTracerProvider becomes a wrapper around TracerProvider class providing a merged configuration from user and environment

Type of change

Please delete options that are not relevant.

  • Refactor (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • npm run compile
  • npm run test

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been updated

@david-luna david-luna added this to the SDK 3.0 milestone Apr 28, 2026
@david-luna david-luna added sdk:traces Issues and PRs related to the Traces SDK pkg:sdk-node labels Apr 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 95.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.87%. Comparing base (988e765) to head (1b256ca).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...opentelemetry-sdk-trace-base/src/TracerProvider.ts 94.93% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6640      +/-   ##
==========================================
+ Coverage   94.85%   94.87%   +0.01%     
==========================================
  Files         377      378       +1     
  Lines       12751    12789      +38     
  Branches     2887     2903      +16     
==========================================
+ Hits        12095    12133      +38     
  Misses        656      656              
Files with missing lines Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 95.90% <100.00%> (-0.03%) ⬇️
...elemetry-sdk-trace-base/src/BasicTracerProvider.ts 100.00% <100.00%> (+6.45%) ⬆️
...telemetry-sdk-trace-node/src/NodeTracerProvider.ts 100.00% <ø> (ø)
...opentelemetry-sdk-trace-base/src/TracerProvider.ts 94.93% <94.93%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@david-luna david-luna marked this pull request as ready for review April 28, 2026 17:15
@david-luna david-luna requested a review from a team as a code owner April 28, 2026 17:15
@david-luna david-luna marked this pull request as draft May 4, 2026 14:50
@david-luna david-luna changed the title chore(sdk-node): move away from @opentelemetry/sdk-trace-node refactor(sdk-trace-base, sdk-node): add TracerProvider class and resolve traces config from env in Node SDK May 4, 2026
Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Unsolicited feedback. I know this is still in draft. :)

Comment thread experimental/packages/opentelemetry-sdk-node/src/index.ts
@@ -24,105 +23,30 @@ export enum ForceFlushState {
/**
* This class represents a basic tracer provider which platform libraries can extend
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.

The PR desc suggests you were going to mark this class as deprecated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

right, I'll add the deprecation mark

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

commit 49b3cfc

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. However if we don't have a replacement yet, should we not deprecate it yet?
My (minor) concern is that users of BasicTracerProvider will get a deprecation marker in their editor/lint output (maybe), but without an alternative to use yet.

Or I suppose you could point to the TracerProvider being adding in this PR, but warning users that it no longer handles reading env vars. Hrm. That's not yet satisfying.

Eventually perhaps there is a createTracerProviderFromEnv() or similar function export from the sdk-node package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My (minor) concern is that users of BasicTracerProvider will get a deprecation marker in their editor/lint output (maybe), but without an alternative to use yet.

I think it's a valid concern. What we can do is:

  • remove the deprecation
  • move on with SDK 3.0
  • once published add the deprecation notice and do a 2.X release

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 suppose we won't consider dropping BasicTracerProvider in 3.0, because it is coming so soon?

If so, then yes, deprecating it some time after SDK 3.0 is released sounds good.

/**
* TracerProviderConfig provides an interface for configuring a Tracer Provider.
*/
export type TracerProviderConfig = TracerConfig;
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.

This reminds me of #6469

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll rename it to TracerProviderOptions then :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

commit 49b3cfc

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.

TracerProviderConfig is fine. The issue is that TracerConfig is currently being used (as config for a TracerProvider) in the existing released packages for something different than what the spec now uses TracerConfig for (as config for a Tracer).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue is that TracerConfig is currently being used (as config for a TracerProvider)...

I thought on changing the name but I think it can wait to the new major.

@david-luna david-luna changed the title refactor(sdk-trace-base, sdk-node): add TracerProvider class and resolve traces config from env in Node SDK refactor(sdk-trace-base, sdk-node): add TracerProvider class and use BasicTracerProvider in Node SDK May 6, 2026
@david-luna david-luna marked this pull request as ready for review May 6, 2026 07:41
Copy link
Copy Markdown
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Just a partial review. I have to run and don't want to forget to submit this so far.

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.

  • Perhaps also get the sdk-trace-node usages in the instr-http and instr-grpc README.md files?
  • Can the sdk-trace-node devDep be removed from those package.json files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • Perhaps also get the sdk-trace-node usages in the instr-http and instr-grpc README.md files?

commit 48a35b7

  • Can the sdk-trace-node devDep be removed from those package.json files?

yes, thanks for pointing it. commit 78aeba6

Comment thread experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Comment thread experimental/CHANGELOG.md Outdated

* test(otlp-transformer): add metrics transform benchmark [#6628](https://github.com/open-telemetry/opentelemetry-js/pull/6628) @pichlermarc
* refactor(opentelemetry-exporter-prometheus): do not call enforcePrometheusNamingConvention() multiple times per metric [#6636](https://github.com/open-telemetry/opentelemetry-js/pull/6636) @cjihrig
* refactor(sdk-node): replace usage of `NodeTracerProvider` for `BasicTracerProvider` in SDK start [#6640](https://github.com/open-telemetry/opentelemetry-js/pull/6640) @david-luna
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.

Reminder to move this up to the top Unreleased section when close to merging.

@@ -24,105 +23,30 @@ export enum ForceFlushState {
/**
* This class represents a basic tracer provider which platform libraries can extend
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. However if we don't have a replacement yet, should we not deprecate it yet?
My (minor) concern is that users of BasicTracerProvider will get a deprecation marker in their editor/lint output (maybe), but without an alternative to use yet.

Or I suppose you could point to the TracerProvider being adding in this PR, but warning users that it no longer handles reading env vars. Hrm. That's not yet satisfying.

Eventually perhaps there is a createTracerProviderFromEnv() or similar function export from the sdk-node package.

import { reconfigureLimits } from './utility';
import { TracerProvider } from './TracerProvider';

export enum ForceFlushState {
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.

Guessing this can be dropped. I didn't check if all uses in this file were removed, and moved to TracerProvider.ts

import { AlwaysOnSampler } from './sampler/AlwaysOnSampler';
import { RandomIdGenerator } from './platform';

export enum ForceFlushState {
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.

Does this need to be exported? This could totally be addressed in a separate PR. I know you are copying BasicTracerProvider.ts with minimal changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New @opentelemetry/sdk-trace pacakge will have this export but it is not necessary to export this class right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

commit 86d391e

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.

That commit stops exporting TracerProvider. I was talking about whether enum ForceFlushState needs to be exported. AFAICT it is only used internally in this file.

@david-luna david-luna requested a review from trentm May 19, 2026 10:48
const { XMLHttpRequestInstrumentation } = require('@opentelemetry/instrumentation-xml-http-request');
const { WebTracerProvider } = require('@opentelemetry/sdk-trace-web');

// XXX
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.

Should this be removed or replaced?

@@ -24,105 +23,30 @@ export enum ForceFlushState {
/**
* This class represents a basic tracer provider which platform libraries can extend
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 suppose we won't consider dropping BasicTracerProvider in 3.0, because it is coming so soon?

If so, then yes, deprecating it some time after SDK 3.0 is released sounds good.

import { AlwaysOnSampler } from './sampler/AlwaysOnSampler';
import { RandomIdGenerator } from './platform';

export enum ForceFlushState {
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.

That commit stops exporting TracerProvider. I was talking about whether enum ForceFlushState needs to be exported. AFAICT it is only used internally in this file.

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

Labels

pkg:sdk-node sdk:traces Issues and PRs related to the Traces SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants