-
Notifications
You must be signed in to change notification settings - Fork 810
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-sdk-node): automatically configure metrics exporter based on environment variables #5168
base: main
Are you sure you want to change the base?
Conversation
@@ -334,6 +350,99 @@ export class NodeSDK { | |||
); | |||
} | |||
|
|||
public configureMetricProviderFromEnv(): MetricReader[] { |
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.
This doesn't need to be a method on the class because it isn't accessing this
. Making it a function improves minification and tree-shaking. It looks like the function wouldn't need to be exported too, keeping the external API surface as small as possible. It should at least not be public.
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.
done
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.
Done
/** | ||
* @Returns param value, if set else returns the default value | ||
*/ | ||
private getValueInMillis(envName: string, defaultValue: number): number { |
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.
This could just be a function because it doesn't access this
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.
Done
{ | ||
"path": "../api-logs" | ||
}, |
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.
Did you mean to remove this?
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.
No, that was a mistake
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.
reverted
// ONLY if OTEL_METRICS_EXPORTER is set | ||
if (enabledExporters.length === 0) { | ||
diag.info('OTEL_METRICS_EXPORTER is empty. Using default otlp exporter.'); | ||
// enabledExporters.push('otlp'); |
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.
Clean up stray commented line of 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.
Done
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.
thanks for working on this 🙌
// ONLY if OTEL_METRICS_EXPORTER is set | ||
if (enabledExporters.length === 0) { |
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.
Hmm, this will always log though even if OTEL_METRICS_EXPORTER
is undefined. I think it'd probably the best to check if process.env.OTEL_METRIC_EXPORTER
is undefined
and returning an empty array right at the beginning of the function to avoid that any log spurious log messages pop up that are not applicable to what the user actually configured.
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.
Done
Please also sign the CLA, otherwise we'll not be able to proceed with this PR. 🙂 |
@dyladan @pichlermarc @JacksonWeber Thanks for you review, I have updated the PR, seeking feedback. |
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.
Thanks for addressing the comments 🙌
Thanks for signing the CLA. 👍 Looks like there's still one commit that does not have the CLA signed (is it using different e-mail, perhaps 🤔) - having all commits authorized by the CLA is a required check, so we'll not be able to merge this PR without that. Would you mind having another look? 🙂
sharedState.metricCollectors[0]._metricReader._exporter instanceof | ||
ConsoleMetricExporter | ||
); | ||
assert( |
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.
please use assert.strictEqual()
wherever possible in the tests that were added. 🙂
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.
sure
if (enabledExporters.includes('none')) { | ||
diag.info( | ||
`OTEL_METRICS_EXPORTER contains "none". Metric provider will not be initialized.` | ||
); |
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.
could we make this return here to reduce nesting below? 🙂
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.
sure
@pichlermarc Those changes are mine but that is not my user id. Let me see if I can remove that commit from my PR. |
That PR is not from my fork (might be I was fiddling with the PR from UI). The use name seems automated (i.e. stripped off all vowels from my name). Are you OK if I raise a new PR (by including all of these PR comments in there? Please advice @pichlermarc |
41f0adf
to
0ee9a27
Compare
I had to rollback all commits in this PR because the first commit was bad (not from a legit fork). I shall soon update this PR with the latest code. @pichlermarc |
1 similar comment
I had to rollback all commits in this PR because the first commit was bad (not from a legit fork). I shall soon update this PR with the latest code. @pichlermarc |
@pichlermarc I have cleaned up the bad PR and addressed all review comments. Seeking your review on this commit |
Which problem is this PR solving?
Provides ability to auto instrument metrics based on environment variables
Fixes #4551
Short description of the changes
Type of change
Please delete options that are not relevant.
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
Checklist: