-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(opentelemetry-node): add cloud/container resource detectors #214
Conversation
Tests are failing since some detectors generate spans. An example is HTTP spans being generated by GCP detector
ba8681a adds a proposal to filter out these spans when testing. To be discussed |
As discussed in today's meeting with @trentm
|
@david-luna This is still draft. I wasn't sure if this was ready for review yet. |
There was a linting issue happening in CI but not in local so it wasn't ready yet. Last commit contains a fix for |
Note on the lint failure.
Linting if failing because of a missing license file, was added in https://github.com/jsdom/tr46/tree/v1.0.0. The Any thoughts @trentm ? |
I think it is fine to add a fallback in the lint script for this. The package.json "license" field says MIT. The very next commit on the tr46 repo adds the license file that is then included in subsequent published versions. I think it would be fine to try a PR on node-fetch to update their whatwg-url dep, but I don't think that needs to block us here. |
const detectorsFromEnv = | ||
process.env['OTEL_NODE_RESOURCE_DETECTORS'] || 'all'; | ||
|
||
if (detectorsFromEnv === 'none') { | ||
return []; | ||
} | ||
|
||
const detectorKeys = | ||
detectorsFromEnv === 'all' | ||
? Object.keys(defaultDetectors) | ||
: detectorsFromEnv.split(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is slightly difference in auto-instr-node: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/dadf30828e7008df7b85c8bd7eaacb90770aac5c/metapackages/auto-instrumentations-node/src/utils.ts#L235-L244
E.g. OTEL_NODE_RESOURCE_DETECTORS=host,os,none
with a "none" in there the behaviour differs. Also if 'all' is one of the values in there.
Personally, I think it would be nice to .trim()
each value so OTEL_NODE_RESOURCE_DETECTORS=host, os
works. auto-instr-node
does trim in its handling of process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS
, FWIW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've applied your suggestions. Thanks :)
@@ -76,6 +76,7 @@ const testFixtures = [ | |||
// ------ trace b8467d (2 spans) ------ | |||
// span bc8a2c "POST" (3.8ms, SPAN_KIND_CLIENT, POST http://127.0.0.1:64972/echo -> 200) | |||
// +2ms `- span 4e7adf "POST" (1.1ms, SPAN_KIND_SERVER, POST http://127.0.0.1:64972/echo -> 200) | |||
// const spans = col.sortedSpans.slice(RESOURCE_DETECTOR_SPAN_COUNT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugging code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, I've missed that
Co-authored-by: Trent Mick <[email protected]>
@trentm I've added some tests since we can inspect the warnings when passing bogus values. With this I've realized the SDK was logging some errors that shouldn't be logged. I'm hesitant if wee need to add more tests for other scenarios like the behaviour when the value |
…ic/elastic-otel-node into dluna/128-cloud-resource-detectors
// hostDetectorSync is not currently in the OTel default, but may be added | ||
hostDetectorSync, | ||
], | ||
resourceDetectors: resolveDetectors(opts.resourceDetectors), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR. I wonder if eventually we may want to export something similar to getInstrumentations()
that enables a user to user our SDK and get the default set of detectors plus one or more custom detectors. Or perhaps this is something that is more generally solved with some concept of SDK plugins or extensions as briefly discussed on the OTel JS SIG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say if the number of detectors grow enough we will have a case for that API to be exported. We can discuss it and create an issue if we agree it's necessary
I think we are fine without the tests. Your call if you'd like to add more. |
Closes #128
This PR adds the container and the cloud resource detectors (alibaba, aws, azure & gcp). By default all are included unless the env var
OTEL_NODE_RESOURCE_DETECTORS
is set. I that case the distro includes according the value set in the environment. Some highlights:distro
detector may be excluded.@opentelemetry/auto-instrumentations-node
there are a couple of detectors not related to cloud/containers left to addQuestion
This detectors resolution gives more priority to setup via code rather than the environment setup via environment vars. I wonder if that's the behaviour we want 🤔
Vanilla SDK seems to have this behaviour too (link) and its
@opentelemetry/auto-instrumentations-node
the one looking up to env varOTEL_NODE_RESOURCE_DETECTORS