Skip to content

Commit b383a39

Browse files
committed
fix(traces): separate entrypoints (#4119)
# Description Refactored the traces package to improve module organization by: 1. Creating dedicated entry points for specific functionality: - Added `encoding.ts` for ReadRangeWire encoding/decoding functions - Added `otlp-entry.ts` for OTLP-related functionality 2. Updated imports across the codebase to use these new entry points: - Changed imports from `@rivetkit/traces/reader` to `@rivetkit/traces/encoding` - Added path mappings in tsconfig.json for the new entry points - Updated package.json exports to expose the new entry points 3. Updated the build script to include the new entry points in the build process ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Verified that all imports resolve correctly and the application builds successfully. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes
1 parent 302cf97 commit b383a39

11 files changed

Lines changed: 87 additions & 62 deletions

File tree

frontend/src/components/actors/actor-inspector-context.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/actors/actor-traces.tsx

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

rivetkit-typescript/packages/rivetkit/src/inspector/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Unsubscribe } from "nanoevents";
33
import type { UpgradeWebSocketArgs } from "@/actor/router-websocket-endpoints";
44
import type { AnyActorInstance, RivetMessageEvent } from "@/mod";
55
import type { ToClient } from "@/schemas/actor-inspector/mod";
6-
import { encodeReadRangeWire } from "@rivetkit/traces";
6+
import { encodeReadRangeWire } from "@rivetkit/traces/encoding";
77
import {
88
CURRENT_VERSION as INSPECTOR_CURRENT_VERSION,
99
TO_CLIENT_VERSIONED as toClient,

rivetkit-typescript/packages/rivetkit/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"@/*": ["./src/*"],
88
"@rivetkit/workflow-engine": ["../workflow-engine/src/index.ts"],
99
"@rivetkit/traces": ["../traces/src/index.ts"],
10+
"@rivetkit/traces/encoding": ["../traces/src/encoding.ts"],
11+
"@rivetkit/traces/otlp": ["../traces/src/otlp-entry.ts"],
1012
// Used for test fixtures
1113
"rivetkit": ["./src/mod.ts"],
1214
"rivetkit/utils": ["./src/utils.ts"]

rivetkit-typescript/packages/rivetkit/tsup.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import defaultConfig from "../../../tsup.base.ts";
66
export default defineConfig({
77
...defaultConfig,
88
outDir: "dist/tsup/",
9+
esbuildOptions(options) {
10+
options.external = options.external ?? [];
11+
options.external.push("@rivetkit/traces", "@rivetkit/traces/encoding", "@rivetkit/traces/otlp");
12+
},
913
define: {
1014
"globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL": process.env
1115
.CUSTOM_RIVETKIT_DEVTOOLS_URL

rivetkit-typescript/packages/traces/package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,32 @@
2626
"default": "./dist/tsup/index.cjs"
2727
}
2828
},
29-
"./reader": {
29+
"./encoding": {
3030
"import": {
31-
"types": "./dist/tsup/reader.d.ts",
32-
"default": "./dist/tsup/reader.js"
31+
"types": "./dist/tsup/encoding.d.ts",
32+
"default": "./dist/tsup/encoding.js"
3333
},
3434
"require": {
35-
"types": "./dist/tsup/reader.d.cts",
36-
"default": "./dist/tsup/reader.cjs"
35+
"types": "./dist/tsup/encoding.d.cts",
36+
"default": "./dist/tsup/encoding.cjs"
37+
}
38+
},
39+
"./otlp": {
40+
"import": {
41+
"types": "./dist/tsup/otlp-entry.d.ts",
42+
"default": "./dist/tsup/otlp-entry.js"
43+
},
44+
"require": {
45+
"types": "./dist/tsup/otlp-entry.d.cts",
46+
"default": "./dist/tsup/otlp-entry.cjs"
3747
}
3848
}
3949
},
4050
"engines": {
4151
"node": ">=18.0.0"
4252
},
4353
"scripts": {
44-
"build": "pnpm run compile:bare && tsup src/index.ts src/reader.ts",
54+
"build": "pnpm run compile:bare && tsup src/index.ts src/index.browser.ts src/encoding.ts src/otlp-entry.ts",
4555
"compile:bare": "tsx scripts/compile-bare.ts compile schemas/v1.bare -o dist/schemas/v1.ts",
4656
"check-types": "pnpm run compile:bare && tsc --noEmit",
4757
"test": "pnpm run compile:bare && vitest run"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
CURRENT_VERSION,
3+
READ_RANGE_VERSIONED,
4+
type ReadRangeWire,
5+
} from "../schemas/versioned.js";
6+
7+
export type { ReadRangeWire };
8+
9+
export function encodeReadRangeWire(wire: ReadRangeWire): Uint8Array {
10+
return READ_RANGE_VERSIONED.serializeWithEmbeddedVersion(
11+
wire,
12+
CURRENT_VERSION,
13+
);
14+
}
15+
16+
export function decodeReadRangeWire(bytes: Uint8Array): ReadRangeWire {
17+
return READ_RANGE_VERSIONED.deserializeWithEmbeddedVersion(bytes);
18+
}

rivetkit-typescript/packages/traces/src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
export {
22
createTraces,
33
} from "./traces.js";
4-
export {
5-
decodeReadRangeWire,
6-
encodeReadRangeWire,
7-
readRangeWireToOtlp,
8-
} from "./read-range.js";
94
export type {
105
EndSpanOptions,
116
EventOptions,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export { readRangeWireToOtlp } from "./read-range.js";
2+
export {
3+
anyValueFromCborBytes,
4+
anyValueFromJs,
5+
base64FromBytes,
6+
hexFromBytes,
7+
type OtlpAnyValue,
8+
type OtlpExportTraceServiceRequestJson,
9+
type OtlpInstrumentationScope,
10+
type OtlpKeyValue,
11+
type OtlpResource,
12+
type OtlpResourceSpans,
13+
type OtlpScopeSpans,
14+
type OtlpSpan,
15+
type OtlpSpanEvent,
16+
type OtlpSpanLink,
17+
type OtlpSpanStatus,
18+
} from "./otlp.js";

rivetkit-typescript/packages/traces/src/read-range.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { decode as decodeCbor } from "cbor-x";
22
import {
3-
CURRENT_VERSION,
4-
READ_RANGE_VERSIONED,
53
type Attributes,
64
type Chunk,
75
type ReadRangeWire,
@@ -87,17 +85,6 @@ function spanKey(spanId: Uint8Array | SpanId): string {
8785
return hexFromBytes(normalizeBytes(spanId));
8886
}
8987

90-
export function encodeReadRangeWire(wire: ReadRangeWire): Uint8Array {
91-
return READ_RANGE_VERSIONED.serializeWithEmbeddedVersion(
92-
wire,
93-
CURRENT_VERSION,
94-
);
95-
}
96-
97-
export function decodeReadRangeWire(bytes: Uint8Array): ReadRangeWire {
98-
return READ_RANGE_VERSIONED.deserializeWithEmbeddedVersion(bytes);
99-
}
100-
10188
export function readRangeWireToOtlp(
10289
wire: ReadRangeWire,
10390
resource?: OtlpResource,

0 commit comments

Comments
 (0)