Skip to content

refactor(otlp-transformer, resources): route platform-specific code through #platform - #7173

Merged
overbalance merged 3 commits into
open-telemetry:mainfrom
embrace-io:overbalance/platform-adoptions
Oct 9, 2026
Merged

overbalance merged 3 commits into
open-telemetry:mainfrom
embrace-io:overbalance/platform-adoptions

Conversation

@overbalance

Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

Two universal packages still chose platform behavior at runtime inside shared code: @opentelemetry/otlp-transformer checked typeof Buffer to pick a base64 encoder, and @opentelemetry/resources read globalThis.process.argv0 inside a try/catch to build the default service name. Both patterns need Node.js types in browser-reachable code.

A follow-up PR (#7142) adds npm run typecheck:browser, which checks every browser build with DOM types and no @types/node. This PR is one of the changes that make that check passable.

Short description of the changes

  • otlp-transformer adopts #platform with the same layout as the other universal packages: an imports["#platform"] map, src/platform/node/index.ts and src/platform/browser/index.ts as tsdown entries. The Node.js barrel encodes base64 with Buffer; the browser barrel keeps the existing btoa loop. JSON_ENCODER.encodeUint8Array calls it. The 3.x migration guide lists the package.
  • resources makes defaultServiceName a #platform unit. The Node.js implementation keeps the cache, the process.argv0 read and its guard for runtimes that stub process; the browser implementation returns unknown_service and never touches globalThis.process.
  • Tests: base64 encoding of small, empty and 100,000-byte inputs under mocha and karma; defaultServiceName with an empty argv0, and in the browser build.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

  • npm run compile, npm run lint, npm run test, npm run test:browser, npm run test:webworker from the root.
  • npm run verify-pack, which loads every #platform branch of otlp-transformer from the packed tarball and checks that the published declarations do not reference #platform.

Checklist:

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

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (a38a5f7) to head (c2ae708).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7173   +/-   ##
=======================================
  Coverage   95.02%   95.02%           
=======================================
  Files         382      385    +3     
  Lines       13532    13539    +7     
  Branches     3126     3125    -1     
=======================================
+ Hits        12859    12866    +7     
  Misses        673      673           
Files with missing lines Coverage Δ
...ntal/packages/otlp-transformer/src/common/utils.ts 100.00% <100.00%> (ø)
...es/otlp-transformer/src/platform/browser/base64.ts 100.00% <100.00%> (ø)
...kages/otlp-transformer/src/platform/node/base64.ts 100.00% <100.00%> (ø)
...ckages/opentelemetry-resources/src/ResourceImpl.ts 98.96% <100.00%> (ø)
...detectors/platform/browser/default-service-name.ts 100.00% <100.00%> (ø)
...-resources/src/detectors/platform/browser/index.ts 100.00% <100.00%> (ø)
...rc/detectors/platform/node/default-service-name.ts 100.00% <ø> (ø)
...try-resources/src/detectors/platform/node/index.ts 100.00% <100.00%> (ø)
🚀 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.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-09 15:47 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@overbalance
overbalance marked this pull request as ready for review October 9, 2026 02:27
@overbalance
overbalance requested review from a team as code owners October 9, 2026 02:27
@overbalance overbalance added this to the SDK 3.0 milestone Oct 9, 2026
@overbalance
overbalance added this pull request to the merge queue Oct 9, 2026
Merged via the queue into open-telemetry:main with commit 2cc7958 Oct 9, 2026
25 checks passed
@overbalance
overbalance deleted the overbalance/platform-adoptions branch October 9, 2026 15:31
pacocartones added a commit to pacocartones/opentelemetry-js that referenced this pull request Oct 13, 2026
Port the factories to the #platform layout from open-telemetry#7141, open-telemetry#7170 and open-telemetry#7173: the
package entry points export createOtlp*Exporter from '#platform', the removed
src/platform/index.ts files stay removed, convertLegacyHttpOptionsWithoutEnv
moves with its module to platform/node/configuration, and the metrics proto
browser factory takes the browser configuration type.

Signed-off-by: pacocartones <pacocartones@users.noreply.github.com>
Assisted-by: Claude Opus 5.5
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