Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-*): add option to opt-out from merging the resource with Resource.default() #4617

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Apr 9, 2024

Description

The spec states that

The SDK MUST provide access to a Resource with at least the attributes listed at
Semantic Attributes with SDK-provided Default Value.
This resource MUST be associated with a TracerProvider or MeterProvider
if another resource was not explicitly specified.

However, we merge with Resource.default() regardless of if another resource was explicitly specified or not.

This leaves us with a difficult choice:

  1. stop merging with Resource.default() - this would likely break telemetry for users that rely on our non spec-compliant behavior of merging all the time, resource attributes that used to be there, would not be there anymore. (I'm not in favor of this)
  2. allow users to explicitly turn this behavior off. It's not optimal as this will still leave us spec non-compliant, but slightly less so. Users will be able to choose.
  3. do something else

This PR chooses option 2, providing a flag to each SDK and sdk-node that allows the users to opt-in to the spec compliant behavior. We can make the spec compliant behavior the default in SDK 2.0

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.19%. Comparing base (4b5c21c) to head (44fd9d8).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4617      +/-   ##
==========================================
+ Coverage   93.17%   93.19%   +0.02%     
==========================================
  Files         315      315              
  Lines        8086     8098      +12     
  Branches     1617     1623       +6     
==========================================
+ Hits         7534     7547      +13     
+ Misses        552      551       -1     
Files with missing lines Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 95.54% <100.00%> (+0.05%) ⬆️
...perimental/packages/sdk-logs/src/LoggerProvider.ts 98.00% <100.00%> (+0.17%) ⬆️
experimental/packages/sdk-logs/src/config.ts 100.00% <ø> (ø)
...elemetry-sdk-trace-base/src/BasicTracerProvider.ts 95.57% <100.00%> (+0.03%) ⬆️
...ackages/opentelemetry-sdk-trace-base/src/config.ts 88.63% <ø> (ø)
packages/sdk-metrics/src/MeterProvider.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@trentm
Copy link
Contributor

trentm commented Apr 11, 2024

Some notes, thinking out loud.

How to create NodeSDK without getting Resource.default() merged in?

// - Option 1: If we had to do it all over again it would be: If you explicitly
//   pass in a `resource` then `.default()` is NOT used.
//   Cons: Breaks backward compat. NodeSDK *is* pre-1.0, so we *could*, but
//   probably don't want to until a major version bump.
const sdk = new NodeSDK({ resource: new Resource({foo: 'bar'}) }); // no defaults
const sdk = new NodeSDK({ resource: Resource.empty() }); // no defaults
const sdk = new NodeSDK({ resource: Resource.default() }); // yes defaults
const sdk = new NodeSDK(); // yes defaults

// - Option 2: Boolean option to say not to merge defaults.
//   Defaults to always merge with Resource.default() for now.
//
//   Could consider later (for SDK 2.0?) changing `mergeResourceWithDefaults`
//   to a tri-state: true, false, or unspecified. Unspecified  means it
//   depends on whether `resource` is given. Eventually then the behaviour
//   would be as in Option 1, with the option to explicitly keep it stable
//   by specifying `mergeResourceWithDefaults`.
const sdk = new NodeSDK({ mergeResourceWithDefaults: false }); // no defaults

Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@trentm
Copy link
Contributor

trentm commented Aug 22, 2024

@pichlermarc Interested in adding a doc section for this in the sdk-node/README.md and then taking this out of draft?

See discussion at #4930

@pichlermarc pichlermarc force-pushed the feat/default-resource-merge-opt-out branch from 1eb145d to 9e44234 Compare September 24, 2024 16:30
@pichlermarc
Copy link
Member Author

@trentm sorry for letting this sit for so long. I'm picking this up again. I don't have good answers to these questions yet but I'll comment here and will take it out of draft once I figured out what's best for NodeSDK.

When we merge this I'll also follow up on the next branch to restore a spec-compliant behavior. I think in 2.0 we can then have a Default Resource detector in NodeSDK that would add the default resource and can be turned off via env var just like the other detectors.

Maybe for now we just allow the same flag as proposed in the NodeSDK for this PR.

@pichlermarc pichlermarc changed the title [prototype] feat(sdk-trace): add option to opt-out from merging the resource with Resource.default() feat(sdk-*): add option to opt-out from merging the resource with Resource.default() Nov 8, 2024
@pichlermarc
Copy link
Member Author

pichlermarc commented Nov 8, 2024

@trentm I've gone the route of adding the same flag to the NodeSDK - this way we stay consistent in what we do in all the SDKs (logs, metrics, traces) as well as the wrapper (sdk-node). I've added the docs section to the NodeSDK.

I suggest we make that spec-compliant behavior the default and drop the option in 2.0. I added a changelog entry to announce that plan.

@pichlermarc pichlermarc marked this pull request as ready for review November 8, 2024 13:32
@pichlermarc pichlermarc requested a review from a team as a code owner November 8, 2024 13:32
@pichlermarc pichlermarc added pkg:sdk-metrics pkg:sdk-node pkg:sdk-trace-base pkg:sdk-trace-node pkg:sdk-trace-web pkg:sdk-logs spec-feature This is a request to implement a new feature which is already specified by the OTel specification and removed never-stale labels Nov 8, 2024
@trentm
Copy link
Contributor

trentm commented Nov 8, 2024

I suggest we make that spec-compliant behavior the default and drop the option in 2.0. I added a changelog entry to announce that plan.

Should we add #4930 to the SDK 2.0 milestone?

experimental/packages/opentelemetry-sdk-node/src/types.ts Outdated Show resolved Hide resolved
experimental/packages/sdk-logs/src/types.ts Outdated Show resolved Hide resolved
packages/sdk-metrics/src/MeterProvider.ts Outdated Show resolved Hide resolved
@pichlermarc
Copy link
Member Author

pichlermarc commented Nov 11, 2024

I suggest we make that spec-compliant behavior the default and drop the option in 2.0. I added a changelog entry to announce that plan.

Should we add #4930 to the SDK 2.0 milestone?

Yes, I'll refine that request into a new issue once I've merged this 🙂

@pichlermarc pichlermarc added this pull request to the merge queue Nov 11, 2024
Merged via the queue into open-telemetry:main with commit 012dc9e Nov 11, 2024
21 checks passed
@pichlermarc pichlermarc deleted the feat/default-resource-merge-opt-out branch November 11, 2024 09:31
@pichlermarc
Copy link
Member Author

I opted to close their issue as this PR seems to address all their requirements for now. I created a follow-up issue to fully align with the spec in SDK 2.0 (#5132)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:sdk-logs pkg:sdk-metrics pkg:sdk-node pkg:sdk-trace-base pkg:sdk-trace-node pkg:sdk-trace-web spec-feature This is a request to implement a new feature which is already specified by the OTel specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants