Skip to content

feat(sdk): implement exporter metrics#6480

Open
anuraaga wants to merge 14 commits intoopen-telemetry:mainfrom
anuraaga:exporter-metrics
Open

feat(sdk): implement exporter metrics#6480
anuraaga wants to merge 14 commits intoopen-telemetry:mainfrom
anuraaga:exporter-metrics

Conversation

@anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Mar 6, 2026

Which problem is this PR solving?

I am helping implement SDK metrics.

https://opentelemetry.io/docs/specs/semconv/otel/sdk-metrics/#metric-otelsdkexporterspaninflight

This PR adds metrics for exporters. otel-js has a looot of exporters so this PR is pretty big and somewhat complex. I tried to design things as sensibly as possible but happy to hear any suggestions.

I have added important tests but there are still more tests to add for sanity checking the actual exporter factories, and also need to add zipkin. But as this PR is quite complex, it will be great to get an initial review while working on it.

/cc @trentm

Short description of the changes

Add metrics for export operations

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

  • Unit tests

Checklist:

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

@anuraaga anuraaga requested review from a team as code owners March 6, 2026 08:48
@anuraaga anuraaga marked this pull request as draft March 6, 2026 08:48
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 92.99363% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.64%. Comparing base (17e9f91) to head (9988382).

Files with missing lines Patch % Lines
...packages/otlp-exporter-base/src/ExporterMetrics.ts 86.27% 7 Missing ⚠️
...ackages/otlp-exporter-base/src/OTLPExporterBase.ts 0.00% 2 Missing ⚠️
...ges/otlp-exporter-base/src/otlp-export-delegate.ts 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6480      +/-   ##
==========================================
- Coverage   95.73%   95.64%   -0.10%     
==========================================
  Files         364      378      +14     
  Lines       11826    11979     +153     
  Branches     2765     2788      +23     
==========================================
+ Hits        11322    11457     +135     
- Misses        504      522      +18     
Files with missing lines Coverage Δ
...ges/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts 100.00% <100.00%> (ø)
...al/packages/exporter-logs-otlp-grpc/src/semconv.ts 100.00% <100.00%> (ø)
...-otlp-http/src/platform/browser/OTLPLogExporter.ts 100.00% <100.00%> (ø)
...ogs-otlp-http/src/platform/node/OTLPLogExporter.ts 100.00% <100.00%> (ø)
...al/packages/exporter-logs-otlp-http/src/semconv.ts 100.00% <100.00%> (ø)
...otlp-proto/src/platform/browser/OTLPLogExporter.ts 100.00% <100.00%> (ø)
...gs-otlp-proto/src/platform/node/OTLPLogExporter.ts 100.00% <100.00%> (ø)
...l/packages/exporter-logs-otlp-proto/src/semconv.ts 100.00% <100.00%> (ø)
.../exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts 100.00% <100.00%> (ø)
...l/packages/exporter-trace-otlp-grpc/src/semconv.ts 100.00% <100.00%> (ø)
... and 23 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

signal,
url: options.url,
meterProvider,
errorAttributes: (error: unknown) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Java implementation had an easier time with it since it instruments the transports themselves. I couldn't see how to do it here though because of RetryingTransport. So I went with this hacky, but non-invasive approach.

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

@anuraaga Thanks. This is just some early notes. I'm learning the exporter packages. My main thought so far is whether limiting to just the OTLP-exporters could simplify a little bit. Or at least avoid adding to the @opentelemetry/core API to limit the blast radius a bit.

);
}

startExport(request: Request): (error: unknown) => void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of Request (which is pretty overloaded), perhaps Internal or InternalRepresentation, closer to what is used for the same thing in the otlp-exporter-base package? I'm still learning this code, so this is a fairly naive suggestion. I.e. take with a grain of salt.

* SPDX-License-Identifier: Apache-2.0
*/

export interface ISignal<Request> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This interface ISignal and another one in "opentelemetry-core/src/internal/ExporterMetrics.ts" I think could have a better name. These are specific to exporter SDK Metrics.

@trentm
Copy link
Contributor

trentm commented Mar 11, 2026

@anuraaga We discussed on the JS SIG call today: both the Jaeger and Zipkin exporters are deprecated. We don't need to add new features to them.

It was mentioned that the Prometheus exporter is a non-OTLP exporter, however. Should that exporter be getting an implementation of any of the otel.sdk.exporter.* metrics?

@anuraaga anuraaga marked this pull request as ready for review March 12, 2026 03:41
@anuraaga
Copy link
Contributor Author

anuraaga commented Mar 12, 2026

Thanks @trentm - this is probably as good a time to mark as ready for review though not surprised if there are still cleanups needed. Notably, allowing metric exporter to be wired up was much trickier than I wished, though not sure of any alternative.

Also, unlike the other PRs this one is pretty huge so I am planning on wiring up in opentelemetry-sdk-node in a separate PR after this one.

It was mentioned that the Prometheus exporter is a non-OTLP exporter, however. Should that exporter be getting an implementation of any of the otel.sdk.exporter.* metrics?

Prometheus is a MetricReader so it doesn't get the exporter metrics, luckily.

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.

2 participants