-
Notifications
You must be signed in to change notification settings - Fork 533
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(auto-instrumentations-node): add getPropagator to get propagators from environment #2232
feat(auto-instrumentations-node): add getPropagator to get propagators from environment #2232
Conversation
…s from enviornment
…pagators from enviornment
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2232 +/- ##
==========================================
+ Coverage 90.97% 97.06% +6.08%
==========================================
Files 146 8 -138
Lines 7492 409 -7083
Branches 1502 67 -1435
==========================================
- Hits 6816 397 -6419
+ Misses 676 12 -664 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by.
* Get a propagator based on the OTEL_PROPAGATORS env var. | ||
*/ | ||
export function getPropagator(): TextMapPropagator { | ||
if (process.env.OTEL_PROPAGATORS == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should empty string be treated as "use the default" as well? (That's what I infer from the language in this section: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#enum-value)
Also the spec mentions handling "none" as a value to say "no propagators": https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should empty string be treated as "use the default" as well? (That's what I infer from the language in this section: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#enum-value)
Yes that's correct, good catch 🙂 I added that to the default case. cf3bb0d
Also the spec mentions handling "none" as a value to say "no propagators": https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration
Also good catch, it would've incorrectly logged that it's unkown before (the Propgator would still have been a no-op CompositePropagator with no sub-propgators, so I think that would've been spec compliant). I added an info log that lets the user know that none
. Though I'm not sure what to do if there's none
among other valid values so I've opted to still take the rest of the propagators in that case. My guess is that users would be least surpirsed if they set tracecontext, none
and the W3CTraceContextPropagator
would be the one that gets set. cf3bb0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comparison points on "none" handling:
- auto-instrumentations-node handling of
OTEL_NODE_RESOURCE_DETECTORS
handlesfoo,none,bar
and "none"opentelemetry-js-contrib/metapackages/auto-instrumentations-node/src/utils.ts
Lines 238 to 244 in caf7cb5
if (resourceDetectorsFromEnv.includes('all')) { return [...resourceDetectors.values()].flat(); } if (resourceDetectorsFromEnv.includes('none')) { return []; } - ditto for sdk-node's handling of that same envvar
- sdk-node's handling of
OTEL_TRACES_EXPORTER
is slightly weird:OTEL_TRACES_EXPORTER=none,otlp
results in different behaviour toOTEL_TRACES_EXPORTER=otlp,none
:) https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts#L101-L126
Anyway, this is something that could perhaps share some common processing at some point. Doesn't have to be this PR, and perhaps would wait for work related to supporting file-config.
Co-authored-by: Trent Mick <[email protected]>
…alue, and 'none' is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the npm run lint:fix
to run first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! (just needs lint as per the previous comment)
also we could note that this updates open-telemetry/opentelemetry-js#4494 |
Thanks for the reviews. 🙇 I'm moving this back to draft as I talked to @martinkuba about some other options to solve this issue. There will likely be a propagator-autoconfigure package that only contains the spec propagators (all from core and including |
closing in favor of #2299 |
Which problem is this PR solving?
According to the spec we MUST NOT maintain the aws propagator be part of the core repo, so we also cannot introduce it as a dependency to
sdk-node
. However, we've hadgetResourceDetectors()
in@opentelemetry/auto-instrumentations-node
which also includes all third-party resource-detectors. This PR addsgetPropagator()
which allows you to get a propagator based on the environment variableOTEL_PROPAGATORS
. It includes third-party ones likexray
orxray-lambda
without having to add them as a core feature.Short description of the changes
getPropagator()
which builds a propagator based onOTEL_PROPAGATORS
@opentelemetry/auto-instrumentations-node/register
export, so it overrides what the SDK would do.