You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(scope)!: add scoped mode; remove OTEL_INSTRUMENT_FETCH env var (#11)
Add a scoped/embeddable mode to `setupOtel()` via a new `register: false`
option, backed by an internal provider holder (`src/scope.ts`). In scoped mode
the library builds and holds its own tracer/logger providers and routes
`withSpan` / `createLogger` / `createInstrumentedFetch` through them, leaving the
host app's global OpenTelemetry untouched. The shared context manager and W3C
propagator are still installed if absent (needed for span nesting and trace
propagation), and auto fetch instrumentation defaults off in scoped mode (it
wraps the process-global `fetch`). `OtelHandle` now also exposes
`tracerProvider` / `loggerProvider` so embedders can build extra tracers or
attach processors.
Remove the `OTEL_INSTRUMENT_FETCH` environment variable (shipped in 2.1.0). It
only toggled the process-global fetch wrap on/off and never addressed the
underlying provider-takeover problem that scoped mode now solves. Fetch
instrumentation is still controlled by the `setupOtel({ instrumentFetch })`
option, and individual clients can be traced with `createInstrumentedFetch()`.
BREAKING CHANGE: the OTEL_INSTRUMENT_FETCH environment variable is removed. Use
the `instrumentFetch` option to toggle fetch instrumentation, or `register:
false` for scoped mode.
|`setupOtel(options): OtelHandle`| Boots OTLP/HTTP traces + logs. Idempotent. Returns `{ shutdown(), tracerProvider, loggerProvider }`. Pass `register: false` for scoped mode (no global takeover).|
51
51
|`isOtelActive(): boolean`| Returns `true` if `setupOtel` has already run in this process. |
52
52
|`instrumentFetch(options?): FetchInstrumentation`| Low-level wrap of `globalThis.fetch` for CLIENT spans + W3C propagation. Returns `{ unpatch() }`. `setupOtel` calls this on Bun; on Node it prefers native undici. |
53
53
|`createInstrumentedFetch(baseFetch?, options?): typeof fetch`| Returns a NEW instrumented fetch (CLIENT spans + W3C propagation) wrapping `baseFetch` (default `globalThis.fetch`) without touching the global. For SDKs that take a `fetch` option. |
@@ -113,7 +113,6 @@ Standard OpenTelemetry env vars always take precedence over `SetupOtelOptions`:
Copy file name to clipboardExpand all lines: docs/configuration.mdx
-9Lines changed: 0 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -183,14 +183,6 @@ setupOtel({
183
183
});
184
184
```
185
185
186
-
Or disable it from the environment — no code change or redeploy of app logic required:
187
-
188
-
```bash
189
-
OTEL_INSTRUMENT_FETCH=false
190
-
```
191
-
192
-
`OTEL_INSTRUMENT_FETCH` accepts `true` / `1` (force on) and `false` / `0` (disable), and takes precedence over both the `instrumentFetch` option and the default. The object form (`mode`, `ignore`) still configures _how_ fetch is traced whenever instrumentation is on.
193
-
194
186
You can force it on even without an exporter endpoint:
195
187
196
188
```ts
@@ -236,7 +228,6 @@ The package always excludes its own OTLP trace and log exporter endpoints from f
Copy file name to clipboardExpand all lines: docs/guides/fetch-instrumentation.mdx
-18Lines changed: 0 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,22 +19,6 @@ When a traces endpoint is configured, setup instruments fetch by default. The st
19
19
20
20
The standalone `instrumentFetch()` export always performs the `globalThis.fetch` wrap, and `createInstrumentedFetch()` wraps a single fetch instance (for SDKs) without touching the global.
21
21
22
-
## Enabling and disabling
23
-
24
-
Pass `instrumentFetch: false` to turn it off, or `true` to force it on even without an endpoint:
The `OTEL_INSTRUMENT_FETCH` environment variable overrides both the option and the default — `true` / `1` forces it on, `false` / `0` disables it. Because env wins over code (matching the rest of the package's configuration), you can silence noisy or expensive fetch spans in production without changing application code:
31
-
32
-
```bash
33
-
OTEL_INSTRUMENT_FETCH=false
34
-
```
35
-
36
-
The env var only flips the on/off decision; when instrumentation stays on, the object form still applies — `OTEL_INSTRUMENT_FETCH=true` alongside `instrumentFetch: { mode: "global", ignore }` keeps your `mode` and `ignore`.
37
-
38
22
## What each fetch span contains
39
23
40
24
For an outbound request, fetch instrumentation creates a span with:
@@ -141,8 +125,6 @@ If fetch is already wrapped by this package, a second call does not stack anothe
141
125
142
126
The implementation uses a global symbol marker to remember the original fetch. That guard works even if two copies of the package are loaded, such as Bun consuming TypeScript source while another path consumes the built ESM bundle.
143
127
144
-
`setupOtel()` is idempotent too: the first call wins, so a later `setupOtel({ instrumentFetch: false })` cannot turn off instrumentation that an earlier call already enabled. Decide on the first call, or use `OTEL_INSTRUMENT_FETCH`, which is read whenever setup actually runs.
0 commit comments