Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
abec2a1
fix(opentelemetry): declare sdk-trace (OTel JS 3.x) as an optional pe…
krassx Oct 21, 2026
c87271a
test(opentelemetry): run the span processor and OTLP path against rea…
krassx Oct 21, 2026
bcda215
feat(opentelemetry): map OTel API 1.10 AnyValue attributes deliberate…
krassx Oct 21, 2026
7df1741
test(packaging-guard): fail on any @opentelemetry deep import, packag…
krassx Oct 21, 2026
ca70e8d
fix(nextjs): zero-config OTel provider falls back to sdk-trace on Ope…
krassx Oct 21, 2026
8166650
docs(opentelemetry): OTel 3 compatibility notes, PROGRESS entry and c…
krassx Oct 21, 2026
c78c345
fix(opentelemetry,performance,nextjs): bounded total attribute serial…
krassx Oct 21, 2026
3331ef8
fix(performance,opentelemetry): null-tolerant scalar arrays, GenAI co…
krassx Oct 22, 2026
8640185
Merge remote-tracking branch 'origin/main' into fix/opentelemetry-3-c…
krassx Oct 22, 2026
069ae8f
fix(performance,protocol): bound attributes of every span before reda…
krassx Oct 22, 2026
519f433
fix(opentelemetry): derive child span kind from the safe attribute co…
krassx Oct 22, 2026
9d46782
fix(performance,opentelemetry): length caps no longer defeat redactio…
krassx Oct 22, 2026
6ab9b59
fix(performance): single length read, copy arrays on flatten, token-d…
krassx Oct 22, 2026
2c16518
fix(opentelemetry): never put the truncation marker inside bytesValue…
krassx Oct 22, 2026
63196be
fix(performance,protocol): boundary-less leaves back off before the l…
krassx Oct 22, 2026
7ef9e08
fix(performance,protocol): back off to the secret the cut lands in, n…
krassx Oct 22, 2026
b3ad7a8
test(protocol,performance): pin the start-check cap, the JWT-with-emb…
krassx Oct 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/nextjs-otel3-provider-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@bugsee/nextjs': minor
---

The zero-config OpenTelemetry provider now falls back to `@opentelemetry/sdk-trace` (its `TracerProvider`) when `@opentelemetry/sdk-trace-base` is not installed. OpenTelemetry JS 3 removed `sdk-trace-base`, so before this an OpenTelemetry 3 install silently left the zero-config provider `unavailable`. `sdk-trace-base` is still preferred when both are installed, so OpenTelemetry 1.x/2.x installs behave as before.

`@opentelemetry/sdk-trace` (`>=2.9.0`) is now declared as an optional peer next to `@opentelemetry/sdk-trace-base` (`>=1.0.0 <3`).
17 changes: 17 additions & 0 deletions .changeset/opentelemetry-3-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@bugsee/opentelemetry': minor
'@bugsee/performance': minor
'@bugsee/protocol': minor
---

Support OpenTelemetry JS 3.x (issue #94).

OpenTelemetry JS 3.0 removed `@opentelemetry/sdk-trace-base` and replaced it with `@opentelemetry/sdk-trace`, and `@opentelemetry/api` 1.10 widened span attributes to the spec's `AnyValue`. `@bugsee/opentelemetry` and `@bugsee/nextjs` (peer ranges) now declare `@opentelemetry/sdk-trace` (`>=2.9.0`) as an optional peer next to `@opentelemetry/sdk-trace-base` (now `>=1.0.0 <3`); `sdk-trace` exists from 2.9 and exports the same `TracerProvider`. Both stay optional: produce-only users install neither. On OpenTelemetry 3 register the processor with `new TracerProvider({ spanProcessors: [processor] })` from `@opentelemetry/sdk-trace` (on 3.x `sdk-trace` is the only SDK package and `BasicTracerProvider` no longer exists; `sdk-trace` 2.9+ exports the same `TracerProvider`). OpenTelemetry 3 itself needs Node.js 22.15 or newer; `@bugsee/opentelemetry` does not import OpenTelemetry and still runs on the Node versions the SDK supports.

Complex span attributes (OpenTelemetry API 1.10 `AnyValue`) are now handled deliberately. Known limitation, unchanged by this release: SQL literal redaction can be defeated by comments, backslash escapes and dollar quoting shifting its quote pairing (bugsee/bugsee-javascript#109). Consumed scalars and small homogeneous scalar arrays are unchanged (a scalar string is capped at 32 KiB); a byte array becomes base64; a `bigint` becomes a number when exact and decimal text otherwise (it used to reach the transaction as a value JSON cannot serialize); `null`, `undefined`, functions and symbols drop the attribute; nested maps and mixed arrays become a bounded JSON-safe copy that the span sanitizer and `setSpanFilter` now see as a tree, so nested sensitive keys (`user: { password }`, `http.request.headers: { authorization }`) are redacted by default. What remains complex is flattened to a bounded JSON string when the transaction is recorded. The copy never throws and is bounded in work as well as size (leaf, key, node, depth and length caps). A raw byte array that Bugsee exports itself (a `Uint8Array`, `ArrayBuffer` or `DataView` attribute on a span Bugsee produced) is sent as OTLP `bytesValue` (valid base64) when it fits (up to 6144 bytes) and as a `stringValue` carrying the truncation marker when it was cut, so a strict collector never sees a marker inside `bytesValue`; a consumed span's bytes are already a base64 string by then and export as `stringValue`. A URL attribute keeps exporting its href (credentials removed), an Error its name and message, and a Date its ISO string. Arrays of one scalar type that contain null entries pass through unchanged. The default sanitizer now also redacts the current GenAI content attributes (`gen_ai.input.messages`, `gen_ai.output.messages`, `gen_ai.system_instructions`, `gen_ai.tool.definitions`, `gen_ai.tool.call.arguments`, `gen_ai.tool.call.result`). One hostile attribute (a Proxy that throws, a cycle, an enormous string) no longer rejects the whole export batch.

`createBugseeSpanProcessor` now ignores `onEnd` after `shutdown()`.

The same bounding now applies to every span the SDK records itself (`setAttribute`, `recordChildSpan`, `recordExternal`), not only consumed OpenTelemetry spans: the nested redaction walk is only run on a bounded copy, with a shared per-span node and character budget (raw cyclic or branching values used to take seconds to forever). A key too long to keep has its value redacted; a statement cut by a length cap no longer leaves an open SQL literal in the clear, and a map leaf cut inside a token (a JWT after its payload, a `ghp_` prefix) drops the unfinished token, and an unbroken run such as `id_token=<jwt>` keeps its prefix but backs off before a secret the cut lands inside, including a JWT whose payload contains a second `eyJ` (a long map-leaf URL is cut back to `https:` by the ordinary token-boundary rule; a top-level string is only cut, because secret-shape scanning does not apply to it, as before: top-level strings, scalar arrays and nested map keys are not shape-scanned); scalar-array attribute values are stored as copies, never aliases of the application's array; and a statement carried as a map or array has its string leaves' literals redacted. `isSensitiveKey` (`@bugsee/protocol`) now normalises its denylist once.

New exports from `@bugsee/protocol`: `unfinishedSecretStart`. New exports from `@bugsee/performance` (some also re-exported from `@bugsee/opentelemetry`): `normalizeAttributes`, `normalizeAttributeValue`, `flattenAttributes`, `stringifyAnyValue`, `safeAnyValue`, `asBytes`, `boundedBase64` and the `MAX_ATTRIBUTE_*` limits.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ jobs:
# <NONEXISTENT> hole the e2e job exists to close.
- name: Harness unit tests (vitest)
run: pnpm exec turbo run test:unit
env:
# This job runs Node 22, which OpenTelemetry JS 3.x supports (>= 22.15): the otel3-compat suite must
# RUN here. With this set, a too-old Node fails that suite instead of skipping it silently.
BUGSEE_REQUIRE_OTEL3: '1'

# End-to-end harnesses: the REAL SDK booted in real node/bun/deno processes against a
# mock collector, plus the real-framework suites (nuxt / sveltekit / astro / next).
Expand Down
22 changes: 22 additions & 0 deletions dev-packages/otel3-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@bugsee/otel3-compat",
"version": "0.0.0",
"private": true,
"type": "module",
"description": "Runs @bugsee/opentelemetry against a REAL @opentelemetry/sdk-trace@3 (OpenTelemetry JS 3.x). Separate from the package itself because sdk-trace@3 peers @opentelemetry/api >=1.10 <1.11 while sdk-trace-base@2 (the package's own devDependency) peers <1.10: one workspace package cannot satisfy both. Node >=22.15 only (OTel 3's engines floor); the suite skips cleanly below it.",
"engines": {
"node": ">=18"
},
"scripts": {
"typecheck": "tsc --noEmit",
"test:unit": "vitest run",
"test": "vitest run"
},
"devDependencies": {
"@bugsee/opentelemetry": "workspace:*",
"@bugsee/performance": "workspace:*",
"@opentelemetry/api": "^1.10.0",
"@opentelemetry/sdk-trace": "^3.0.0"
},
"license": "MIT"
}
53 changes: 53 additions & 0 deletions dev-packages/otel3-compat/src/node-gate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest';
import {
nodeAtLeast,
OTEL3_MIN_NODE,
otel3Required,
otel3Supported,
skipIsForbidden,
} from './node-gate';

describe('nodeAtLeast', () => {
it.each([
['22.15.0', true],
['22.15.1', true],
['22.16.0', true],
['23.0.0', true],
['24.15.0', true],
['22.14.9', false],
['22.12.0', false],
['20.19.0', false],
['18.20.4', false],
])('%s -> %s against the OTel 3 floor', (version, expected) => {
expect(nodeAtLeast(version)).toBe(expected);
});

it('treats missing trailing parts as zero and honours a custom floor', () => {
expect(nodeAtLeast('22.15')).toBe(true);
expect(nodeAtLeast('22')).toBe(false);
expect(nodeAtLeast('20.6.0', [20, 6, 0])).toBe(true);
expect(nodeAtLeast('20.5.9', [20, 6, 0])).toBe(false);
});

it('pins the floor to what sdk-trace@3 declares', () => {
expect(OTEL3_MIN_NODE).toEqual([22, 15, 0]);
});

it('agrees with the running Node', () => {
expect(otel3Supported).toBe(nodeAtLeast(process.versions.node));
});
});

describe('skipIsForbidden (BUGSEE_REQUIRE_OTEL3)', () => {
it('is on only for the exact value "1"', () => {
expect(skipIsForbidden({ BUGSEE_REQUIRE_OTEL3: '1' })).toBe(true);
for (const v of [undefined, '', '0', 'true', 'yes', ' 1']) {
expect(skipIsForbidden({ BUGSEE_REQUIRE_OTEL3: v })).toBe(false);
}
expect(skipIsForbidden({})).toBe(false);
});

it('reads the real environment for the exported flag', () => {
expect(otel3Required).toBe(skipIsForbidden(process.env));
});
});
36 changes: 36 additions & 0 deletions dev-packages/otel3-compat/src/node-gate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// OpenTelemetry JS 3.x declares `engines.node >=22.15.0` on core / resources / sdk-trace. CI runs Node 22
// (>= 22.15 satisfies it), but a developer machine can have an older Node: the OTel 3 suites stand down below
// that floor instead of failing, unless BUGSEE_REQUIRE_OTEL3=1 (see skipIsForbidden).

/** The first Node release OpenTelemetry JS 3.x supports. */
export const OTEL3_MIN_NODE = [22, 15, 0] as const;

/** Compare a dotted Node version (`process.versions.node` shape) against `min`. */
export function nodeAtLeast(
version: string,
min: readonly [number, number, number] = OTEL3_MIN_NODE,
): boolean {
const parts = version.split('.').map((part) => Number.parseInt(part, 10));
for (let i = 0; i < 3; i++) {
const have = parts[i] ?? 0;
const need = min[i] as number;
if (have !== need) return have > need;
}
return true;
}

/** True when the running Node can load OpenTelemetry JS 3.x. */
export const otel3Supported: boolean = nodeAtLeast(process.versions.node);

/** Suite title suffix that states WHY the suite is skipped, so a skip in the report is self-explanatory. */
export const OTEL3_SKIP_NOTE = 'needs Node >= 22.15 (OpenTelemetry JS 3.x engines floor)';

/**
* Whether a skip of the OTel 3 suite must be treated as a FAILURE. A silent skip on a runner whose Node is too
* old would let the 3.x coverage rot unnoticed, so the CI job that runs Node 22 sets `BUGSEE_REQUIRE_OTEL3=1`.
*/
export function skipIsForbidden(env: Record<string, string | undefined>): boolean {
return env.BUGSEE_REQUIRE_OTEL3 === '1';
}

export const otel3Required: boolean = skipIsForbidden(process.env);
Loading