feat: resource auto-detection#899
Conversation
Codecov Report❌ Patch coverage is 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
🚀 New features to boost your workflow:
|
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/EnvDetector.ts
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/GcpDetector.ts
Outdated
Show resolved
Hide resolved
mayurkale22
left a comment
There was a problem hiding this comment.
Overall LGTM, added a few comments in the first pass.
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Show resolved
Hide resolved
| * EnvDetector can be used to detect the presence of and create a Resource | ||
| * from the OTEL_RESOURCE_LABELS environment variable. | ||
| */ | ||
| export class EnvDetector { |
There was a problem hiding this comment.
I think specs is not yet defined for the env detector. Perhaps, we can open an issue in specs to start the discussion.
There was a problem hiding this comment.
packages/opentelemetry-resources/src/platform/node/detectors/GcpDetector.ts
Outdated
Show resolved
Hide resolved
d0e0cf5 to
db0df52
Compare
| "@opentelemetry/api": "^0.5.2", | ||
| "@opentelemetry/base": "^0.5.2" | ||
| "@opentelemetry/base": "^0.5.2", | ||
| "gcp-metadata": "^3.5.0" |
There was a problem hiding this comment.
Minor: latest available version is 4.0.0.
There was a problem hiding this comment.
It appears as though node 8 support was dropped in 4.0.0: https://github.com/googleapis/gcp-metadata/blob/master/CHANGELOG.md#-breaking-changes.
mayurkale22
left a comment
There was a problem hiding this comment.
Overall LGTM, thanks for the PR.
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Show resolved
Hide resolved
packages/opentelemetry-resources/src/platform/node/detectors/AwsEc2Detector.ts
Show resolved
Hide resolved
| try { | ||
| resolve(JSON.parse(rawData)); | ||
| } catch (e) { | ||
| res.resume(); // consume response data to free up memory |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
This came from: https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-resource-util/src/resource-utils.ts#L153. I can remove it if it's useless.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
What happens if a detector throws?
1ebaab9 to
a8486fc
Compare
|
I think this is good to go, please resolve the merge conflicts. |
a8486fc to
7a3ed94
Compare
…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>
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
detectResourcesmethod during setup, making this functionality opt-in. For example: