Skip to content

Commit d77a4fc

Browse files
committed
refactor(rivetkit): make traces server only lib
1 parent 0232d12 commit d77a4fc

File tree

7 files changed

+218
-90
lines changed

7 files changed

+218
-90
lines changed

pnpm-lock.yaml

Lines changed: 12 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rivetkit-typescript/packages/traces/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
],
1313
"exports": {
1414
".": {
15+
"browser": {
16+
"import": {
17+
"types": "./dist/tsup/browser.d.ts",
18+
"default": "./dist/tsup/browser.js"
19+
},
20+
"require": {
21+
"types": "./dist/tsup/browser.d.cts",
22+
"default": "./dist/tsup/browser.cjs"
23+
}
24+
},
1525
"import": {
1626
"types": "./dist/tsup/index.d.ts",
1727
"default": "./dist/tsup/index.js"
@@ -36,15 +46,15 @@
3646
"node": ">=18.0.0"
3747
},
3848
"scripts": {
39-
"build": "pnpm run compile:bare && tsup src/index.ts src/reader.ts",
49+
"build": "pnpm run compile:bare && tsup src/index.ts src/reader.ts src/browser.ts",
4050
"compile:bare": "tsx scripts/compile-bare.ts compile schemas/v1.bare -o dist/schemas/v1.ts",
4151
"check-types": "pnpm run compile:bare && tsc --noEmit",
4252
"test": "pnpm run compile:bare && vitest run"
4353
},
4454
"dependencies": {
4555
"@rivetkit/bare-ts": "^0.6.2",
4656
"cbor-x": "^1.6.0",
47-
"fdb-tuple": "^1.0.0",
57+
"@rivetkit/fdb-tuple": "https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2",
4858
"vbare": "^0.0.4"
4959
},
5060
"devDependencies": {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Browser stub for @rivetkit/traces
2+
// This file is used as the browser entry point to prevent Node.js-specific code from being bundled
3+
4+
import type {
5+
OtlpAnyValue,
6+
OtlpExportTraceServiceRequestJson,
7+
OtlpInstrumentationScope,
8+
OtlpKeyValue,
9+
OtlpResource,
10+
OtlpResourceSpans,
11+
OtlpScopeSpans,
12+
OtlpSpan,
13+
OtlpSpanEvent,
14+
OtlpSpanLink,
15+
OtlpSpanStatus,
16+
} from "./otlp.js";
17+
import type {
18+
EndSpanOptions,
19+
EventOptions,
20+
ReadRangeOptions,
21+
ReadRangeResult,
22+
ReadRangeWire,
23+
SpanHandle,
24+
SpanStatusInput,
25+
StartSpanOptions,
26+
Traces,
27+
TracesDriver,
28+
TracesOptions,
29+
UpdateSpanOptions,
30+
} from "./types.js";
31+
32+
function notSupported(name: string): never {
33+
throw new Error(
34+
`@rivetkit/traces: ${name} is not supported in the browser. Traces are only available on the server.`,
35+
);
36+
}
37+
38+
export function createTraces(
39+
_options: TracesOptions<OtlpResource>,
40+
): Traces<OtlpExportTraceServiceRequestJson> {
41+
notSupported("createTraces");
42+
}
43+
44+
export function encodeReadRangeWire(_wire: ReadRangeWire): Uint8Array {
45+
notSupported("encodeReadRangeWire");
46+
}
47+
48+
export function decodeReadRangeWire(_bytes: Uint8Array): ReadRangeWire {
49+
notSupported("decodeReadRangeWire");
50+
}
51+
52+
export function readRangeWireToOtlp(
53+
_wire: ReadRangeWire,
54+
_resource?: OtlpResource,
55+
): { otlp: OtlpExportTraceServiceRequestJson; clamped: boolean } {
56+
notSupported("readRangeWireToOtlp");
57+
}
58+
59+
// Re-export types (these are safe for browsers)
60+
export type {
61+
EndSpanOptions,
62+
EventOptions,
63+
ReadRangeOptions,
64+
ReadRangeResult,
65+
ReadRangeWire,
66+
SpanHandle,
67+
SpanStatusInput,
68+
StartSpanOptions,
69+
Traces,
70+
TracesDriver,
71+
TracesOptions,
72+
UpdateSpanOptions,
73+
OtlpAnyValue,
74+
OtlpExportTraceServiceRequestJson,
75+
OtlpInstrumentationScope,
76+
OtlpKeyValue,
77+
OtlpResource,
78+
OtlpResourceSpans,
79+
OtlpScopeSpans,
80+
OtlpSpan,
81+
OtlpSpanEvent,
82+
OtlpSpanLink,
83+
OtlpSpanStatus,
84+
};

0 commit comments

Comments
 (0)