@sentry/server-utils 10.59.0 → 10.61.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.
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/server-utils",
3
- "version": "10.59.0",
3
+ "version": "10.61.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,21 +86,13 @@
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.59.0",
89
+ "@sentry/core": "10.61.0",
90
90
  "magic-string": "~0.30.0"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@types/node": "^18.19.1",
94
94
  "vite": "^6.4.3"
95
95
  },
96
- "peerDependencies": {
97
- "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
98
- },
99
- "peerDependenciesMeta": {
100
- "vite": {
101
- "optional": true
102
- }
103
- },
104
96
  "scripts": {
105
97
  "build": "run-p build:transpile build:types",
106
98
  "build:dev": "yarn build",