@sentry/server-utils 10.60.0 → 10.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/build/cjs/index.js +4 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing-channel/mysql.js +12 -5
  4. package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
  5. package/build/cjs/redis/redis-dc-subscriber.js +47 -82
  6. package/build/cjs/redis/redis-dc-subscriber.js.map +1 -1
  7. package/build/cjs/tracing-channel.js +94 -0
  8. package/build/cjs/tracing-channel.js.map +1 -0
  9. package/build/cjs/vercel-ai/index.js +21 -0
  10. package/build/cjs/vercel-ai/index.js.map +1 -0
  11. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +362 -0
  12. package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
  13. package/build/esm/index.js +2 -0
  14. package/build/esm/index.js.map +1 -1
  15. package/build/esm/integrations/tracing-channel/mysql.js +13 -6
  16. package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
  17. package/build/esm/package.json +1 -1
  18. package/build/esm/redis/redis-dc-subscriber.js +45 -80
  19. package/build/esm/redis/redis-dc-subscriber.js.map +1 -1
  20. package/build/esm/tracing-channel.js +92 -0
  21. package/build/esm/tracing-channel.js.map +1 -0
  22. package/build/esm/vercel-ai/index.js +19 -0
  23. package/build/esm/vercel-ai/index.js.map +1 -0
  24. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +357 -0
  25. package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -0
  26. package/build/types/index.d.ts +4 -1
  27. package/build/types/index.d.ts.map +1 -1
  28. package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
  29. package/build/types/redis/redis-dc-subscriber.d.ts +7 -32
  30. package/build/types/redis/redis-dc-subscriber.d.ts.map +1 -1
  31. package/build/types/tracing-channel.d.ts +46 -0
  32. package/build/types/tracing-channel.d.ts.map +1 -0
  33. package/build/types/vercel-ai/index.d.ts +25 -0
  34. package/build/types/vercel-ai/index.d.ts.map +1 -0
  35. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
  36. package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -0
  37. package/build/types-ts3.8/index.d.ts +4 -1
  38. package/build/types-ts3.8/redis/redis-dc-subscriber.d.ts +7 -32
  39. package/build/types-ts3.8/tracing-channel.d.ts +46 -0
  40. package/build/types-ts3.8/vercel-ai/index.d.ts +25 -0
  41. package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +62 -0
  42. package/package.json +2 -2
@@ -0,0 +1,62 @@
1
+ import type { Span } from '@sentry/core';
2
+ import type { TracingChannel } from 'node:diagnostics_channel';
3
+ /** Drop the per-operation `callId` maps once the owning top-level operation settles (success or error). */
4
+ export declare function clearOperationId(data: VercelAiChannelMessage): void;
5
+ /** The lifecycle event types the `ai:telemetry` channel can carry. */
6
+ export type ChannelEventType = 'generateText' | 'streamText' | 'step' | 'languageModelCall' | 'executeTool' | 'embed' | 'rerank';
7
+ /**
8
+ * The context object the AI SDK passes through one tracing-channel call. It is the same object
9
+ * identity across `start`/`end`/`asyncEnd`/`error`, and Node's `tracingChannel` attaches
10
+ * `result`/`error` to it as the traced promise settles.
11
+ */
12
+ export interface VercelAiChannelMessage {
13
+ type: ChannelEventType;
14
+ event: Record<string, unknown>;
15
+ result?: unknown;
16
+ error?: unknown;
17
+ }
18
+ /**
19
+ * Platform-provided factory that returns a tracing channel for the given channel name. The factory
20
+ * is responsible for, when `start` fires, calling `transformStart(data)` and storing the returned
21
+ * span on `data._sentrySpan` so the subscriber's `asyncEnd`/`error` handlers can read it.
22
+ *
23
+ * Node passes `@sentry/opentelemetry/tracing-channel`, which uses `bindStore` to additionally make
24
+ * the span the active OTel context for the duration of the traced operation. That is what makes
25
+ * nested AI SDK operations (model calls, tool calls) become children of the enclosing span without
26
+ * any manual parent bookkeeping here.
27
+ */
28
+ type VercelAiTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;
29
+ /** Integration-level recording options, pinned at subscribe time so we never look the integration up per event. */
30
+ interface VercelAiChannelOptions {
31
+ recordInputs?: boolean;
32
+ recordOutputs?: boolean;
33
+ enableTruncation?: boolean;
34
+ }
35
+ /**
36
+ * Subscribe Sentry span handlers to the `ai` SDK's native telemetry tracing channel (`ai:telemetry`,
37
+ * available in `ai` >= 7) and emit fully-formed `gen_ai.*` spans directly — no OpenTelemetry span
38
+ * post-processing involved.
39
+ *
40
+ * The integration passes its options in directly (rather than us looking the integration up on every
41
+ * event); the global `dataCollection.genAI` default is still read from the client per event.
42
+ *
43
+ * Safe to always call: on `ai` versions that don't publish to the channel (e.g. < 7) nothing is
44
+ * ever emitted and this is inert, so there is no double-instrumentation against the OTel-based
45
+ * patcher. Idempotent.
46
+ */
47
+ export declare function subscribeVercelAiTracingChannel(tracingChannel: VercelAiTracingChannelFactory, options?: VercelAiChannelOptions): void;
48
+ /**
49
+ * Transform a channel `start` payload into the span that should be active for the operation. For
50
+ * `step` we deliberately don't open a span (model calls and tool calls are siblings under the
51
+ * invoke_agent span, matching the OTel-based output), so we reuse the active span and mark the
52
+ * payload to skip ending it.
53
+ */
54
+ export declare function createSpanFromMessage(data: VercelAiChannelMessage, channelOptions: VercelAiChannelOptions): Span | undefined;
55
+ /**
56
+ * Best-effort enrichment from the resolved value the AI SDK attaches to the channel context.
57
+ * Everything here is guarded: when a field is missing or the shape differs across `ai` versions,
58
+ * we simply don't set the attribute rather than emit a malformed span.
59
+ */
60
+ export declare function enrichSpanOnEnd(span: Span, data: VercelAiChannelMessage, channelOptions: VercelAiChannelOptions): void;
61
+ export {};
62
+ //# sourceMappingURL=vercel-ai-dc-subscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vercel-ai-dc-subscriber.d.ts","sourceRoot":"","sources":["../../../src/vercel-ai/vercel-ai-dc-subscriber.ts"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
@@ -4,5 +4,8 @@
4
4
  * @module
5
5
  */
6
6
  export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels, } from './redis/redis-dc-subscriber';
7
- export { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannel, RedisTracingChannelContextWithSpan, RedisTracingChannelFactory, RedisTracingChannelSubscribers, } from './redis/redis-dc-subscriber';
7
+ export { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannelFactory, } from './redis/redis-dc-subscriber';
8
+ export { bindTracingChannelToSpan } from './tracing-channel';
9
+ export { SentryTracingChannel, TracingChannelLifeCycleOptions, TracingChannelBindingHandle, TracingChannelPayloadWithSpan, } from './tracing-channel';
10
+ export { vercelAiIntegration } from './vercel-ai';
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { TracingChannel } from 'node:diagnostics_channel';
1
2
  import { Span } from '@sentry/core';
2
3
  export declare const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
3
4
  export declare const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
@@ -68,39 +69,13 @@ export interface RedisConnectData {
68
69
  */
69
70
  export type RedisDiagnosticChannelResponseHook = (span: Span, cmdName: string, cmdArgs: string[], result: unknown) => void;
70
71
  /**
71
- * Payload type observed by tracing-channel subscribers — the channel payload
72
- * with `_sentrySpan` stamped on it by the start handler so async/error
73
- * handlers downstream can read it back.
74
- */
75
- export type RedisTracingChannelContextWithSpan<T> = T & {
76
- _sentrySpan?: Span;
77
- };
78
- /** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */
79
- export interface RedisTracingChannelSubscribers<T> {
80
- start: (data: RedisTracingChannelContextWithSpan<T>) => void;
81
- asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;
82
- asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;
83
- end: (data: RedisTracingChannelContextWithSpan<T>) => void;
84
- error: (data: RedisTracingChannelContextWithSpan<T>) => void;
85
- }
86
- /** Minimal tracing-channel surface the subscriber depends on. */
87
- export interface RedisTracingChannel<T extends object> {
88
- subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;
89
- }
90
- /**
91
- * Platform-provided factory that returns a tracing channel for the given
92
- * channel name. Implementations are responsible for ensuring that, when the
93
- * channel's `start` event fires, the span returned by `transformStart(data)`
94
- * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`
95
- * handlers can read it.
72
+ * Platform-provided factory that creates a native tracing channel for the given name. The
73
+ * subscriber binds the span and its lifecycle onto the channel via `bindTracingChannelToSpan`,
74
+ * which propagates the active span through the runtime's async context.
96
75
  *
97
- * - Node passes `@sentry/opentelemetry/tracing-channel` which uses
98
- * `bindStore` to also propagate the span as the active OTel context.
99
- * - Deno (and other non-OTel runtimes) pass a portable wrapper around
100
- * `node:diagnostics_channel.tracingChannel` that just stamps
101
- * `data._sentrySpan` in `start` without `bindStore`.
76
+ * Both Node and Deno pass `node:diagnostics_channel`'s `tracingChannel` directly.
102
77
  */
103
- export type RedisTracingChannelFactory = <T extends object>(name: string, transformStart: (data: T) => Span) => RedisTracingChannel<T>;
78
+ export type RedisTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;
104
79
  /**
105
80
  * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel
106
81
  * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis
@@ -114,6 +89,6 @@ export type RedisTracingChannelFactory = <T extends object>(name: string, transf
114
89
  * re-subscribe.
115
90
  */
116
91
  export declare function subscribeRedisDiagnosticChannels(tracingChannel: RedisTracingChannelFactory, responseHook?: RedisDiagnosticChannelResponseHook): void;
117
- /** Test-only: reset module-local subscribe state. */
92
+ /** Test-only: detach all channel bindings and reset module-local subscribe state. */
118
93
  export declare function _resetRedisDiagnosticChannelsForTesting(): void;
119
94
  //# sourceMappingURL=redis-dc-subscriber.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { TracingChannel, TracingChannelSubscribers } from 'node:diagnostics_channel';
2
+ import { ExclusiveEventHintOrCaptureContext, Span } from '@sentry/core';
3
+ export type TracingChannelPayloadWithSpan<TData extends object> = TData & {
4
+ _sentrySpan?: Span;
5
+ };
6
+ export interface SentryTracingChannel<TData extends object = object> extends Pick<TracingChannel<TData, TracingChannelPayloadWithSpan<TData>>, Exclude<keyof TracingChannel<TData, TracingChannelPayloadWithSpan<TData>>, 'subscribe' | 'unsubscribe'>> {
7
+ subscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
8
+ unsubscribe(subscribers: Partial<TracingChannelSubscribers<TracingChannelPayloadWithSpan<TData>>>): void;
9
+ }
10
+ export interface TracingChannelLifeCycleOptions<TData extends object = object> {
11
+ /**
12
+ * Invoked with the span and the channel context object once the traced operation completes
13
+ * Use it to enrich the span from the result/error (branch on `'error' in data` / `'result' in data`) or to run cleanup.
14
+ */
15
+ beforeSpanEnd?: (span: Span, data: TracingChannelPayloadWithSpan<TData>) => void;
16
+ /**
17
+ * Whether a thrown error is captured as a Sentry event. The span is always marked with error status regardless. Defaults to `false`.
18
+ * You can alternatively pass a function that sets the ExclusiveEventHintOrCaptureContext on the captured error.
19
+ * Set `true` for instrumentations that own the error boundary, (e.g: route handlers)
20
+ * For database drivers, it is not recommended to set this at all.
21
+ */
22
+ captureError?: boolean | ((e: unknown) => ExclusiveEventHintOrCaptureContext);
23
+ }
24
+ /** Returned by {@link bindTracingChannelToSpan}: the bound channel plus a teardown handle. */
25
+ export interface TracingChannelBindingHandle<TData extends object = object> {
26
+ /**
27
+ * The tracing channel with the span bound into async context.
28
+ */
29
+ channel: SentryTracingChannel<TData>;
30
+ /**
31
+ * Tears down the binding: unsubscribes lifecycle handlers, when present, and unbinds the start store.
32
+ * Idempotent, and a no-op when no async context binding was available.
33
+ */
34
+ unbind: () => void;
35
+ }
36
+ /**
37
+ * Bind a span and its lifecycle to a tracing channel so the span becomes the active async context
38
+ * for the traced operation and is ended when the operation completes.
39
+ *
40
+ * `getSpan` may return `undefined` to opt a payload out entirely: nothing is bound, no span is
41
+ * tracked, and the active context is left untouched. Use it for events that ride the same channel
42
+ * but should reuse the enclosing span instead of opening (and ending) their own — e.g. an agent
43
+ * loop's per-step events, where ending a freshly opened span would close the parent prematurely.
44
+ */
45
+ export declare function bindTracingChannelToSpan<TData extends object>(channel: TracingChannel<TData, TData>, getSpan: (data: TracingChannelPayloadWithSpan<TData>) => Span | undefined, opts?: TracingChannelLifeCycleOptions<TData>): TracingChannelBindingHandle<TData>;
46
+ //# sourceMappingURL=tracing-channel.d.ts.map
@@ -0,0 +1,25 @@
1
+ type VercelAiOptions = {
2
+ /**
3
+ * Enable or disable input recording. Enabled if `dataCollection.genAI.inputs` (or the deprecated `sendDefaultPii` option) is `true`
4
+ * or if you set `isEnabled` to `true` in your ai SDK method telemetry settings.
5
+ * Integration-level options take precedence over global `dataCollection` config.
6
+ */
7
+ recordInputs?: boolean;
8
+ /**
9
+ * Enable or disable output recording. Enabled if `dataCollection.genAI.outputs` (or the deprecated `sendDefaultPii` option) is `true`
10
+ * or if you set `isEnabled` to `true` in your ai SDK method telemetry settings.
11
+ * Integration-level options take precedence over global `dataCollection` config.
12
+ */
13
+ recordOutputs?: boolean;
14
+ /**
15
+ * Enable or disable truncation of recorded input messages.
16
+ * Defaults to `true`.
17
+ */
18
+ enableTruncation?: boolean;
19
+ };
20
+ /**
21
+ * Auto-instrument the `ai` SDK's native telemetry tracing channel (ai >= 7).
22
+ */
23
+ export declare const vercelAiIntegration: (options?: VercelAiOptions | undefined) => import("@sentry/core").Integration;
24
+ export {};
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { Span } from '@sentry/core';
2
+ import { TracingChannel } from 'node:diagnostics_channel';
3
+ /** Drop the per-operation `callId` maps once the owning top-level operation settles (success or error). */
4
+ export declare function clearOperationId(data: VercelAiChannelMessage): void;
5
+ /** The lifecycle event types the `ai:telemetry` channel can carry. */
6
+ export type ChannelEventType = 'generateText' | 'streamText' | 'step' | 'languageModelCall' | 'executeTool' | 'embed' | 'rerank';
7
+ /**
8
+ * The context object the AI SDK passes through one tracing-channel call. It is the same object
9
+ * identity across `start`/`end`/`asyncEnd`/`error`, and Node's `tracingChannel` attaches
10
+ * `result`/`error` to it as the traced promise settles.
11
+ */
12
+ export interface VercelAiChannelMessage {
13
+ type: ChannelEventType;
14
+ event: Record<string, unknown>;
15
+ result?: unknown;
16
+ error?: unknown;
17
+ }
18
+ /**
19
+ * Platform-provided factory that returns a tracing channel for the given channel name. The factory
20
+ * is responsible for, when `start` fires, calling `transformStart(data)` and storing the returned
21
+ * span on `data._sentrySpan` so the subscriber's `asyncEnd`/`error` handlers can read it.
22
+ *
23
+ * Node passes `@sentry/opentelemetry/tracing-channel`, which uses `bindStore` to additionally make
24
+ * the span the active OTel context for the duration of the traced operation. That is what makes
25
+ * nested AI SDK operations (model calls, tool calls) become children of the enclosing span without
26
+ * any manual parent bookkeeping here.
27
+ */
28
+ type VercelAiTracingChannelFactory = <T extends object>(name: string) => TracingChannel<T, T>;
29
+ /** Integration-level recording options, pinned at subscribe time so we never look the integration up per event. */
30
+ interface VercelAiChannelOptions {
31
+ recordInputs?: boolean;
32
+ recordOutputs?: boolean;
33
+ enableTruncation?: boolean;
34
+ }
35
+ /**
36
+ * Subscribe Sentry span handlers to the `ai` SDK's native telemetry tracing channel (`ai:telemetry`,
37
+ * available in `ai` >= 7) and emit fully-formed `gen_ai.*` spans directly — no OpenTelemetry span
38
+ * post-processing involved.
39
+ *
40
+ * The integration passes its options in directly (rather than us looking the integration up on every
41
+ * event); the global `dataCollection.genAI` default is still read from the client per event.
42
+ *
43
+ * Safe to always call: on `ai` versions that don't publish to the channel (e.g. < 7) nothing is
44
+ * ever emitted and this is inert, so there is no double-instrumentation against the OTel-based
45
+ * patcher. Idempotent.
46
+ */
47
+ export declare function subscribeVercelAiTracingChannel(tracingChannel: VercelAiTracingChannelFactory, options?: VercelAiChannelOptions): void;
48
+ /**
49
+ * Transform a channel `start` payload into the span that should be active for the operation. For
50
+ * `step` we deliberately don't open a span (model calls and tool calls are siblings under the
51
+ * invoke_agent span, matching the OTel-based output), so we reuse the active span and mark the
52
+ * payload to skip ending it.
53
+ */
54
+ export declare function createSpanFromMessage(data: VercelAiChannelMessage, channelOptions: VercelAiChannelOptions): Span | undefined;
55
+ /**
56
+ * Best-effort enrichment from the resolved value the AI SDK attaches to the channel context.
57
+ * Everything here is guarded: when a field is missing or the shape differs across `ai` versions,
58
+ * we simply don't set the attribute rather than emit a malformed span.
59
+ */
60
+ export declare function enrichSpanOnEnd(span: Span, data: VercelAiChannelMessage, channelOptions: VercelAiChannelOptions): void;
61
+ export {};
62
+ //# sourceMappingURL=vercel-ai-dc-subscriber.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/server-utils",
3
- "version": "10.60.0",
3
+ "version": "10.62.0",
4
4
  "description": "Server Utilities for all Sentry JavaScript SDKs",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/server-utils",
@@ -86,7 +86,7 @@
86
86
  "@apm-js-collab/code-transformer": "^0.15.0",
87
87
  "@apm-js-collab/tracing-hooks": "^0.10.0",
88
88
  "@sentry/conventions": "^0.12.0",
89
- "@sentry/core": "10.60.0",
89
+ "@sentry/core": "10.62.0",
90
90
  "magic-string": "~0.30.0"
91
91
  },
92
92
  "devDependencies": {