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

Create sync resource with some attributes that resolve asynchronously #3460

Merged

Conversation

samimusallam
Copy link
Member

@samimusallam samimusallam commented Dec 1, 2022

Which problem is this PR solving?

Fixes #2912

Short description of the changes

I spoke to @aabmass and agreed on taking on this issue and reopening his PR #2933 and build on it, as I think he has one of the best solutions for this issue.

  • In @opentelemetry/sdk-node
    • Adds an optional Promise to the Resource constructor which can asynchronously resolve some attributes. When this promise resolves, the attributes will be merged with the "synchronous" attributes.
    • Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
    • Update Detector.detect() signature to allow it to be synchronous and updated documentation that the synchronous variant should be used
  • In @opentelemetry/sdk-node
    • Updated NodeSDK.start() and its dependencies to now be synchronous (doesn't return a promise). This is a breaking change, but that package is experimental.
  • Updated BatchSpanProcessorBase and SimpleSpanProcessor to await the resource promise before calling exporters, if the resource has asynchronous attributes AND they have not already resolved. I.e. if there is no promise in the Resource (the case for existing detectors and code), the behavior is unchanged.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)

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

  • Existing tests pass with no modification
  • Added new tests to Resource.test.ts
  • Added detect-resources.test.ts

Checklist:

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

@samimusallam samimusallam requested a review from a team as a code owner December 1, 2022 14:42
… into feat/sync-resource-detectors

� Conflicts:
�	experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
�	packages/opentelemetry-resources/src/platform/node/detect-resources.ts
�	packages/opentelemetry-sdk-trace-base/src/export/SimpleSpanProcessor.ts
�	packages/sdk-metrics/src/export/PeriodicExportingMetricReader.ts
@codecov
Copy link

codecov bot commented Dec 4, 2022

Codecov Report

Merging #3460 (c8bd141) into main (3bc0807) will increase coverage by 1.71%.
The diff coverage is 88.01%.

❗ Current head c8bd141 differs from pull request most recent head 60a161a. Consider uploading reports for the commit 60a161a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3460      +/-   ##
==========================================
+ Coverage   92.32%   94.04%   +1.71%     
==========================================
  Files         153      268     +115     
  Lines        3608     7920    +4312     
  Branches      727     1641     +914     
==========================================
+ Hits         3331     7448    +4117     
- Misses        277      472     +195     
Impacted Files Coverage Δ
...ntelemetry-browser-detector/src/BrowserDetector.ts 14.28% <0.00%> (ø)
packages/opentelemetry-sdk-trace-base/src/Span.ts 98.58% <ø> (+0.70%) ⬆️
...ackages/opentelemetry-sdk-trace-base/src/Tracer.ts 98.59% <ø> (ø)
packages/sdk-metrics/src/export/MetricData.ts 100.00% <ø> (ø)
...es/opentelemetry-resources/src/detect-resources.ts 64.58% <64.58%> (ø)
...opentelemetry-resources/src/platform/node/utils.ts 66.66% <66.66%> (ø)
...etrics/src/export/PeriodicExportingMetricReader.ts 92.98% <70.00%> (ø)
...dk-trace-base/src/export/BatchSpanProcessorBase.ts 92.30% <78.57%> (-2.26%) ⬇️
...y-sdk-trace-base/src/export/SimpleSpanProcessor.ts 91.42% <90.00%> (+7.42%) ⬆️
...lemetry-resources/src/detectors/EnvDetectorSync.ts 94.11% <94.11%> (ø)
... and 138 more

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Sorry for the late review. This can be a very nice addition. Thank you for working on this!

Just a few comments I'd like to address before merging.

removed unnecessary await

Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
packages/opentelemetry-resources/src/Resource.ts Outdated Show resolved Hide resolved
packages/opentelemetry-resources/src/Resource.ts Outdated Show resolved Hide resolved
packages/opentelemetry-resources/src/Resource.ts Outdated Show resolved Hide resolved
packages/opentelemetry-resources/src/Resource.ts Outdated Show resolved Hide resolved
packages/opentelemetry-resources/test/Resource.test.ts Outdated Show resolved Hide resolved
@blumamir blumamir added this pull request to the merge queue Feb 13, 2023
@legendecas legendecas removed this pull request from the merge queue due to the queue being cleared Feb 13, 2023
@legendecas legendecas added this pull request to the merge queue Feb 13, 2023
@legendecas legendecas removed this pull request from the merge queue due to the queue being cleared Feb 13, 2023
@legendecas legendecas merged commit 47444f2 into open-telemetry:main Feb 13, 2023
pichlermarc added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Mar 15, 2023
waitingsong added a commit to waitingsong/midway that referenced this pull request Mar 27, 2023
`NodeSDK.start()` become `synchronous`

ref: open-telemetry/opentelemetry-js#3460
czy88840616 pushed a commit to midwayjs/midway that referenced this pull request Mar 27, 2023
czy88840616 pushed a commit to midwayjs/midway that referenced this pull request Mar 31, 2023
kirrg001 added a commit to instana/opentelemetry-js-contrib that referenced this pull request Apr 6, 2023
…node@0.37.0

- open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
kirrg001 added a commit to instana/opentelemetry-js-contrib that referenced this pull request Apr 11, 2023
…node@0.37.0

- open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
kirrg001 added a commit to instana/opentelemetry-js-contrib that referenced this pull request Apr 11, 2023
…node@0.37.0

- open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
kirrg001 added a commit to instana/opentelemetry-js-contrib that referenced this pull request Apr 12, 2023
…node@0.37.0

- open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
Flarna pushed a commit to open-telemetry/opentelemetry-js-contrib that referenced this pull request Apr 12, 2023
…node@0.37.0 (#1462)

- Refs: open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
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.

Add or change resource detection to be synchronous
8 participants