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

feat(opentelemetry-sdk-node): automatically configure metrics exporter based on environment variables #5168

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bhaskarbanerjee
Copy link

@bhaskarbanerjee bhaskarbanerjee commented Nov 15, 2024

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • Test A

Checklist:

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

@bhaskarbanerjee bhaskarbanerjee requested a review from a team as a code owner November 15, 2024 21:31
Copy link

linux-foundation-easycla bot commented Nov 15, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@@ -334,6 +350,99 @@ export class NodeSDK {
);
}

public configureMetricProviderFromEnv(): MetricReader[] {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Author

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 {
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

Done

Comment on lines 42 to 44
{
"path": "../api-logs"
},
Copy link
Member

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?

Copy link
Author

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

Copy link
Author

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');
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@pichlermarc pichlermarc left a 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 🙌

Comment on lines 360 to 361
// ONLY if OTEL_METRICS_EXPORTER is set
if (enabledExporters.length === 0) {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@pichlermarc
Copy link
Member

Please also sign the CLA, otherwise we'll not be able to proceed with this PR. 🙂

@bhaskarbanerjee
Copy link
Author

@dyladan @pichlermarc @JacksonWeber Thanks for you review, I have updated the PR, seeking feedback.

Copy link
Member

@pichlermarc pichlermarc left a 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? 🙂

experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
sharedState.metricCollectors[0]._metricReader._exporter instanceof
ConsoleMetricExporter
);
assert(
Copy link
Member

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. 🙂

Copy link
Author

Choose a reason for hiding this comment

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

sure

Comment on lines +127 to +125
if (enabledExporters.includes('none')) {
diag.info(
`OTEL_METRICS_EXPORTER contains "none". Metric provider will not be initialized.`
);
Copy link
Member

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? 🙂

Copy link
Author

Choose a reason for hiding this comment

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

sure

@bhaskarbanerjee
Copy link
Author

@pichlermarc
I am unsure how the commit 73c2071 made it from user bhskrbnrj

Those changes are mine but that is not my user id. Let me see if I can remove that commit from my PR.

@bhaskarbanerjee
Copy link
Author

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?
I will keep this PR open until then. and once the other PR is merged, I will close this out.

Please advice @pichlermarc

@bhaskarbanerjee
Copy link
Author

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
@bhaskarbanerjee
Copy link
Author

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

@bhaskarbanerjee
Copy link
Author

@pichlermarc I have cleaned up the bad PR and addressed all review comments. Seeking your review on this commit

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.

[sdk-node] automatically configure metrics exporter based on enviornment variables
4 participants