-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(sdk-trace): implement span start/end metrics #6213
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
53d90a7
feat: implement span start/end metrics
anuraaga 8f7d498
Style
anuraaga 3ef44da
Commit
anuraaga d573088
Commit
anuraaga 2af11e6
Compile
anuraaga 0fcaed8
Finish
anuraaga d212424
Tweak test
anuraaga f336a00
Tweak better
anuraaga 12dc161
Proper fix
anuraaga 28328d4
Changelog
anuraaga 91ba67f
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
anuraaga 568aef4
Cleanup
anuraaga 6379c36
Initialize tracer metrics in NodeSDK
anuraaga 8ba3cf4
semconv
anuraaga ddf2814
Make SDK tests default to no exporter
anuraaga 26a9d38
Stutter
anuraaga 49c10d5
Add guard
anuraaga feb1621
Code block
anuraaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,12 @@ describe('Node SDK', () => { | |
|
|
||
| setGlobalTracerProviderSpy = Sinon.spy(trace, 'setGlobalTracerProvider'); | ||
| setGlobalLoggerProviderSpy = Sinon.spy(logs, 'setGlobalLoggerProvider'); | ||
|
|
||
| // need to set these to none, since the default value is 'otlp'. Tests either | ||
| // provide exporters programatically or reset to an appropriate value. | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| process.env.OTEL_LOGS_EXPORTER = 'none'; | ||
| process.env.OTEL_METRICS_EXPORTER = 'none'; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
|
|
@@ -124,13 +130,10 @@ describe('Node SDK', () => { | |
| delete process.env.OTEL_METRICS_EXPORTER; | ||
| delete process.env.OTEL_PROPAGATORS; | ||
| delete process.env.OTEL_TRACES_EXPORTER; | ||
| delete process.env.OTEL_NODE_EXPERIMENTAL_SDK_METRICS; | ||
| }); | ||
|
|
||
| it('should not register more than the minimal SDK components', async () => { | ||
| // need to set these to none, since the default value is 'otlp' | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| process.env.OTEL_LOGS_EXPORTER = 'none'; | ||
| process.env.OTEL_METRICS_EXPORTER = 'none'; | ||
| const sdk = new NodeSDK({ | ||
| autoDetectResources: false, | ||
| }); | ||
|
|
@@ -272,9 +275,6 @@ describe('Node SDK', () => { | |
| }); | ||
|
|
||
| it('should register a meter provider if a reader is provided', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| // which sets up an exporter and affects the context manager | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const exporter = new ConsoleMetricExporter(); | ||
| const metricReader = new PeriodicExportingMetricReader({ | ||
| exporter: exporter, | ||
|
|
@@ -303,9 +303,6 @@ describe('Node SDK', () => { | |
| }); | ||
|
|
||
| it('should register a meter provider if multiple readers are provided', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| // which sets up an exporter and affects the context manager | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const consoleExporter = new ConsoleMetricExporter(); | ||
| const inMemoryExporter = new InMemoryMetricExporter( | ||
| AggregationTemporality.CUMULATIVE | ||
|
|
@@ -347,9 +344,6 @@ describe('Node SDK', () => { | |
| }); | ||
|
|
||
| it('should show deprecation warning when using metricReader option', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| // which sets up an exporter and affects the context manager | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const exporter = new ConsoleMetricExporter(); | ||
| const metricReader = new PeriodicExportingMetricReader({ | ||
| exporter: exporter, | ||
|
|
@@ -378,9 +372,6 @@ describe('Node SDK', () => { | |
| }); | ||
|
|
||
| it('should not show deprecation warning when using metricReaders option', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| // which sets up an exporter and affects the context manager | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const exporter = new ConsoleMetricExporter(); | ||
| const metricReader = new PeriodicExportingMetricReader({ | ||
| exporter: exporter, | ||
|
|
@@ -409,8 +400,6 @@ describe('Node SDK', () => { | |
| }); | ||
|
|
||
| it('should not register meter provider when metricReaders is empty array', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const sdk = new NodeSDK({ | ||
| metricReaders: [], | ||
| autoDetectResources: false, | ||
|
|
@@ -431,8 +420,68 @@ describe('Node SDK', () => { | |
| await sdk.shutdown(); | ||
| }); | ||
|
|
||
| it('should register a meter provider to the tracer provider if both initialized and metrics enabled', async () => { | ||
| process.env.OTEL_NODE_EXPERIMENTAL_SDK_METRICS = 'true'; | ||
| const exporter = new ConsoleMetricExporter(); | ||
| const metricReader = new PeriodicExportingMetricReader({ | ||
| exporter: exporter, | ||
| exportIntervalMillis: 100, | ||
| exportTimeoutMillis: 100, | ||
| }); | ||
|
|
||
| const sdk = new NodeSDK({ | ||
| metricReader: metricReader, | ||
| traceExporter: new ConsoleSpanExporter(), | ||
| autoDetectResources: false, | ||
| }); | ||
|
|
||
| sdk.start(); | ||
|
|
||
| assertDefaultContextManagerRegistered(); | ||
| assertDefaultPropagatorRegistered(); | ||
|
|
||
| assert.strictEqual(setGlobalTracerProviderSpy.callCount, 1); | ||
| const tracerProvider = setGlobalTracerProviderSpy.lastCall.args[0]; | ||
| assert.ok(tracerProvider instanceof NodeTracerProvider); | ||
| assert.ok( | ||
| (tracerProvider as any)._config.meterProvider instanceof MeterProvider | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't great but couldn't think of anything better. Let me know if you have any ideas |
||
| ); | ||
|
|
||
| assert.ok(metrics.getMeterProvider() instanceof MeterProvider); | ||
|
|
||
| await sdk.shutdown(); | ||
| }); | ||
|
|
||
| it('should not register a meter provider to the tracer provider if both initialized but metrics disabled', async () => { | ||
| const exporter = new ConsoleMetricExporter(); | ||
| const metricReader = new PeriodicExportingMetricReader({ | ||
| exporter: exporter, | ||
| exportIntervalMillis: 100, | ||
| exportTimeoutMillis: 100, | ||
| }); | ||
|
|
||
| const sdk = new NodeSDK({ | ||
| metricReader: metricReader, | ||
| traceExporter: new ConsoleSpanExporter(), | ||
| autoDetectResources: false, | ||
| }); | ||
|
|
||
| sdk.start(); | ||
|
|
||
| assertDefaultContextManagerRegistered(); | ||
| assertDefaultPropagatorRegistered(); | ||
|
|
||
| assert.strictEqual(setGlobalTracerProviderSpy.callCount, 1); | ||
| const tracerProvider = setGlobalTracerProviderSpy.lastCall.args[0]; | ||
| assert.ok(tracerProvider instanceof NodeTracerProvider); | ||
| assert.equal((tracerProvider as any)._config.meterProvider, undefined); | ||
|
|
||
| assert.ok(metrics.getMeterProvider() instanceof MeterProvider); | ||
|
|
||
| await sdk.shutdown(); | ||
| }); | ||
|
|
||
| it('should register a logger provider if a log record processor is provided', async () => { | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const logRecordExporter = new InMemoryLogRecordExporter(); | ||
| const logRecordProcessor = new SimpleLogRecordProcessor( | ||
| logRecordExporter | ||
|
|
@@ -604,9 +653,6 @@ describe('Node SDK', () => { | |
| } | ||
|
|
||
| it('should register meter views when provided', async () => { | ||
| // need to set OTEL_TRACES_EXPORTER to none since default value is otlp | ||
| // which sets up an exporter and affects the context manager | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| const exporter = new InMemoryMetricExporter( | ||
| AggregationTemporality.CUMULATIVE | ||
| ); | ||
|
|
@@ -1163,6 +1209,9 @@ describe('Node SDK', () => { | |
|
|
||
| beforeEach(() => { | ||
| stubLogger = Sinon.stub(diag, 'info'); | ||
| delete process.env.OTEL_LOGS_EXPORTER; | ||
| delete process.env.OTEL_METRICS_EXPORTER; | ||
| delete process.env.OTEL_TRACES_EXPORTER; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
|
|
@@ -1303,8 +1352,6 @@ describe('Node SDK', () => { | |
|
|
||
| it('should apply OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT and OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT', async () => { | ||
| // arrange | ||
| process.env.OTEL_TRACES_EXPORTER = 'none'; | ||
| process.env.OTEL_METRICS_EXPORTER = 'none'; | ||
| process.env.OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT = '2'; | ||
| process.env.OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT = '10'; | ||
|
|
||
|
|
@@ -1355,6 +1402,9 @@ describe('Node SDK', () => { | |
| beforeEach(() => { | ||
| infoStub = Sinon.stub(diag, 'info'); | ||
| warnStub = Sinon.stub(diag, 'warn'); | ||
| delete process.env.OTEL_LOGS_EXPORTER; | ||
| delete process.env.OTEL_METRICS_EXPORTER; | ||
| delete process.env.OTEL_TRACES_EXPORTER; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
|
|
@@ -1684,6 +1734,9 @@ describe('Node SDK', () => { | |
|
|
||
| beforeEach(() => { | ||
| stubLoggerError = Sinon.stub(diag, 'warn'); | ||
| delete process.env.OTEL_LOGS_EXPORTER; | ||
| delete process.env.OTEL_METRICS_EXPORTER; | ||
| delete process.env.OTEL_TRACES_EXPORTER; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wiring up metrics to tracer caused some impact on unrelated tests. This seemed like a reasonable default, but let me know how it looks
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 think this is reasonable. I think these process.env settings can bleed out to other running .test.ts files in the same package, because mocha runs all the tests in the same process. However, that was already the case here.