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

Delay evaluation of resource.Default to first call #2371

Merged
merged 4 commits into from Nov 15, 2021

Conversation

bmon
Copy link
Contributor

@bmon bmon commented Nov 11, 2021

Currently defaultResource (which includes data calculated by parsing env var OTEL_RESOURCE_ATTRIBUTES) is evaluated as an import side effect. Some applications might want to update that variable with go code (eg to load extra env vars from a configuration file, for example using https://github.com/joho/godotenv). By only evaluating it the first time resource.Default() is called, we can allow those applications an opportunity to set OTEL_RESOURCE_ATTRIBUTES first, while still only calculating the value once.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 11, 2021

CLA Signed

The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Nov 11, 2021

Codecov Report

Merging #2371 (d39a348) into main (2fa7bce) will decrease coverage by 0.0%.
The diff coverage is 57.1%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #2371     +/-   ##
=======================================
- Coverage   73.8%   73.8%   -0.1%     
=======================================
  Files        175     175             
  Lines      12430   12439      +9     
=======================================
+ Hits        9184    9185      +1     
- Misses      3012    3017      +5     
- Partials     234     237      +3     
Impacted Files Coverage Δ
sdk/resource/resource.go 82.5% <57.1%> (-1.2%) ⬇️
sdk/metric/refcount_mapped.go 80.0% <0.0%> (-20.0%) ⬇️
sdk/metric/sdk.go 80.2% <0.0%> (-1.5%) ⬇️
exporters/jaeger/jaeger.go 94.3% <0.0%> (+0.8%) ⬆️

sdk/resource/resource.go Outdated Show resolved Hide resolved
@WillsonHG
Copy link

/easycla

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

The implementation looks good to me. Can you add an entry to the changelog describing the changed behavior to the end user?

@bmon bmon requested a review from MrAlias November 15, 2021 00:50
@MrAlias MrAlias merged commit 47203fa into open-telemetry:main Nov 15, 2021
@bmon bmon deleted the delay-default-resource branch November 16, 2021 07:09
@bmon
Copy link
Contributor Author

bmon commented Nov 16, 2021

Thanks very much, all. Cheers! 👍

@Aneurysm9 Aneurysm9 mentioned this pull request Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants