Skip to content

feat: resource auto-detection#899

Merged
dyladan merged 21 commits intoopen-telemetry:masterfrom
mwear:resource_autodetection
Apr 15, 2020
Merged

feat: resource auto-detection#899
dyladan merged 21 commits intoopen-telemetry:masterfrom
mwear:resource_autodetection

Conversation

@mwear
Copy link
Copy Markdown
Member

@mwear mwear commented Mar 25, 2020

Which problem is this PR solving?

Short description of the changes

The PR ports the existing resource auto-detection logic from OpenCensus. Some of the code has been reorganized and it uses the OpenTelemetry semantic conventions. For the most part, resource auto-detection is unspecified for OTel, so I've kept to the Census approach for the initial port.

The biggest change from the Census implementation is that I reorganized the detection logic for each Resource type into its own "detector" class. With the goal of making it easier to add detectors in the future.

For reference, here are links to the Census code this is based on:

Because there is potential latency involved in auto-detection, users need to manually call the detectResources method during setup, making this functionality opt-in. For example:

import { detectResources } from '@opentelemetry/resources'

const provider = new NodeTracerProvider({ resource: detectResources() });

@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 25, 2020

Codecov Report

❌ Patch coverage is 96.39344% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.79%. Comparing base (8e56923) to head (689ffd3).

Files with missing lines Patch % Lines
...sources/src/platform/node/detectors/EnvDetector.ts 88.09% 5 Missing ⚠️
...rces/src/platform/node/detectors/AwsEc2Detector.ts 87.09% 4 Missing ⚠️
...sources/src/platform/node/detectors/GcpDetector.ts 95.12% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #899      +/-   ##
==========================================
+ Coverage   94.75%   94.79%   +0.04%     
==========================================
  Files         248      259      +11     
  Lines       11288    11590     +302     
  Branches     1079     1094      +15     
==========================================
+ Hits        10696    10987     +291     
- Misses        592      603      +11     
Files with missing lines Coverage Δ
packages/opentelemetry-resources/src/Resource.ts 100.00% <100.00%> (ø)
...ages/opentelemetry-resources/src/platform/index.ts 100.00% <100.00%> (ø)
...ry-resources/src/platform/node/detect-resources.ts 100.00% <100.00%> (ø)
...try-resources/src/platform/node/detectors/index.ts 100.00% <100.00%> (ø)
...opentelemetry-resources/src/platform/node/index.ts 100.00% <100.00%> (ø)
...ages/opentelemetry-resources/test/Resource.test.ts 100.00% <100.00%> (ø)
...ntelemetry-resources/test/detect-resources.test.ts 100.00% <100.00%> (ø)
...ry-resources/test/detectors/AwsEc2Detector.test.ts 100.00% <100.00%> (ø)
...metry-resources/test/detectors/EnvDetector.test.ts 100.00% <100.00%> (ø)
...metry-resources/test/detectors/GcpDetector.test.ts 100.00% <100.00%> (ø)
... and 4 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, added a few comments in the first pass.

* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_LABELS environment variable.
*/
export class EnvDetector {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think specs is not yet defined for the env detector. Perhaps, we can open an issue in specs to start the discussion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mwear mwear force-pushed the resource_autodetection branch 2 times, most recently from d0e0cf5 to db0df52 Compare April 1, 2020 19:12
"@opentelemetry/api": "^0.5.2",
"@opentelemetry/base": "^0.5.2"
"@opentelemetry/base": "^0.5.2",
"gcp-metadata": "^3.5.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: latest available version is 4.0.0.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, thanks for the PR.

try {
resolve(JSON.parse(rawData));
} catch (e) {
res.resume(); // consume response data to free up memory
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no need to call resume after end event as far as I'm aware. Can you explain why you're calling it here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From the node http docs:

if a 'response' event handler is added, then the data from the response object must be consumed, either by calling response.read() whenever there is a 'readable' event, or by adding a 'data' handler, or by calling the .resume() method. Until the data is consumed, the 'end' event will not fire.

To me, this implies that resume has nothing to consume when the 'end' event fires.

@mayurkale22 added that line to census so maybe he can weigh in?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed the res.resume() calls. I can add them back if we find they do have a benefit.

*/
export const detectResources = async (): Promise<Resource> => {
const resources: Array<Resource> = await Promise.all(
DETECTORS.map(d => d.detect())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if a detector throws?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a try / catch.

@mwear mwear force-pushed the resource_autodetection branch 2 times, most recently from 1ebaab9 to a8486fc Compare April 4, 2020 03:29
@mayurkale22
Copy link
Copy Markdown
Member

I think this is good to go, please resolve the merge conflicts.

@dyladan dyladan added the enhancement New feature or request label Apr 9, 2020
Copy link
Copy Markdown
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Copy Markdown
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm, nice documentation!

@mwear mwear force-pushed the resource_autodetection branch from a8486fc to 7a3ed94 Compare April 12, 2020 20:30
@dyladan dyladan merged commit 182e9ee into open-telemetry:master Apr 15, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
…dCapacity is set to None (open-telemetry#899)

* DynamoDB metrics for BatchGetItem fails when ReturnConsumedCapacity is set to NONE

* fix(unit): add unit test and change if

* fix(formatting): wrong formatting

* fix(formatting): formatting

Co-authored-by: Amir Blum <amir@aspecto.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants