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

fix(sdk-node): Allow Defining Sampler with Exporter in Env #4394

Merged

Conversation

JacksonWeber
Copy link
Contributor

@JacksonWeber JacksonWeber commented Dec 29, 2023

Which problem is this PR solving?

Previously if the exporter was defined via the environment, any configured values like samplers would not be read from the NodeSDK configuration. By updating the check we allow for those configurations to be read even if the traceExporter/spanProcessor is not defined directly in the NodeSDK configuration.

Fixes #4212
Fixes #4004

Short description of the changes

Modies the SDK such that if the trace exporter is configured via the environment we still create/configure the tracerProvider.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested locally using a sample application to confirm that the changes allow the sampler to be read from the NodeSDK configuration even when the exporter is not defined outside of the environment.

Also added a test to ensure that when the exporter is defined in the environment that the appropriate tracerProvider is created.

Checklist:

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

@JacksonWeber JacksonWeber requested a review from a team as a code owner December 29, 2023 06:00
Copy link

codecov bot commented Dec 29, 2023

Codecov Report

Merging #4394 (a639e1c) into main (ac75b70) will decrease coverage by 0.16%.
The diff coverage is 100.00%.

❗ Current head a639e1c differs from pull request most recent head 7bd5316. Consider uploading reports for the commit 7bd5316 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4394      +/-   ##
==========================================
- Coverage   92.39%   92.23%   -0.16%     
==========================================
  Files         331      336       +5     
  Lines        9518     9533      +15     
  Branches     2022     2021       -1     
==========================================
- Hits         8794     8793       -1     
- Misses        724      740      +16     
Files Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 92.80% <100.00%> (ø)

... and 6 files with indirect coverage changes

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Looks good % changelog nit
Thanks for taking care of this 🙂

experimental/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

I had another look, as I was wondering how this affects the setup when

  • a sampler is configured manually
  • an exporter is configured via the environment

and now it looks like the sampler is configured, but the exporter is not. @JacksonWeber would you mind having another look to verify? I think we'd want the config to merge so that the exporter is configured via the environment, but the sampler is set to what's passed to NodeSDK.

@JacksonWeber
Copy link
Contributor Author

I had another look, as I was wondering how this affects the setup when

  • a sampler is configured manually
  • an exporter is configured via the environment

and now it looks like the sampler is configured, but the exporter is not. @JacksonWeber would you mind having another look to verify? I think we'd want the config to merge so that the exporter is configured via the environment, but the sampler is set to what's passed to NodeSDK.

Took a look into this. You were correct that it would ignore the configured exporter. I've updated the logic to use a TraceProviderWithEnvExporters in the case that the OTEL_TRACES_EXPORTER is defined, even if the rest of the configuration options are populated manually.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Hmm, now it seems like two span processors are registered, one with the correct exporter (if set via an env var) and the other without an exporter.

experimental/CHANGELOG.md Outdated Show resolved Hide resolved
experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for working on this and thanks for taking the time to address the comment 🙂

Just a few test nits then this PR should be ready to merge. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants