Skip to content

Conversation

@overbalance
Copy link
Contributor

What problem is this solving?

Browser and Edge Runtime consumers importing trace or log serializers inadvertently bundle @opentelemetry/sdk-metrics due to the barrel export. sdk-metrics uses setImmediate, which is unavailable in Edge Runtime, causing build warnings.

Tree-shaking cannot solve this because sdk-metrics has runtime dependencies that bundlers cannot statically eliminate. The import graph pulls in code that references setImmediate regardless of what you actually use.

Short description of changes

  • Add subpath exports to package.json for signal-specific imports:
    • @opentelemetry/otlp-transformer/trace - trace serializers only
    • @opentelemetry/otlp-transformer/logs - log serializers only
    • @opentelemetry/otlp-transformer/metrics - metrics serializers only
  • Export JsonTraceSerializer, ProtobufTraceSerializer from ./trace
  • Export JsonLogsSerializer, ProtobufLogsSerializer from ./logs
  • Export JsonMetricsSerializer, ProtobufMetricsSerializer from ./metrics

This follows existing precedent in @opentelemetry/otlp-exporter-base, which has ./node-http and ./browser-http subpath exports.

This is non-breaking. The main entry point continues to export everything.

Usage:

// Before: pulls in sdk-metrics
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';

// After: only trace code bundled
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer/trace';

Testing

  • Existing tests pass
  • Verified Edge Runtime builds without warnings using Next.js 15 middleware
  • Verified subpath imports resolve correctly for both ESM and CJS

@overbalance overbalance requested a review from a team as a code owner December 8, 2025 21:01
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.41%. Comparing base (0a1a631) to head (2d45fb0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6199   +/-   ##
=======================================
  Coverage   95.41%   95.41%           
=======================================
  Files         317      317           
  Lines        9460     9460           
  Branches     2199     2199           
=======================================
  Hits         9026     9026           
  Misses        434      434           
🚀 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.

@overbalance overbalance enabled auto-merge December 8, 2025 21:16
@pichlermarc
Copy link
Member

Hmm, looking at the code, I'd say the setImmediate call there is not strictly necessary.
The common code-path for the ConsoleMetricExporter runs synchronously too without any issues.

WDYT about removing the call to setImmediate() and instead invoking the callback directly to solve the problem?

@overbalance overbalance disabled auto-merge December 9, 2025 09:37
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