Skip to content

feat: add @opentelemetry/browser-sdk package#288

Merged
overbalance merged 69 commits into
open-telemetry:mainfrom
david-luna:otel-browser
Jun 12, 2026
Merged

feat: add @opentelemetry/browser-sdk package#288
overbalance merged 69 commits into
open-telemetry:mainfrom
david-luna:otel-browser

Conversation

@david-luna

@david-luna david-luna commented May 22, 2026

Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

Follow up on #224. This PR is now targeting a feature branch so we can break down the implementation in smaller PRs and merge it to main once its ready.

Short description of the changes

  • add a new @opentelemetry/browser package
  • all comment in the prior PR were resolved except feat: add @opentelemetry/browser package #224 (comment)
  • for this last comment the package now exports startBrowserSdk function instead of the combine utility. The reason is there is no other use case. Either you start one single SDK or both. The combine function stays internal until we decide to add a third signal (metrics).

This PR aims to define the main API to configure the signals (logs, traces) separate and together. Also it explores on how to provide a flexible way for defaults without having to pay the toll on bundle size.

For those who want to read

Add a new package named @opentelemetry/browser which holds the setup of the different signals separately and provides a main function which composes them together into an SDK interface with stop method.

This approach has taken into consideration that configuring all signals into a single SDK class presents challenges when it comes to tree shaking and bundlers cannot anticipate which modules are going to be used. So the configuration has been split by signal and needs to be imported explicitly by the consumer making easier for bundlers to analyse the code and remove unused modules. The package provides different entry points depending on which signal you want to configure

Subpath Purpose
@opentelemetry/browser/logs startLogsSdk — setup logs
@opentelemetry/browser/traces startTracesSdk — setup traces
@opentelemetry/browser/sdk startBrowserSdk — setup both

with this approach you can configure a single signal

import { startLogsSdk } from '@opentelemetry/browser/logs';

const logsSdk = startLogsSdk({
  logLevel: 'DEBUG',
  serviceName: 'my-service',
  exportConfig: {
    url: 'https://collector.mycompany.com/v1/logs',
    headers: { foo: 'bar' }
  },
  logRecordLimits: { attributeCountLimit: 128 },
});

or both at the same time

import { startBrowserSdk } from '@opentelemetry/browser/sdk';

const sdk = startBrowserSdk({
  logLevel: 'DEBUG',
  serviceName: 'my-service',
  serviceVersion: '1.0',
  resourceAttributes: {
    'browser.has_speech_recognition': typeof SpeechRecognition === 'function'
  },
  exportConfig: {
    url: 'https://collector.mycompany.com',
    headers: { foo: 'bar' }
  },
  // Optional - logs signal configuration. Default empty empty
  logs: {
    logRecordLimits: { attributeCountLimit: 128 },
  },
  // Optional - traces signal configuration. Default empty empty
  traces: {
    spanLimits: { attributeCountLimit: 128 },
  },
});

Note: the intent is to have all necessary components to start/build SDKs in this package. This PR does not go any further than providing a small API (3 functions) and configurations types for several reasons:

  • keep the review scope small so we have meaningful conversations. We can add more components in follow-up PRs also keeping the scope small
  • this also enables other contributors to add code to this package so it's not a solo quest but rather a collaboration effort
  • IMO as a consequence of the points above the velocity of implementing this package will increase. Also I will not be holding/blocking anything in a huge PR (this is already big enough).

Also this PR targets a feature branch and not main so the package won't be published until the SIG decides it has all it need to be public.

For more details on the package and its design refer to the README.md file of the package.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests

Checklist:

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

david-luna and others added 29 commits March 31, 2026 11:50
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
@david-luna
david-luna requested a review from a team as a code owner May 22, 2026 17:11
@martinkuba

Copy link
Copy Markdown
Contributor

I wonder if the directory this package is in should be called sdk instead of browser, which does not describe what the package is (even though it maps to the published name, but that has a specific reasoning). We already don't match it, as we have instrumentation directory that contains package called browser-instrumentation.

@david-luna

Copy link
Copy Markdown
Contributor Author

I wonder if the directory this package is in should be called sdk instead of browser, which does not describe what the package is (even though it maps to the published name, but that has a specific reasoning). We already don't match it, as we have instrumentation directory that contains package called browser-instrumentation.

If we want to align with the existing instrumentation package then we should:

  • change the package name to @opentelemetry/browser-sdk
  • rename the folder to sdk

I'm okay with that. I would add a review to the package exports section for better naming. This might look weird

import { strartBrowserSdk } from '@opentelemetry/browser-sdk/sdk';

// rest of the code

Comment thread packages/sdk/src/types.ts Outdated
Comment thread packages/browser/src/sdk.ts Outdated
Comment thread packages/sdk/src/types.ts
Comment thread packages/sdk/src/sdk.ts Outdated
Comment thread packages/sdk/src/sdk.ts Outdated
Comment thread packages/sdk/src/types.ts
Comment thread packages/browser/src/sdk.ts Outdated
Comment thread packages/browser/src/traces.ts Outdated
@david-luna david-luna changed the title feat: add @opentelemetry/browser package feat: add @opentelemetry/browser-sdk package Jun 12, 2026
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
url: ${{ steps.deploy.outputs.page_url }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
@david-luna
david-luna changed the base branch from feature/sdk-package to main June 12, 2026 14:32
Comment thread packages/sdk/package.json
"repository": {
"type": "git",
"url": "git+https://github.com/open-telemetry/opentelemetry-browser.git",
"directory": "packages/browser"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TODO: fix after merge

@overbalance
overbalance merged commit 701ac7c into open-telemetry:main Jun 12, 2026
7 checks passed
@otelbot-browser otelbot-browser Bot mentioned this pull request Jul 9, 2026
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.

5 participants