@sentry/server-utils 11.15.0 → 11.16.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.
@@ -162,6 +162,7 @@ async function wrapServerRequestHandler(config, handler) {
162
162
  Object.assign(attributes, (0, _sentry_core.httpHeadersToSpanAttributes)(headers, dataCollection));
163
163
  Object.assign(attributes, config.attributes);
164
164
  attributes[_sentry_conventions_attributes.SENTRY_OP] = _sentry_conventions_op.HTTP_SERVER;
165
+ attributes[_sentry_conventions_attributes.SENTRY_KIND] = "server";
165
166
  return (0, _sentry_core.startSpanManual)({
166
167
  name,
167
168
  attributes
@@ -1 +1 @@
1
- {"version":3,"file":"index.request-handler.js","names":["isError","DEBUG_BUILD","debug","captureException","winterCGRequestToRequestData","isServedTunnelRequest","startRequestSession","classifyResponseStreaming","safeCallback","DEBUG_BUILD","captureBodyFromWinterCGRequest","parseStringToURLObject","continueTrace","getHttpSpanDetailsFromUrlObject","SENTRY_SEGMENT_NAME_SOURCE","hasSpanStreamingEnabled","HTTP_SPAN_NAME_FALLBACK","HTTP_REQUEST_BODY_SIZE","USER_AGENT_ORIGINAL","winterCGHeadersToDict","getClientIPAddress","CLIENT_ADDRESS","CLIENT_PORT","NETWORK_PROTOCOL_NAME","httpHeadersToSpanAttributes","SENTRY_OP","HTTP_SERVER","startSpanManual","SPAN_STATUS_ERROR","setHttpStatus","getCurrentScope","withIsolationScope","withScope","hasSpansEnabled","isStaticAssetRequest"],"sources":["../../src/utils/monitorStream.ts","../../src/utils/wrapServerRequestHandler.ts"],"sourcesContent":["import { debug, isError } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\n/**\n * Monitor the source without reading ahead or treating cancellation as a source failure.\n *\n * `onDone` runs once, while the returned stream is still open: before it closes, before it errors,\n * or when the consumer cancels it. A runtime can end the request when the response body closes\n * (Cloudflare Workers then reject `waitUntil`), so work that `onDone` starts must begin first.\n */\nexport function monitorStream(\n stream: ReadableStream<Uint8Array>,\n onDone: () => void,\n onError: (error: unknown) => void,\n): ReadableStream<Uint8Array> {\n let reader: ReadableStreamDefaultReader<Uint8Array>;\n let finished = false;\n const finish = (error?: { error: unknown }): void => {\n if (finished) {\n return;\n }\n finished = true;\n // A callback that throws must not fail the response body.\n try {\n // A source that stops on `request.signal` errors with an `AbortError` when the client\n // disconnects, which is a cancellation too.\n if (error && !(isError(error.error) && error.error.name === 'AbortError')) {\n onError(error.error);\n }\n onDone();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error when a monitored stream finished:', e);\n }\n };\n\n return new ReadableStream<Uint8Array>(\n {\n // Locks the source only once the stream exists, so a constructor that throws leaves it usable.\n start() {\n reader = stream.getReader();\n // A source can fail while no one reads from it. A cancelled reader closes normally; only a\n // source failure should be captured as an error.\n void reader.closed.then(\n () => finish(),\n error => finish({ error }),\n );\n },\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finish();\n controller.close();\n reader.releaseLock();\n } else {\n controller.enqueue(value);\n }\n } catch (error) {\n finish({ error });\n controller.error(error);\n reader.releaseLock();\n }\n },\n async cancel(reason) {\n finish();\n try {\n await reader.cancel(reason);\n } finally {\n reader.releaseLock();\n }\n },\n },\n { highWaterMark: 0 },\n );\n}\n","import {\n CLIENT_ADDRESS,\n CLIENT_PORT,\n HTTP_REQUEST_BODY_SIZE,\n NETWORK_PROTOCOL_NAME,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n USER_AGENT_ORIGINAL,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport type { Client, Mechanism, Scope, SpanAttributes } from '@sentry/core';\nimport {\n captureBodyFromWinterCGRequest,\n captureException,\n continueTrace,\n getCurrentScope,\n getHttpSpanDetailsFromUrlObject,\n hasSpansEnabled,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n safeCallback,\n setHttpStatus,\n SPAN_STATUS_ERROR,\n startSpanManual,\n winterCGHeadersToDict,\n winterCGRequestToRequestData,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type { ServerRequestOptions } from '@sentry/core/server';\nimport {\n _INTERNAL_isServedTunnelRequest as isServedTunnelRequest,\n classifyResponseStreaming,\n getClientIPAddress,\n isStaticAssetRequest,\n startRequestSession,\n} from '@sentry/core/server';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { monitorStream } from './monitorStream';\n\nexport interface ServerRequestHandlerConfig {\n request: Request;\n client: Client;\n /** The isolation scope of this request. */\n isolationScope: Scope;\n /** The options of the runtime's integration for incoming requests. */\n options: ServerRequestOptions<Request, Response> | undefined;\n /** Origin of the span, e.g. `auto.http.deno`. */\n origin: string;\n /** Mechanism of errors that the handler or the response stream throws. Omit to not capture them. */\n mechanism?: Mechanism;\n /** The address and port of the socket, if the runtime knows them. */\n getSocketAddress?: () => { address: string; port?: number } | undefined;\n /** The matched route of the server framework, e.g. `/users/:id`. Sets `http.route` and the span name. */\n routeName?: string;\n /** Span attributes that only the runtime knows, e.g. the route parameters. */\n attributes?: SpanAttributes;\n /**\n * Called in the scope of the continued trace, before the span starts. Lets the runtime continue\n * its own trace, e.g. the trace that Cloudflare exports for the invocation.\n */\n onTraceContinued?: () => void;\n /** Whether the response streams. Return `undefined` to use the default classification. */\n isStreamingResponse?: (response: Response) => boolean | undefined;\n /**\n * Called once when the request is done: when the response is returned, when a streamed body\n * finishes, or when the handler throws (then without a response).\n */\n onDone?: (response: Response | undefined) => void;\n}\n\n/**\n * Wraps a handler of a web `Request`, as used by `Deno.serve`, `Bun.serve` and Cloudflare Workers.\n *\n * It records the request session, attaches the request data and body, continues the incoming\n * trace, creates the `http.server` span, and captures errors that the handler throws. The rules\n * follow core's `node:http` server code:\n *\n * - `OPTIONS` and `HEAD` requests get no span and no body capture.\n * - The static asset filter applies only to `GET`.\n * - The span and the session of a streamed response end when the stream finishes.\n *\n * The handler can return no response, as Bun's `fetch` does after a WebSocket upgrade.\n */\nexport async function wrapServerRequestHandler<R extends Response | undefined = Response>(\n config: ServerRequestHandlerConfig,\n handler: () => R | Promise<R>,\n): Promise<R> {\n const { request, client, isolationScope, options, mechanism } = config;\n\n const method = request.method.toUpperCase();\n const captureError = (error: unknown): void => {\n if (mechanism) {\n captureException(error, { mechanism });\n }\n };\n\n const socketAddress = config.getSocketAddress?.();\n // Without `AsyncLocalStorage`, all requests share one isolation scope, so clear what an earlier\n // request left on it: the merge keeps its body, and its response context would stay set.\n isolationScope.setSDKProcessingMetadata({\n normalizedRequest: { ...winterCGRequestToRequestData(request), data: undefined },\n ipAddress: socketAddress?.address,\n });\n isolationScope.setContext('response', null);\n\n // Tunnel requests get no session, body or span, whether the SDK or the app answers them. The app answers them with\n // `intercept: false`, from its own code, so its errors are still captured.\n if (isServedTunnelRequest(request, client)) {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n config.onDone?.(response);\n }\n }\n\n const endSession = options?.sessions\n ? startRequestSession(client, {\n requestIsolationScope: isolationScope,\n sessionFlushingDelayMS: options.sessionFlushingDelayMS,\n })\n : undefined;\n const finish = (response: Response | undefined): void => {\n endSession?.();\n config.onDone?.(response);\n };\n const isStreamingResponse = (response: Response): boolean => {\n const classification = config.isStreamingResponse?.(response);\n return typeof classification === 'boolean' ? classification : classifyResponseStreaming(response).isStreaming;\n };\n\n if (method === 'OPTIONS' || method === 'HEAD') {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n finish(response);\n }\n }\n\n const dataCollection = client.getDataCollectionOptions();\n const effectiveBodySize =\n options?.maxRequestBodySize ?? (dataCollection.httpBodies.includes('incomingRequest') ? 'medium' : 'none');\n const ignoreRequestBody = options?.ignoreRequestBody;\n if (\n method !== 'GET' &&\n effectiveBodySize !== 'none' &&\n // If the filter throws, skip the body so it cannot leak data the filter was meant to hide.\n !(\n ignoreRequestBody &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreRequestBody`, skipping the body:' : '',\n () => ignoreRequestBody(request.url, request),\n () => true,\n )\n )\n ) {\n await captureBodyFromWinterCGRequest(request, isolationScope, effectiveBodySize);\n }\n\n const urlObject = parseStringToURLObject(request.url);\n const urlPath = urlObject ? `${urlObject.pathname}${urlObject.search}` : '/';\n const createSpan = shouldCreateSpan(client, options, request, urlPath);\n\n return continueTrace(\n {\n sentryTrace: request.headers.get('sentry-trace') || '',\n baggage: request.headers.get('baggage'),\n },\n async () => {\n config.onTraceContinued?.();\n\n if (!createSpan) {\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n captureError(e);\n finish(undefined);\n throw e;\n }\n if (response) {\n isolationScope.setContext('response', { status_code: response.status });\n }\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => finish(response)),\n inRequestScope(captureError),\n );\n }\n\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n config.origin,\n request,\n config.routeName,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !hasSpanStreamingEnabled(client)\n ? rawName\n : method || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes[HTTP_REQUEST_BODY_SIZE] = parseInt(contentLength, 10);\n }\n const userAgent = request.headers.get('user-agent');\n if (userAgent) {\n attributes[USER_AGENT_ORIGINAL] = userAgent;\n }\n\n const headers = winterCGHeadersToDict(request.headers);\n if (dataCollection.userInfo) {\n // `client.address` is the originating client, so a forwarding header wins over the socket, which\n // behind a proxy holds the proxy's address. The socket port is the proxy's too, so `client.port`\n // stays unset then.\n const forwardedAddress = getClientIPAddress(headers);\n if (forwardedAddress) {\n attributes[CLIENT_ADDRESS] = forwardedAddress;\n } else if (socketAddress) {\n attributes[CLIENT_ADDRESS] = socketAddress.address;\n if (socketAddress.port !== undefined) {\n attributes[CLIENT_PORT] = socketAddress.port;\n }\n }\n }\n\n // describes the OSI application-layer protocol (http), not the scheme (might be https)\n attributes[NETWORK_PROTOCOL_NAME] = 'http';\n Object.assign(attributes, httpHeadersToSpanAttributes(headers, dataCollection));\n Object.assign(attributes, config.attributes);\n attributes[SENTRY_OP] = HTTP_SERVER;\n\n return startSpanManual({ name, attributes }, async span => {\n const { onSpanCreated, onSpanEnd } = options ?? {};\n if (onSpanCreated) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanCreated`:' : '',\n () => onSpanCreated(span, request),\n () => undefined,\n );\n }\n\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n span.end();\n captureError(e);\n finish(undefined);\n throw e;\n }\n\n if (response) {\n setHttpStatus(span, response.status);\n isolationScope.setContext('response', { status_code: response.status });\n span.setAttributes(\n httpHeadersToSpanAttributes(responseHeadersToDict(response.headers), dataCollection, 'response'),\n );\n }\n\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => {\n if (onSpanEnd && response) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanEnd`:' : '',\n () => onSpanEnd(span, request, response),\n () => undefined,\n );\n }\n span.end();\n finish(response);\n }),\n inRequestScope((error: unknown) => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureError(error);\n }),\n );\n });\n },\n );\n}\n\n/**\n * Returns a function that binds a callback to the request's isolation scope and the current scope.\n *\n * A streamed body finishes after the handler returns. Without `AsyncLocalStorage` (Cloudflare\n * Workers without `nodejs_compat`), its callbacks then run outside the request's scopes, where\n * `getClient()` finds no client: the segment span would be sent as a transaction, and a captured\n * error would not update the request session.\n */\nfunction bindToRequestScope(\n isolationScope: Scope,\n): <A extends unknown[]>(fn: (...args: A) => void) => (...args: A) => void {\n const scope = getCurrentScope();\n return fn =>\n (...args) =>\n withIsolationScope(isolationScope, () => withScope(scope, () => fn(...args)));\n}\n\nfunction shouldCreateSpan(\n client: Client,\n options: ServerRequestOptions<Request, Response> | undefined,\n request: Request,\n urlPath: string,\n): boolean {\n if (!(options?.spans ?? hasSpansEnabled(client.getOptions()))) {\n return false;\n }\n if (options?.ignoreStaticAssets && request.method.toUpperCase() === 'GET' && isStaticAssetRequest(urlPath)) {\n return false;\n }\n const ignoreIncomingRequests = options?.ignoreIncomingRequests;\n return !(\n ignoreIncomingRequests &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreIncomingRequests`, creating the span:' : '',\n () => ignoreIncomingRequests(urlPath, request),\n () => false,\n )\n );\n}\n\n/**\n * Calls `onDone` when the response is done: at once, or when a streamed body finishes.\n * Returns the response to send.\n */\nfunction onResponseDone<R extends Response | undefined>(\n response: R,\n isStreaming: boolean,\n onDone: () => void,\n onStreamError: (error: unknown) => void,\n): R {\n if (isStreaming && response?.body && !response.body.locked) {\n try {\n // Passing the original response as the init keeps its status, status text and headers, and\n // on Cloudflare also `encodeBody: 'manual'`, so workerd does not compress a compressed body again.\n return new Response(monitorStream(response.body, onDone, onStreamError), response) as R;\n } catch {\n // Workers with a compatibility date before 2022-11-30 and without the\n // `streams_enable_constructors` flag cannot construct a `ReadableStream`, so end at once.\n }\n }\n onDone();\n return response;\n}\n\n// `Headers.forEach` lists each `Set-Cookie` header on its own, so a plain dict keeps only the last one.\nfunction responseHeadersToDict(headers: Headers): Record<string, string | string[]> {\n const dict: Record<string, string | string[]> = winterCGHeadersToDict(headers);\n const setCookie = typeof headers.getSetCookie === 'function' ? headers.getSetCookie() : [];\n if (setCookie.length) {\n dict['set-cookie'] = setCookie;\n }\n return dict;\n}\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAgB,cACd,QACA,QACA,SAC4B;CAC5B,IAAI;CACJ,IAAI,WAAW;CACf,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DEBUG_BUILD","debug","captureException","winterCGRequestToRequestData","isServedTunnelRequest","startRequestSession","classifyResponseStreaming","safeCallback","DEBUG_BUILD","captureBodyFromWinterCGRequest","parseStringToURLObject","continueTrace","getHttpSpanDetailsFromUrlObject","SENTRY_SEGMENT_NAME_SOURCE","hasSpanStreamingEnabled","HTTP_SPAN_NAME_FALLBACK","HTTP_REQUEST_BODY_SIZE","USER_AGENT_ORIGINAL","winterCGHeadersToDict","getClientIPAddress","CLIENT_ADDRESS","CLIENT_PORT","NETWORK_PROTOCOL_NAME","httpHeadersToSpanAttributes","SENTRY_OP","HTTP_SERVER","SENTRY_KIND","startSpanManual","SPAN_STATUS_ERROR","setHttpStatus","getCurrentScope","withIsolationScope","withScope","hasSpansEnabled","isStaticAssetRequest"],"sources":["../../src/utils/monitorStream.ts","../../src/utils/wrapServerRequestHandler.ts"],"sourcesContent":["import { debug, isError } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\n/**\n * Monitor the source without reading ahead or treating cancellation as a source failure.\n *\n * `onDone` runs once, while the returned stream is still open: before it closes, before it errors,\n * or when the consumer cancels it. A runtime can end the request when the response body closes\n * (Cloudflare Workers then reject `waitUntil`), so work that `onDone` starts must begin first.\n */\nexport function monitorStream(\n stream: ReadableStream<Uint8Array>,\n onDone: () => void,\n onError: (error: unknown) => void,\n): ReadableStream<Uint8Array> {\n let reader: ReadableStreamDefaultReader<Uint8Array>;\n let finished = false;\n const finish = (error?: { error: unknown }): void => {\n if (finished) {\n return;\n }\n finished = true;\n // A callback that throws must not fail the response body.\n try {\n // A source that stops on `request.signal` errors with an `AbortError` when the client\n // disconnects, which is a cancellation too.\n if (error && !(isError(error.error) && error.error.name === 'AbortError')) {\n onError(error.error);\n }\n onDone();\n } catch (e) {\n DEBUG_BUILD && debug.error('Error when a monitored stream finished:', e);\n }\n };\n\n return new ReadableStream<Uint8Array>(\n {\n // Locks the source only once the stream exists, so a constructor that throws leaves it usable.\n start() {\n reader = stream.getReader();\n // A source can fail while no one reads from it. A cancelled reader closes normally; only a\n // source failure should be captured as an error.\n void reader.closed.then(\n () => finish(),\n error => finish({ error }),\n );\n },\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n finish();\n controller.close();\n reader.releaseLock();\n } else {\n controller.enqueue(value);\n }\n } catch (error) {\n finish({ error });\n controller.error(error);\n reader.releaseLock();\n }\n },\n async cancel(reason) {\n finish();\n try {\n await reader.cancel(reason);\n } finally {\n reader.releaseLock();\n }\n },\n },\n { highWaterMark: 0 },\n );\n}\n","import {\n CLIENT_ADDRESS,\n CLIENT_PORT,\n HTTP_REQUEST_BODY_SIZE,\n NETWORK_PROTOCOL_NAME,\n SENTRY_KIND,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n USER_AGENT_ORIGINAL,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport type { Client, Mechanism, Scope, SpanAttributes } from '@sentry/core';\nimport {\n captureBodyFromWinterCGRequest,\n captureException,\n continueTrace,\n getCurrentScope,\n getHttpSpanDetailsFromUrlObject,\n hasSpansEnabled,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n safeCallback,\n setHttpStatus,\n SPAN_STATUS_ERROR,\n startSpanManual,\n winterCGHeadersToDict,\n winterCGRequestToRequestData,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type { ServerRequestOptions } from '@sentry/core/server';\nimport {\n _INTERNAL_isServedTunnelRequest as isServedTunnelRequest,\n classifyResponseStreaming,\n getClientIPAddress,\n isStaticAssetRequest,\n startRequestSession,\n} from '@sentry/core/server';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { monitorStream } from './monitorStream';\n\nexport interface ServerRequestHandlerConfig {\n request: Request;\n client: Client;\n /** The isolation scope of this request. */\n isolationScope: Scope;\n /** The options of the runtime's integration for incoming requests. */\n options: ServerRequestOptions<Request, Response> | undefined;\n /** Origin of the span, e.g. `auto.http.deno`. */\n origin: string;\n /** Mechanism of errors that the handler or the response stream throws. Omit to not capture them. */\n mechanism?: Mechanism;\n /** The address and port of the socket, if the runtime knows them. */\n getSocketAddress?: () => { address: string; port?: number } | undefined;\n /** The matched route of the server framework, e.g. `/users/:id`. Sets `http.route` and the span name. */\n routeName?: string;\n /** Span attributes that only the runtime knows, e.g. the route parameters. */\n attributes?: SpanAttributes;\n /**\n * Called in the scope of the continued trace, before the span starts. Lets the runtime continue\n * its own trace, e.g. the trace that Cloudflare exports for the invocation.\n */\n onTraceContinued?: () => void;\n /** Whether the response streams. Return `undefined` to use the default classification. */\n isStreamingResponse?: (response: Response) => boolean | undefined;\n /**\n * Called once when the request is done: when the response is returned, when a streamed body\n * finishes, or when the handler throws (then without a response).\n */\n onDone?: (response: Response | undefined) => void;\n}\n\n/**\n * Wraps a handler of a web `Request`, as used by `Deno.serve`, `Bun.serve` and Cloudflare Workers.\n *\n * It records the request session, attaches the request data and body, continues the incoming\n * trace, creates the `http.server` span, and captures errors that the handler throws. The rules\n * follow core's `node:http` server code:\n *\n * - `OPTIONS` and `HEAD` requests get no span and no body capture.\n * - The static asset filter applies only to `GET`.\n * - The span and the session of a streamed response end when the stream finishes.\n *\n * The handler can return no response, as Bun's `fetch` does after a WebSocket upgrade.\n */\nexport async function wrapServerRequestHandler<R extends Response | undefined = Response>(\n config: ServerRequestHandlerConfig,\n handler: () => R | Promise<R>,\n): Promise<R> {\n const { request, client, isolationScope, options, mechanism } = config;\n\n const method = request.method.toUpperCase();\n const captureError = (error: unknown): void => {\n if (mechanism) {\n captureException(error, { mechanism });\n }\n };\n\n const socketAddress = config.getSocketAddress?.();\n // Without `AsyncLocalStorage`, all requests share one isolation scope, so clear what an earlier\n // request left on it: the merge keeps its body, and its response context would stay set.\n isolationScope.setSDKProcessingMetadata({\n normalizedRequest: { ...winterCGRequestToRequestData(request), data: undefined },\n ipAddress: socketAddress?.address,\n });\n isolationScope.setContext('response', null);\n\n // Tunnel requests get no session, body or span, whether the SDK or the app answers them. The app answers them with\n // `intercept: false`, from its own code, so its errors are still captured.\n if (isServedTunnelRequest(request, client)) {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n config.onDone?.(response);\n }\n }\n\n const endSession = options?.sessions\n ? startRequestSession(client, {\n requestIsolationScope: isolationScope,\n sessionFlushingDelayMS: options.sessionFlushingDelayMS,\n })\n : undefined;\n const finish = (response: Response | undefined): void => {\n endSession?.();\n config.onDone?.(response);\n };\n const isStreamingResponse = (response: Response): boolean => {\n const classification = config.isStreamingResponse?.(response);\n return typeof classification === 'boolean' ? classification : classifyResponseStreaming(response).isStreaming;\n };\n\n if (method === 'OPTIONS' || method === 'HEAD') {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n finish(response);\n }\n }\n\n const dataCollection = client.getDataCollectionOptions();\n const effectiveBodySize =\n options?.maxRequestBodySize ?? (dataCollection.httpBodies.includes('incomingRequest') ? 'medium' : 'none');\n const ignoreRequestBody = options?.ignoreRequestBody;\n if (\n method !== 'GET' &&\n effectiveBodySize !== 'none' &&\n // If the filter throws, skip the body so it cannot leak data the filter was meant to hide.\n !(\n ignoreRequestBody &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreRequestBody`, skipping the body:' : '',\n () => ignoreRequestBody(request.url, request),\n () => true,\n )\n )\n ) {\n await captureBodyFromWinterCGRequest(request, isolationScope, effectiveBodySize);\n }\n\n const urlObject = parseStringToURLObject(request.url);\n const urlPath = urlObject ? `${urlObject.pathname}${urlObject.search}` : '/';\n const createSpan = shouldCreateSpan(client, options, request, urlPath);\n\n return continueTrace(\n {\n sentryTrace: request.headers.get('sentry-trace') || '',\n baggage: request.headers.get('baggage'),\n },\n async () => {\n config.onTraceContinued?.();\n\n if (!createSpan) {\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n captureError(e);\n finish(undefined);\n throw e;\n }\n if (response) {\n isolationScope.setContext('response', { status_code: response.status });\n }\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => finish(response)),\n inRequestScope(captureError),\n );\n }\n\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n config.origin,\n request,\n config.routeName,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !hasSpanStreamingEnabled(client)\n ? rawName\n : method || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes[HTTP_REQUEST_BODY_SIZE] = parseInt(contentLength, 10);\n }\n const userAgent = request.headers.get('user-agent');\n if (userAgent) {\n attributes[USER_AGENT_ORIGINAL] = userAgent;\n }\n\n const headers = winterCGHeadersToDict(request.headers);\n if (dataCollection.userInfo) {\n // `client.address` is the originating client, so a forwarding header wins over the socket, which\n // behind a proxy holds the proxy's address. The socket port is the proxy's too, so `client.port`\n // stays unset then.\n const forwardedAddress = getClientIPAddress(headers);\n if (forwardedAddress) {\n attributes[CLIENT_ADDRESS] = forwardedAddress;\n } else if (socketAddress) {\n attributes[CLIENT_ADDRESS] = socketAddress.address;\n if (socketAddress.port !== undefined) {\n attributes[CLIENT_PORT] = socketAddress.port;\n }\n }\n }\n\n // describes the OSI application-layer protocol (http), not the scheme (might be https)\n attributes[NETWORK_PROTOCOL_NAME] = 'http';\n Object.assign(attributes, httpHeadersToSpanAttributes(headers, dataCollection));\n Object.assign(attributes, config.attributes);\n attributes[SENTRY_OP] = HTTP_SERVER;\n attributes[SENTRY_KIND] = 'server';\n\n return startSpanManual({ name, attributes }, async span => {\n const { onSpanCreated, onSpanEnd } = options ?? {};\n if (onSpanCreated) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanCreated`:' : '',\n () => onSpanCreated(span, request),\n () => undefined,\n );\n }\n\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n span.end();\n captureError(e);\n finish(undefined);\n throw e;\n }\n\n if (response) {\n setHttpStatus(span, response.status);\n isolationScope.setContext('response', { status_code: response.status });\n span.setAttributes(\n httpHeadersToSpanAttributes(responseHeadersToDict(response.headers), dataCollection, 'response'),\n );\n }\n\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => {\n if (onSpanEnd && response) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanEnd`:' : '',\n () => onSpanEnd(span, request, response),\n () => undefined,\n );\n }\n span.end();\n finish(response);\n }),\n inRequestScope((error: unknown) => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureError(error);\n }),\n );\n });\n },\n );\n}\n\n/**\n * Returns a function that binds a callback to the request's isolation scope and the current scope.\n *\n * A streamed body finishes after the handler returns. Without `AsyncLocalStorage` (Cloudflare\n * Workers without `nodejs_compat`), its callbacks then run outside the request's scopes, where\n * `getClient()` finds no client: the segment span would be sent as a transaction, and a captured\n * error would not update the request session.\n */\nfunction bindToRequestScope(\n isolationScope: Scope,\n): <A extends unknown[]>(fn: (...args: A) => void) => (...args: A) => void {\n const scope = getCurrentScope();\n return fn =>\n (...args) =>\n withIsolationScope(isolationScope, () => withScope(scope, () => fn(...args)));\n}\n\nfunction shouldCreateSpan(\n client: Client,\n options: ServerRequestOptions<Request, Response> | undefined,\n request: Request,\n urlPath: string,\n): boolean {\n if (!(options?.spans ?? hasSpansEnabled(client.getOptions()))) {\n return false;\n }\n if (options?.ignoreStaticAssets && request.method.toUpperCase() === 'GET' && isStaticAssetRequest(urlPath)) {\n return false;\n }\n const ignoreIncomingRequests = options?.ignoreIncomingRequests;\n return !(\n ignoreIncomingRequests &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreIncomingRequests`, creating the span:' : '',\n () => ignoreIncomingRequests(urlPath, request),\n () => false,\n )\n );\n}\n\n/**\n * Calls `onDone` when the response is done: at once, or when a streamed body finishes.\n * Returns the response to send.\n */\nfunction onResponseDone<R extends Response | undefined>(\n response: R,\n isStreaming: boolean,\n onDone: () => void,\n onStreamError: (error: unknown) => void,\n): R {\n if (isStreaming && response?.body && !response.body.locked) {\n try {\n // Passing the original response as the init keeps its status, status text and headers, and\n // on Cloudflare also `encodeBody: 'manual'`, so workerd does not compress a compressed body again.\n return new Response(monitorStream(response.body, onDone, onStreamError), response) as R;\n } catch {\n // Workers with a compatibility date before 2022-11-30 and without the\n // `streams_enable_constructors` flag cannot construct a `ReadableStream`, so end at once.\n }\n }\n onDone();\n return response;\n}\n\n// `Headers.forEach` lists each `Set-Cookie` header on its own, so a plain dict keeps only the last one.\nfunction responseHeadersToDict(headers: Headers): Record<string, string | string[]> {\n const dict: Record<string, string | string[]> = winterCGHeadersToDict(headers);\n const setCookie = typeof headers.getSetCookie === 'function' ? headers.getSetCookie() : [];\n if (setCookie.length) {\n dict['set-cookie'] = setCookie;\n }\n return dict;\n}\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAgB,cACd,QACA,QACA,SAC4B;CAC5B,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,UAAU,UAAqC;EACnD,IAAI,UACF;EAEF,WAAW;EAEX,IAAI;GAGF,IAAI,SAAS,GAAA,GAAEA,aAAAA,QAAAA,CAAQ,MAAM,KAAK,KAAK,MAAM,MAAM,SAAS,eAC1D,QAAQ,MAAM,KAAK;GAErB,OAAO;EACT,SAAS,GAAG;GACVC,oBAAAA,eAAeC,aAAAA,MAAM,MAAM,2CAA2C,CAAC;EACzE;CACF;CAEA,OAAO,IAAI,eACT;EAEE,QAAQ;GACN,SAAS,OAAO,UAAU;GAGrB,OAAO,OAAO,WACX,OAAO,IACb,UAAS,OAAO,EAAE,MAAM,CAAC,CAC3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AI,CAAC,CAAC;AAClF;AAEA,SAAS,iBACP,QACA,SACA,SACA,SACS;CACT,IAAI,EAAE,SAAS,UAAA,GAASC,aAAAA,gBAAAA,CAAgB,OAAO,WAAW,CAAC,IACzD,OAAO;CAET,IAAI,SAAS,sBAAsB,QAAQ,OAAO,YAAY,MAAM,UAAA,GAASC,oBAAAA,qBAAAA,CAAqB,OAAO,GACvG,OAAO;CAET,MAAM,yBAAyB,SAAS;CACxC,OAAO,EACL,2BAAA,GACA3B,aAAAA,aAAAA,CACEC,oBAAAA,cAAc,0DAA0D,UAClE,uBAAuB,SAAS,OAAO,SACvC,KACR;AAEJ;;;;;AAMA,SAAS,eACP,UACA,aACA,QACA,eACG;CACH,IAAI,eAAe,UAAU,QAAQ,CAAC,SAAS,KAAK,QAClD,IAAI;EAGF,OAAO,IAAI,SAAS,cAAc,SAAS,MAAM,QAAQ,aAAa,GAAG,QAAQ;CACnF,QAAQ,CAGR;CAEF,OAAO;CACP,OAAO;AACT;AAGA,SAAS,sBAAsB,SAAqD;CAClF,MAAM,QAAA,GAA0CU,aAAAA,sBAAAA,CAAsB,OAAO;CAC7E,MAAM,YAAY,OAAO,QAAQ,iBAAiB,aAAa,QAAQ,aAAa,IAAI,CAAC;CACzF,IAAI,UAAU,QACZ,KAAK,gBAAgB;CAEvB,OAAO;AACT"}
@@ -67,6 +67,7 @@ function startToolSpan(observation, context, toolSpans, options) {
67
67
  ...recordInputs && observation.args !== void 0 ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(observation.args) } : {}
68
68
  }
69
69
  });
70
+ if (observation.conversationId) span.setAttribute(GEN_AI_CONVERSATION_ID, observation.conversationId);
70
71
  if (recordOutputs) TOOL_SPANS_RECORDING_OUTPUTS.add(span);
71
72
  runGenAiSpanStart(options, span, call);
72
73
  TOOL_SPAN_END_HOOKS.set(span, (end) => runGenAiSpanEnd(options, span, call, end.isError ? {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/ai/flue/utils.ts"],"sourcesContent":["import type { LRUMap, Span } from '@sentry/core';\nimport {\n captureException,\n isObjectLike,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n stringify,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n GEN_AI_CONVERSATION_ID,\n GEN_AI_OPERATION_NAME,\n GEN_AI_TOOL_CALL_ARGUMENTS,\n GEN_AI_TOOL_CALL_RESULT,\n GEN_AI_TOOL_NAME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport type { GenAiSpanHooks } from '../core/span-hooks';\nimport { runGenAiSpanEnd, runGenAiSpanStart } from '../core/span-hooks';\nimport type { GenAiCallOptions } from '../core/utils';\nimport { getGenAiSpanOp, resolveGenAiCallRecording } from '../core/utils';\nimport { piAiContentToString } from '../pi-ai/messages';\nimport { FLUE_ORIGIN, MAX_TRACKED_FLUE_SPANS } from './constants';\nimport type { FlueCallInfo, FlueErrorInfo, FlueEventContext, FlueObservation } from './types';\n\n/**\n * Turn and tool spans, keyed by the id of the work they cover. Bounded, because the key is only\n * removed when the matching end observation arrives and an abandoned stream never emits one.\n */\nexport type SpanTracker = LRUMap<string, Span>;\n\nconst TOOL_SPANS_RECORDING_OUTPUTS = new WeakSet<Span>();\nconst TOOL_SPAN_END_HOOKS = new WeakMap<Span, (observation: FlueObservation) => void>();\n\n/**\n * Store a span under `key`. Callers only reach this with a key the tracker does not hold, so the\n * one span at risk of being dropped without `end()` is the oldest entry, which `LRUMap.set` silently\n * evicts once the tracker is full.\n */\nfunction trackSpan(tracker: SpanTracker, key: string, span: Span): void {\n if (tracker.size >= MAX_TRACKED_FLUE_SPANS) {\n const oldestKey = tracker.keys()[0];\n if (oldestKey !== undefined) {\n tracker.remove(oldestKey)?.end();\n }\n }\n\n tracker.set(key, span);\n}\n\n/**\n * Report a failed tool as an error event.\n *\n * Flue catches whatever the tool threw and hands it back to the model as a tool result, so nothing\n * propagates for the SDK's global handlers to see: without this a throwing tool produces an errored\n * span and no issue at all. `errorInfo` carries the original name, message and stack, so rebuild an\n * `Error` from it rather than capturing the serialized shape.\n *\n * Tools only. A failed turn carries no `errorInfo` — a provider auth failure produces an errored\n * `chat` span and nothing to rebuild from — so there is no turn equivalent to capture.\n */\nfunction captureToolError(span: Span, errorInfo: FlueErrorInfo | undefined): void {\n if (!errorInfo) {\n return;\n }\n\n const error = new Error(errorInfo.message ?? 'Flue tool failed');\n error.name = errorInfo.name ?? errorInfo.type ?? 'Error';\n if (errorInfo.stack) {\n error.stack = errorInfo.stack;\n }\n\n // Captured under the operation's own span so the issue lands on the right trace, matching how the\n // Mastra integration attaches its captures.\n withActiveSpan(span, () => {\n // Handled: this is not a rejection observed on a tracing channel, where the handled state is\n // unknowable. Flue caught the throw and returned it to the model as a tool result, so it is\n // definitively handled and no global hook will ever see it.\n captureException(error, { mechanism: { handled: true, type: FLUE_ORIGIN } });\n });\n}\n\n/**\n * Tool spans hang off the agent invocation rather than the turn, matching how Flue's own\n * OpenTelemetry adapter projects them: siblings of `chat`, correlated to model output by tool call\n * id. Keyed by `toolCallId` so concurrent tool calls in one turn cannot cross-attribute.\n */\nexport function startToolSpan(\n observation: FlueObservation,\n context: FlueEventContext,\n toolSpans: SpanTracker,\n options: GenAiCallOptions<FlueCallInfo> & GenAiSpanHooks<FlueCallInfo, FlueObservation>,\n): void {\n const { toolCallId, toolName } = observation;\n if (!toolCallId || toolSpans.get(toolCallId)) {\n return;\n }\n\n const call: FlueCallInfo = { operation: 'execute_tool', observation, context };\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n const span = startInactiveSpan({\n name: `execute_tool ${toolName ?? 'unknown'}`,\n op: getGenAiSpanOp('execute_tool'),\n attributes: {\n [SENTRY_ORIGIN]: FLUE_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'execute_tool',\n [GEN_AI_TOOL_NAME]: toolName,\n [GEN_AI_CONVERSATION_ID]: observation.conversationId,\n ...(recordInputs && observation.args !== undefined\n ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(observation.args) }\n : {}),\n },\n });\n if (recordOutputs) {\n TOOL_SPANS_RECORDING_OUTPUTS.add(span);\n }\n runGenAiSpanStart(options, span, call);\n TOOL_SPAN_END_HOOKS.set(span, end =>\n runGenAiSpanEnd(options, span, call, end.isError ? { response: end, error: end.errorInfo } : { response: end }),\n );\n trackSpan(toolSpans, toolCallId, span);\n}\n\nexport function endToolSpan(observation: FlueObservation, toolSpans: SpanTracker): void {\n const { toolCallId } = observation;\n const span = toolCallId ? toolSpans.get(toolCallId) : undefined;\n if (!span || !toolCallId) {\n return;\n }\n toolSpans.remove(toolCallId);\n\n if (TOOL_SPANS_RECORDING_OUTPUTS.has(span)) {\n const result = toolResultForModel(observation);\n if (result !== undefined) {\n span.setAttribute(GEN_AI_TOOL_CALL_RESULT, result);\n }\n }\n\n if (observation.isError) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureToolError(span, observation.errorInfo);\n }\n TOOL_SPAN_END_HOOKS.get(span)?.(observation);\n span.end();\n}\n\n/**\n * The result the model receives: Flue's `effectiveResult` when it has one, else the content blocks\n * of its harness-level `result` (`{ content, details }`, whose `details` payload is tool-specific).\n */\nfunction toolResultForModel(observation: FlueObservation): string | undefined {\n const { effectiveResult } = observation;\n if (effectiveResult !== undefined) {\n if (typeof effectiveResult === 'string') {\n return effectiveResult;\n }\n return Array.isArray(effectiveResult) ? piAiContentToString(effectiveResult) : stringify(effectiveResult);\n }\n const { result } = observation;\n if (isObjectLike(result) && Array.isArray(result.content)) {\n return piAiContentToString(result.content);\n }\n return result === undefined ? undefined : stringify(result);\n}\n"],"mappings":";;;;;;;AA+BA,MAAM,+CAA+B,IAAI,QAAc;AACvD,MAAM,sCAAsB,IAAI,QAAsD;;;;;;AAOtF,SAAS,UAAU,SAAsB,KAAa,MAAkB;CACtE,IAAI,QAAQ,QAAA,KAAgC;EAC1C,MAAM,YAAY,QAAQ,KAAK,CAAC,CAAC;EACjC,IAAI,cAA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AAO,aAAa,UAAU,IAAI,UAAU,IAAI,KAAA;CACtD,IAAI,CAAC,QAAQ,CAAC,YACZ;CAEF,UAAU,OAAO,UAAU;CAE3B,IAAI,6BAA6B,IAAI,IAAI,GAAG;EAC1C,MAAM,SAAS,mBAAmB,WAAW;EAC7C,IAAI,WAAW,KAAA,GACb,KAAK,aAAa,yBAAyB,MAAM;CAErD;CAEA,IAAI,YAAY,SAAS;EACvB,KAAK,UAAU;GAAE,MAAM;GAAmB,SAAS;EAAiB,CAAC;EACrE,iBAAiB,MAAM,YAAY,SAAS;CAC9C;CACA,oBAAoB,IAAI,IAAI,CAAC,GAAG,WAAW;CAC3C,KAAK,IAAI;AACX;;;;;AAMA,SAAS,mBAAmB,aAAkD;CAC5E,MAAM,EAAE,oBAAoB;CAC5B,IAAI,oBAAoB,KAAA,GAAW;EACjC,IAAI,OAAO,oBAAoB,UAC7B,OAAO;EAET,OAAO,MAAM,QAAQ,eAAe,IAAI,oBAAoB,eAAe,IAAI,UAAU,eAAe;CAC1G;CACA,MAAM,EAAE,WAAW;CACnB,IAAI,aAAa,MAAM,KAAK,MAAM,QAAQ,OAAO,OAAO,GACtD,OAAO,oBAAoB,OAAO,OAAO;CAE3C,OAAO,WAAW,KAAA,IAAY,KAAA,IAAY,UAAU,MAAM;AAC5D"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/ai/flue/utils.ts"],"sourcesContent":["import type { LRUMap, Span } from '@sentry/core';\nimport {\n captureException,\n isObjectLike,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n stringify,\n withActiveSpan,\n} from '@sentry/core';\nimport {\n GEN_AI_CONVERSATION_ID,\n GEN_AI_OPERATION_NAME,\n GEN_AI_TOOL_CALL_ARGUMENTS,\n GEN_AI_TOOL_CALL_RESULT,\n GEN_AI_TOOL_NAME,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport type { GenAiSpanHooks } from '../core/span-hooks';\nimport { runGenAiSpanEnd, runGenAiSpanStart } from '../core/span-hooks';\nimport type { GenAiCallOptions } from '../core/utils';\nimport { getGenAiSpanOp, resolveGenAiCallRecording } from '../core/utils';\nimport { piAiContentToString } from '../pi-ai/messages';\nimport { FLUE_ORIGIN, MAX_TRACKED_FLUE_SPANS } from './constants';\nimport type { FlueCallInfo, FlueErrorInfo, FlueEventContext, FlueObservation } from './types';\n\n/**\n * Turn and tool spans, keyed by the id of the work they cover. Bounded, because the key is only\n * removed when the matching end observation arrives and an abandoned stream never emits one.\n */\nexport type SpanTracker = LRUMap<string, Span>;\n\nconst TOOL_SPANS_RECORDING_OUTPUTS = new WeakSet<Span>();\nconst TOOL_SPAN_END_HOOKS = new WeakMap<Span, (observation: FlueObservation) => void>();\n\n/**\n * Store a span under `key`. Callers only reach this with a key the tracker does not hold, so the\n * one span at risk of being dropped without `end()` is the oldest entry, which `LRUMap.set` silently\n * evicts once the tracker is full.\n */\nfunction trackSpan(tracker: SpanTracker, key: string, span: Span): void {\n if (tracker.size >= MAX_TRACKED_FLUE_SPANS) {\n const oldestKey = tracker.keys()[0];\n if (oldestKey !== undefined) {\n tracker.remove(oldestKey)?.end();\n }\n }\n\n tracker.set(key, span);\n}\n\n/**\n * Report a failed tool as an error event.\n *\n * Flue catches whatever the tool threw and hands it back to the model as a tool result, so nothing\n * propagates for the SDK's global handlers to see: without this a throwing tool produces an errored\n * span and no issue at all. `errorInfo` carries the original name, message and stack, so rebuild an\n * `Error` from it rather than capturing the serialized shape.\n *\n * Tools only. A failed turn carries no `errorInfo` — a provider auth failure produces an errored\n * `chat` span and nothing to rebuild from — so there is no turn equivalent to capture.\n */\nfunction captureToolError(span: Span, errorInfo: FlueErrorInfo | undefined): void {\n if (!errorInfo) {\n return;\n }\n\n const error = new Error(errorInfo.message ?? 'Flue tool failed');\n error.name = errorInfo.name ?? errorInfo.type ?? 'Error';\n if (errorInfo.stack) {\n error.stack = errorInfo.stack;\n }\n\n // Captured under the operation's own span so the issue lands on the right trace, matching how the\n // Mastra integration attaches its captures.\n withActiveSpan(span, () => {\n // Handled: this is not a rejection observed on a tracing channel, where the handled state is\n // unknowable. Flue caught the throw and returned it to the model as a tool result, so it is\n // definitively handled and no global hook will ever see it.\n captureException(error, { mechanism: { handled: true, type: FLUE_ORIGIN } });\n });\n}\n\n/**\n * Tool spans hang off the agent invocation rather than the turn, matching how Flue's own\n * OpenTelemetry adapter projects them: siblings of `chat`, correlated to model output by tool call\n * id. Keyed by `toolCallId` so concurrent tool calls in one turn cannot cross-attribute.\n */\nexport function startToolSpan(\n observation: FlueObservation,\n context: FlueEventContext,\n toolSpans: SpanTracker,\n options: GenAiCallOptions<FlueCallInfo> & GenAiSpanHooks<FlueCallInfo, FlueObservation>,\n): void {\n const { toolCallId, toolName } = observation;\n if (!toolCallId || toolSpans.get(toolCallId)) {\n return;\n }\n\n const call: FlueCallInfo = { operation: 'execute_tool', observation, context };\n const { recordInputs, recordOutputs } = resolveGenAiCallRecording(options, call);\n const span = startInactiveSpan({\n name: `execute_tool ${toolName ?? 'unknown'}`,\n op: getGenAiSpanOp('execute_tool'),\n attributes: {\n [SENTRY_ORIGIN]: FLUE_ORIGIN,\n [GEN_AI_OPERATION_NAME]: 'execute_tool',\n [GEN_AI_TOOL_NAME]: toolName,\n [GEN_AI_CONVERSATION_ID]: observation.conversationId,\n ...(recordInputs && observation.args !== undefined\n ? { [GEN_AI_TOOL_CALL_ARGUMENTS]: stringify(observation.args) }\n : {}),\n },\n });\n // Again after start, so the Flue id wins over one from `Sentry.setConversationId()`, as on the agent and chat spans.\n if (observation.conversationId) {\n span.setAttribute(GEN_AI_CONVERSATION_ID, observation.conversationId);\n }\n if (recordOutputs) {\n TOOL_SPANS_RECORDING_OUTPUTS.add(span);\n }\n runGenAiSpanStart(options, span, call);\n TOOL_SPAN_END_HOOKS.set(span, end =>\n runGenAiSpanEnd(options, span, call, end.isError ? { response: end, error: end.errorInfo } : { response: end }),\n );\n trackSpan(toolSpans, toolCallId, span);\n}\n\nexport function endToolSpan(observation: FlueObservation, toolSpans: SpanTracker): void {\n const { toolCallId } = observation;\n const span = toolCallId ? toolSpans.get(toolCallId) : undefined;\n if (!span || !toolCallId) {\n return;\n }\n toolSpans.remove(toolCallId);\n\n if (TOOL_SPANS_RECORDING_OUTPUTS.has(span)) {\n const result = toolResultForModel(observation);\n if (result !== undefined) {\n span.setAttribute(GEN_AI_TOOL_CALL_RESULT, result);\n }\n }\n\n if (observation.isError) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureToolError(span, observation.errorInfo);\n }\n TOOL_SPAN_END_HOOKS.get(span)?.(observation);\n span.end();\n}\n\n/**\n * The result the model receives: Flue's `effectiveResult` when it has one, else the content blocks\n * of its harness-level `result` (`{ content, details }`, whose `details` payload is tool-specific).\n */\nfunction toolResultForModel(observation: FlueObservation): string | undefined {\n const { effectiveResult } = observation;\n if (effectiveResult !== undefined) {\n if (typeof effectiveResult === 'string') {\n return effectiveResult;\n }\n return Array.isArray(effectiveResult) ? piAiContentToString(effectiveResult) : stringify(effectiveResult);\n }\n const { result } = observation;\n if (isObjectLike(result) && Array.isArray(result.content)) {\n return piAiContentToString(result.content);\n }\n return result === undefined ? undefined : stringify(result);\n}\n"],"mappings":";;;;;;;AA+BA,MAAM,+CAA+B,IAAI,QAAc;AACvD,MAAM,sCAAsB,IAAI,QAAsD;;;;;;AAOtF,SAAS,UAAU,SAAsB,KAAa,MAAkB;CACtE,IAAI,QAAQ,QAAA,KAAgC;EAC1C,MAAM,YAAY,QAAQ,KAAK,CAAC,CAAC;EACjC,IAAI,cAAc,KAAA,GAChB,QAAQ,OAAO,SAAS,CAAC,EAAE,IAAI;CAEnC;CAEA,QAAQ,IAAI,KAAK,IAAI;AACvB;;;;;;;;;;;;AAaA,SAAS,iBAAiB,MAAY,WAA4C;CAChF,IAAI,CAAC,WACH;CAGF,MAAM,QAAQ,IAAI,MAAM,UAAU,WAAW,kBAAkB;CAC/D,MAAM,OAAO,UAAU,QAAQ,UAAU,QAAQ;C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AAK,aAAa,yBAAyB,MAAM;CAErD;CAEA,IAAI,YAAY,SAAS;EACvB,KAAK,UAAU;GAAE,MAAM;GAAmB,SAAS;EAAiB,CAAC;EACrE,iBAAiB,MAAM,YAAY,SAAS;CAC9C;CACA,oBAAoB,IAAI,IAAI,CAAC,GAAG,WAAW;CAC3C,KAAK,IAAI;AACX;;;;;AAMA,SAAS,mBAAmB,aAAkD;CAC5E,MAAM,EAAE,oBAAoB;CAC5B,IAAI,oBAAoB,KAAA,GAAW;EACjC,IAAI,OAAO,oBAAoB,UAC7B,OAAO;EAET,OAAO,MAAM,QAAQ,eAAe,IAAI,oBAAoB,eAAe,IAAI,UAAU,eAAe;CAC1G;CACA,MAAM,EAAE,WAAW;CACnB,IAAI,aAAa,MAAM,KAAK,MAAM,QAAQ,OAAO,OAAO,GACtD,OAAO,oBAAoB,OAAO,OAAO;CAE3C,OAAO,WAAW,KAAA,IAAY,KAAA,IAAY,UAAU,MAAM;AAC5D"}
@@ -8,10 +8,38 @@ import { isObjectLike } from "@sentry/core";
8
8
  */
9
9
  function getDecisionInputMessages(params) {
10
10
  return getEvaluationInputMessages({
11
- state: params.input,
11
+ state: toStateMessages(params.input),
12
12
  questions: params.questions
13
13
  });
14
14
  }
15
+ /**
16
+ * Multimodal evidence is one part or a list of parts, recorded as one user message so it renders like OpenAI's.
17
+ * Inline media is reported by modality and media type only: its `data` is base64, which the conventions require
18
+ * to be dropped.
19
+ */
20
+ function toStateMessages(input) {
21
+ if (typeof input === "string") return input;
22
+ return [{
23
+ role: "user",
24
+ parts: (Array.isArray(input) ? input : [input]).filter(isObjectLike).map((part) => {
25
+ if (part.type === "text") return {
26
+ type: "text",
27
+ content: part.text
28
+ };
29
+ if (typeof part.uri === "string") return {
30
+ type: "uri",
31
+ modality: part.type,
32
+ mime_type: part.mime_type,
33
+ uri: part.uri
34
+ };
35
+ return {
36
+ type: "blob",
37
+ modality: part.type,
38
+ mime_type: part.mime_type
39
+ };
40
+ })
41
+ }];
42
+ }
15
43
  function addDecisionResponseAttributes(span, response, recordOutputs) {
16
44
  if (!isObjectLike(response)) return;
17
45
  if (isObjectLike(response.usage)) {
@@ -1 +1 @@
1
- {"version":3,"file":"decisions.js","names":[],"sources":["../../../../src/ai/google-genai/decisions.ts"],"sourcesContent":["// Google's questions and answers already use Jev's layout, so only the evaluated input is renamed.\nimport { GEN_AI_OUTPUT_MESSAGES } from '@sentry/conventions/attributes';\nimport type { Span } from '@sentry/core';\nimport { isObjectLike } from '@sentry/core';\nimport { getEvaluationInputMessages, getEvaluationOutputMessages, getTokenUsageAttributes } from '../core/utils';\n\n/**\n * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`\n * so both render the same.\n */\nexport function getDecisionInputMessages(params: Record<string, unknown>): string | undefined {\n return getEvaluationInputMessages({ state: params.input, questions: params.questions });\n}\n\nexport function addDecisionResponseAttributes(span: Span, response: unknown, recordOutputs: boolean): void {\n if (!isObjectLike(response)) {\n return;\n }\n\n if (isObjectLike(response.usage)) {\n const usage = response.usage as Record<string, number | undefined>;\n span.setAttributes(\n getTokenUsageAttributes(\n usage.total_input_tokens,\n usage.total_output_tokens,\n undefined,\n usage.total_cached_tokens,\n usage.total_tokens,\n ),\n );\n }\n\n if (recordOutputs && response.answers !== undefined) {\n span.setAttribute(GEN_AI_OUTPUT_MESSAGES, getEvaluationOutputMessages(response.answers));\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,yBAAyB,QAAqD;CAC5F,OAAO,2BAA2B;EAAE,OAAO,OAAO;EAAO,WAAW,OAAO;CAAU,CAAC;AACxF;AAEA,SAAgB,8BAA8B,MAAY,UAAmB,eAA8B;CACzG,IAAI,CAAC,aAAa,QAAQ,GACxB;CAGF,IAAI,aAAa,SAAS,KAAK,GAAG;EAChC,MAAM,QAAQ,SAAS;EACvB,KAAK,cACH,wBACE,MAAM,oBACN,MAAM,qBACN,KAAA,GACA,MAAM,qBACN,MAAM,YACR,CACF;CACF;CAEA,IAAI,iBAAiB,SAAS,YAAY,KAAA,GACxC,KAAK,aAAa,wBAAwB,4BAA4B,SAAS,OAAO,CAAC;AAE3F"}
1
+ {"version":3,"file":"decisions.js","names":[],"sources":["../../../../src/ai/google-genai/decisions.ts"],"sourcesContent":["// Google's questions and answers already use Jev's layout, so only the evaluated input is mapped.\nimport { GEN_AI_OUTPUT_MESSAGES } from '@sentry/conventions/attributes';\nimport type { Span } from '@sentry/core';\nimport { isObjectLike } from '@sentry/core';\nimport { getEvaluationInputMessages, getEvaluationOutputMessages, getTokenUsageAttributes } from '../core/utils';\nimport type { GenAiMessage, GenAiMessagePart } from '../types';\n\n/**\n * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`\n * so both render the same.\n */\nexport function getDecisionInputMessages(params: Record<string, unknown>): string | undefined {\n return getEvaluationInputMessages({ state: toStateMessages(params.input), questions: params.questions });\n}\n\n/**\n * Multimodal evidence is one part or a list of parts, recorded as one user message so it renders like OpenAI's.\n * Inline media is reported by modality and media type only: its `data` is base64, which the conventions require\n * to be dropped.\n */\nfunction toStateMessages(input: unknown): unknown {\n if (typeof input === 'string') {\n return input;\n }\n\n const parts = (Array.isArray(input) ? input : [input]).filter(isObjectLike).map((part): GenAiMessagePart => {\n if (part.type === 'text') {\n return { type: 'text', content: part.text };\n }\n if (typeof part.uri === 'string') {\n return { type: 'uri', modality: part.type, mime_type: part.mime_type, uri: part.uri };\n }\n return { type: 'blob', modality: part.type, mime_type: part.mime_type };\n });\n return [{ role: 'user', parts } satisfies GenAiMessage];\n}\n\nexport function addDecisionResponseAttributes(span: Span, response: unknown, recordOutputs: boolean): void {\n if (!isObjectLike(response)) {\n return;\n }\n\n if (isObjectLike(response.usage)) {\n const usage = response.usage as Record<string, number | undefined>;\n span.setAttributes(\n getTokenUsageAttributes(\n usage.total_input_tokens,\n usage.total_output_tokens,\n undefined,\n usage.total_cached_tokens,\n usage.total_tokens,\n ),\n );\n }\n\n if (recordOutputs && response.answers !== undefined) {\n span.setAttribute(GEN_AI_OUTPUT_MESSAGES, getEvaluationOutputMessages(response.answers));\n }\n}\n"],"mappings":";;;;;;;;AAWA,SAAgB,yBAAyB,QAAqD;CAC5F,OAAO,2BAA2B;EAAE,OAAO,gBAAgB,OAAO,KAAK;EAAG,WAAW,OAAO;CAAU,CAAC;AACzG;;;;;;AAOA,SAAS,gBAAgB,OAAyB;CAChD,IAAI,OAAO,UAAU,UACnB,OAAO;CAYT,OAAO,CAAC;EAAE,MAAM;EAAQ,QATT,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAA,CAAG,OAAO,YAAY,CAAC,CAAC,KAAK,SAA2B;GAC1G,IAAI,KAAK,SAAS,QAChB,OAAO;IAAE,MAAM;IAAQ,SAAS,KAAK;GAAK;GAE5C,IAAI,OAAO,KAAK,QAAQ,UACtB,OAAO;IAAE,MAAM;IAAO,UAAU,KAAK;IAAM,WAAW,KAAK;IAAW,KAAK,KAAK;GAAI;GAEtF,OAAO;IAAE,MAAM;IAAQ,UAAU,KAAK;IAAM,WAAW,KAAK;GAAU;EACxE,CAC4B;CAAE,CAAwB;AACxD;AAEA,SAAgB,8BAA8B,MAAY,UAAmB,eAA8B;CACzG,IAAI,CAAC,aAAa,QAAQ,GACxB;CAGF,IAAI,aAAa,SAAS,KAAK,GAAG;EAChC,MAAM,QAAQ,SAAS;EACvB,KAAK,cACH,wBACE,MAAM,oBACN,MAAM,qBACN,KAAA,GACA,MAAM,qBACN,MAAM,YACR,CACF;CACF;CAEA,IAAI,iBAAiB,SAAS,YAAY,KAAA,GACxC,KAAK,aAAa,wBAAwB,4BAA4B,SAAS,OAAO,CAAC;AAE3F"}
@@ -12,10 +12,57 @@ import { isObjectLike } from "@sentry/core";
12
12
  function getDecisionInputMessages(params) {
13
13
  const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;
14
14
  return getEvaluationInputMessages({
15
- state: params.input,
15
+ state: toStateMessages(params.input),
16
16
  questions: keyByName(questions)
17
17
  });
18
18
  }
19
+ /**
20
+ * Lay out evidence messages as gen_ai messages, so they render like Google's. Other input items (tool calls and
21
+ * their outputs) keep their layout, with output parts mapped like message parts.
22
+ */
23
+ function toStateMessages(input) {
24
+ if (!Array.isArray(input)) return input;
25
+ return input.map((item) => {
26
+ if (!isObjectLike(item)) return item;
27
+ if (typeof item.role === "string") return {
28
+ role: item.role === "developer" ? "system" : item.role,
29
+ parts: Array.isArray(item.content) ? item.content.filter(isObjectLike).map(toMessagePart) : [{
30
+ type: "text",
31
+ content: item.content
32
+ }]
33
+ };
34
+ return Array.isArray(item.output) ? {
35
+ ...item,
36
+ output: item.output.filter(isObjectLike).map(toMessagePart)
37
+ } : item;
38
+ });
39
+ }
40
+ /**
41
+ * An image in a data URL is reported by its media type only: the URL holds base64, which the conventions require to be
42
+ * dropped.
43
+ */
44
+ function toMessagePart(part) {
45
+ if (part.type === "input_image" && typeof part.image_url === "string") {
46
+ const dataUrlMimeType = /^data:([^;,]+)/.exec(part.image_url)?.[1];
47
+ return part.image_url.startsWith("data:") ? {
48
+ type: "blob",
49
+ modality: "image",
50
+ mime_type: dataUrlMimeType
51
+ } : {
52
+ type: "uri",
53
+ modality: "image",
54
+ uri: part.image_url
55
+ };
56
+ }
57
+ if (part.type === "input_json") return {
58
+ type: "object",
59
+ content: part.data
60
+ };
61
+ return {
62
+ type: "text",
63
+ content: part.text ?? part.refusal
64
+ };
65
+ }
19
66
  /** Serialize the answers of a decisions response, laid out and keyed like Jev answers. */
20
67
  function getDecisionOutputMessages(answers) {
21
68
  return getEvaluationOutputMessages(keyByName(answers.map(toJevAnswerFormat)));
@@ -1 +1 @@
1
- {"version":3,"file":"mapping.js","names":[],"sources":["../../../../src/ai/openai/mapping.ts"],"sourcesContent":["/**\n * Maps OpenAI decisions requests and responses to the format Jev calls are recorded in, so Sentry renders\n * both the same way.\n */\nimport { isObjectLike } from '@sentry/core';\nimport { getEvaluationInputMessages, getEvaluationOutputMessages } from '../core/utils';\n\n/**\n * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`\n * so both render the same.\n */\nexport function getDecisionInputMessages(params: Record<string, unknown>): string | undefined {\n const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;\n return getEvaluationInputMessages({ state: params.input, questions: keyByName(questions) });\n}\n\n/** Serialize the answers of a decisions response, laid out and keyed like Jev answers. */\nexport function getDecisionOutputMessages(answers: unknown[]): string | undefined {\n return getEvaluationOutputMessages(keyByName(answers.map(toJevAnswerFormat)));\n}\n\n/**\n * Lay out a decisions question like a Jev question, with its options in `criteria`: choices as\n * `{ [value]: description }` (an empty description when there is none), and score levels as their labels,\n * indexed by score value, with any level descriptions in `descriptions`, keyed by score value.\n */\nfunction toJevQuestionFormat(question: unknown): unknown {\n if (!isObjectLike(question)) {\n return question;\n }\n\n if (question.type === 'choice' && Array.isArray(question.choices)) {\n const { choices, ...rest } = question;\n const criteria = Object.fromEntries(\n choices\n .filter(isObjectLike)\n .map(choice => [String(choice.value), typeof choice.description === 'string' ? choice.description : '']),\n );\n return { ...rest, criteria };\n }\n\n if (question.type === 'score' && Array.isArray(question.levels)) {\n const { levels, ...rest } = question;\n const criteria = levels.map(level => (isObjectLike(level) ? level.label : level));\n // Sentry renders score criteria as a list of labels only, so level descriptions go in their own field,\n // keyed by score value like an answer's `legend`.\n const descriptions = Object.fromEntries(\n levels.flatMap((level, index) =>\n isObjectLike(level) && typeof level.description === 'string' ? [[String(index), level.description]] : [],\n ),\n );\n return Object.keys(descriptions).length ? { ...rest, criteria, descriptions } : { ...rest, criteria };\n }\n\n return question;\n}\n\n/**\n * Lay out choice and score answers like Jev answers: probabilities keyed by option or score value, with\n * score labels in a `legend`. Predicate answers are already in the shape Sentry renders.\n */\nfunction toJevAnswerFormat(answer: unknown): unknown {\n if (\n !isObjectLike(answer) ||\n (answer.type !== 'choice' && answer.type !== 'score') ||\n !Array.isArray(answer.probabilities)\n ) {\n return answer;\n }\n\n const options = answer.probabilities.filter(isObjectLike);\n const probabilities = Object.fromEntries(options.map(option => [String(option.value), option.probability]));\n if (answer.type === 'choice') {\n // Choice values can be booleans, but Sentry renders a choice as a string, like its `probabilities` keys.\n return { ...answer, choice: String(answer.choice), probabilities };\n }\n\n const legend = Object.fromEntries(\n options.filter(option => typeof option.label === 'string').map(option => [String(option.value), option.label]),\n );\n return { ...answer, probabilities, legend };\n}\n\n/**\n * The decisions API lists questions and answers as arrays with an optional `name`, where the conventions\n * key them by question name. An unnamed item is keyed by its position.\n */\nfunction keyByName(items: unknown): unknown {\n if (!Array.isArray(items)) {\n return items;\n }\n\n return Object.fromEntries(\n items.map((item, index) => {\n if (!isObjectLike(item)) {\n return [String(index), item];\n }\n const { name, ...rest } = item;\n return [typeof name === 'string' ? name : String(index), rest];\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,yBAAyB,QAAqD;CAC5F,MAAM,YAAY,MAAM,QAAQ,OAAO,SAAS,IAAI,OAAO,UAAU,IAAI,mBAAmB,IAAI,OAAO;CACvG,OAAO,2BAA2B;EAAE,OAAO,OAAO;EAAO,WAAW,UAAU,SAAS;CAAE,CAAC;AAC5F;;AAGA,SAAgB,0BAA0B,SAAwC;CAChF,OAAO,4BAA4B,UAAU,QAAQ,IAAI,iBAAiB,CAAC,CAAC;AAC9E;;;;;;AAOA,SAAS,oBAAoB,UAA4B;CACvD,IAAI,CAAC,aAAa,QAAQ,GACxB,OAAO;CAGT,IAAI,SAAS,SAAS,YAAY,MAAM,QAAQ,SAAS,OAAO,GAAG;EACjE,MAAM,EAAE,SAAS,GAAG,SAAS;EAC7B,MAAM,WAAW,OAAO,YACtB,QACG,OAAO,YAAY,CAAC,CACpB,KAAI,WAAU,CAAC,OAAO,OAAO,KAAK,GAAG,OAAO,OAAO,gBAAgB,WAAW,OAAO,cAAc,EAAE,CAAC,CAC3G;EACA,OAAO;GAAE,GAAG;GAAM;EAAS;CAC7B;CAEA,IAAI,SAAS,SAAS,WAAW,MAAM,QA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I;EAE7B,MAAM,EAAE,MAAM,GAAG,SAAS;EAC1B,OAAO,CAAC,OAAO,SAAS,WAAW,OAAO,OAAO,KAAK,GAAG,IAAI;CAC/D,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"mapping.js","names":[],"sources":["../../../../src/ai/openai/mapping.ts"],"sourcesContent":["/**\n * Maps OpenAI decisions requests and responses to the format Jev calls are recorded in, so Sentry renders\n * both the same way.\n */\nimport { isObjectLike } from '@sentry/core';\nimport { getEvaluationInputMessages, getEvaluationOutputMessages } from '../core/utils';\nimport type { GenAiMessage, GenAiMessagePart } from '../types';\n\n/**\n * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`\n * so both render the same.\n */\nexport function getDecisionInputMessages(params: Record<string, unknown>): string | undefined {\n const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;\n return getEvaluationInputMessages({ state: toStateMessages(params.input), questions: keyByName(questions) });\n}\n\n/**\n * Lay out evidence messages as gen_ai messages, so they render like Google's. Other input items (tool calls and\n * their outputs) keep their layout, with output parts mapped like message parts.\n */\nfunction toStateMessages(input: unknown): unknown {\n if (!Array.isArray(input)) {\n return input;\n }\n\n return input.map(item => {\n if (!isObjectLike(item)) {\n return item;\n }\n if (typeof item.role === 'string') {\n return {\n // The gen_ai conventions have no `developer` role.\n role: (item.role === 'developer' ? 'system' : item.role) as GenAiMessage['role'],\n parts: Array.isArray(item.content)\n ? item.content.filter(isObjectLike).map(toMessagePart)\n : [{ type: 'text', content: item.content }],\n } satisfies GenAiMessage;\n }\n return Array.isArray(item.output) ? { ...item, output: item.output.filter(isObjectLike).map(toMessagePart) } : item;\n });\n}\n\n/**\n * An image in a data URL is reported by its media type only: the URL holds base64, which the conventions require to be\n * dropped.\n */\nfunction toMessagePart(part: Record<PropertyKey, unknown>): GenAiMessagePart {\n if (part.type === 'input_image' && typeof part.image_url === 'string') {\n const dataUrlMimeType = /^data:([^;,]+)/.exec(part.image_url)?.[1];\n return part.image_url.startsWith('data:')\n ? { type: 'blob', modality: 'image', mime_type: dataUrlMimeType }\n : { type: 'uri', modality: 'image', uri: part.image_url };\n }\n if (part.type === 'input_json') {\n return { type: 'object', content: part.data };\n }\n return { type: 'text', content: part.text ?? part.refusal };\n}\n\n/** Serialize the answers of a decisions response, laid out and keyed like Jev answers. */\nexport function getDecisionOutputMessages(answers: unknown[]): string | undefined {\n return getEvaluationOutputMessages(keyByName(answers.map(toJevAnswerFormat)));\n}\n\n/**\n * Lay out a decisions question like a Jev question, with its options in `criteria`: choices as\n * `{ [value]: description }` (an empty description when there is none), and score levels as their labels,\n * indexed by score value, with any level descriptions in `descriptions`, keyed by score value.\n */\nfunction toJevQuestionFormat(question: unknown): unknown {\n if (!isObjectLike(question)) {\n return question;\n }\n\n if (question.type === 'choice' && Array.isArray(question.choices)) {\n const { choices, ...rest } = question;\n const criteria = Object.fromEntries(\n choices\n .filter(isObjectLike)\n .map(choice => [String(choice.value), typeof choice.description === 'string' ? choice.description : '']),\n );\n return { ...rest, criteria };\n }\n\n if (question.type === 'score' && Array.isArray(question.levels)) {\n const { levels, ...rest } = question;\n const criteria = levels.map(level => (isObjectLike(level) ? level.label : level));\n // Sentry renders score criteria as a list of labels only, so level descriptions go in their own field,\n // keyed by score value like an answer's `legend`.\n const descriptions = Object.fromEntries(\n levels.flatMap((level, index) =>\n isObjectLike(level) && typeof level.description === 'string' ? [[String(index), level.description]] : [],\n ),\n );\n return Object.keys(descriptions).length ? { ...rest, criteria, descriptions } : { ...rest, criteria };\n }\n\n return question;\n}\n\n/**\n * Lay out choice and score answers like Jev answers: probabilities keyed by option or score value, with\n * score labels in a `legend`. Predicate answers are already in the shape Sentry renders.\n */\nfunction toJevAnswerFormat(answer: unknown): unknown {\n if (\n !isObjectLike(answer) ||\n (answer.type !== 'choice' && answer.type !== 'score') ||\n !Array.isArray(answer.probabilities)\n ) {\n return answer;\n }\n\n const options = answer.probabilities.filter(isObjectLike);\n const probabilities = Object.fromEntries(options.map(option => [String(option.value), option.probability]));\n if (answer.type === 'choice') {\n // Choice values can be booleans, but Sentry renders a choice as a string, like its `probabilities` keys.\n return { ...answer, choice: String(answer.choice), probabilities };\n }\n\n const legend = Object.fromEntries(\n options.filter(option => typeof option.label === 'string').map(option => [String(option.value), option.label]),\n );\n return { ...answer, probabilities, legend };\n}\n\n/**\n * The decisions API lists questions and answers as arrays with an optional `name`, where the conventions\n * key them by question name. An unnamed item is keyed by its position.\n */\nfunction keyByName(items: unknown): unknown {\n if (!Array.isArray(items)) {\n return items;\n }\n\n return Object.fromEntries(\n items.map((item, index) => {\n if (!isObjectLike(item)) {\n return [String(index), item];\n }\n const { name, ...rest } = item;\n return [typeof name === 'string' ? name : String(index), rest];\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,yBAAyB,QAAqD;CAC5F,MAAM,YAAY,MAAM,QAAQ,OAAO,SAAS,IAAI,OAAO,UAAU,IAAI,mBAAmB,IAAI,OAAO;CACvG,OAAO,2BAA2B;EAAE,OAAO,gBAAgB,OAAO,KAAK;EAAG,WAAW,UAAU,SAAS;CAAE,CAAC;AAC7G;;;;;AAMA,SAAS,gBAAgB,OAAyB;CAChD,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,OAAO;CAGT,OAAO,MAAM,KAAI,SAAQ;EACvB,IAAI,CAAC,aAAa,IAAI,GACpB,OAAO;EAET,IAAI,OAAO,KAAK,SAAS,UACvB,OAAO;GAEL,MAAO,KAAK,SAAS,cAAc,WAAW,KAAK;GACnD,OAAO,MAAM,QAAQ,KAAK,OAAO,IAC7B,KAAK,QAAQ,OAAO,YAAY,CAAC,CAAC,IAAI,aAAa,IACnD,CAAC;IAAE,MAAM;IAAQ,SAAS,KAAK;GAAQ,CAAC;EAC9C;EAEF,OAAO,MAAM,QAAQ,KAAK,MAAM,IAAI;GAAE,GAAG;GAAM,QAAQ,KAAK,OAAO,OAAO,YAAY,CAAC,CAAC,IAAI,aAAa;EAAE,IAAI;CACjH,CAA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
  import { monitorStream } from "./monitorStream.js";
3
- import { CLIENT_ADDRESS, CLIENT_PORT, HTTP_REQUEST_BODY_SIZE, NETWORK_PROTOCOL_NAME, SENTRY_OP, SENTRY_SEGMENT_NAME_SOURCE, USER_AGENT_ORIGINAL } from "@sentry/conventions/attributes";
3
+ import { CLIENT_ADDRESS, CLIENT_PORT, HTTP_REQUEST_BODY_SIZE, NETWORK_PROTOCOL_NAME, SENTRY_KIND, SENTRY_OP, SENTRY_SEGMENT_NAME_SOURCE, USER_AGENT_ORIGINAL } from "@sentry/conventions/attributes";
4
4
  import { HTTP_SPAN_NAME_FALLBACK, SPAN_STATUS_ERROR, captureBodyFromWinterCGRequest, captureException, continueTrace, getCurrentScope, getHttpSpanDetailsFromUrlObject, hasSpanStreamingEnabled, hasSpansEnabled, httpHeadersToSpanAttributes, parseStringToURLObject, safeCallback, setHttpStatus, startSpanManual, winterCGHeadersToDict, winterCGRequestToRequestData, withIsolationScope, withScope } from "@sentry/core";
5
5
  import { HTTP_SERVER } from "@sentry/conventions/op";
6
6
  import { _INTERNAL_isServedTunnelRequest, classifyResponseStreaming, getClientIPAddress, isStaticAssetRequest, startRequestSession } from "@sentry/core/server";
@@ -112,6 +112,7 @@ async function wrapServerRequestHandler(config, handler) {
112
112
  Object.assign(attributes, httpHeadersToSpanAttributes(headers, dataCollection));
113
113
  Object.assign(attributes, config.attributes);
114
114
  attributes[SENTRY_OP] = HTTP_SERVER;
115
+ attributes[SENTRY_KIND] = "server";
115
116
  return startSpanManual({
116
117
  name,
117
118
  attributes
@@ -1 +1 @@
1
- {"version":3,"file":"wrapServerRequestHandler.js","names":["isServedTunnelRequest"],"sources":["../../../src/utils/wrapServerRequestHandler.ts"],"sourcesContent":["import {\n CLIENT_ADDRESS,\n CLIENT_PORT,\n HTTP_REQUEST_BODY_SIZE,\n NETWORK_PROTOCOL_NAME,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n USER_AGENT_ORIGINAL,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport type { Client, Mechanism, Scope, SpanAttributes } from '@sentry/core';\nimport {\n captureBodyFromWinterCGRequest,\n captureException,\n continueTrace,\n getCurrentScope,\n getHttpSpanDetailsFromUrlObject,\n hasSpansEnabled,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n safeCallback,\n setHttpStatus,\n SPAN_STATUS_ERROR,\n startSpanManual,\n winterCGHeadersToDict,\n winterCGRequestToRequestData,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type { ServerRequestOptions } from '@sentry/core/server';\nimport {\n _INTERNAL_isServedTunnelRequest as isServedTunnelRequest,\n classifyResponseStreaming,\n getClientIPAddress,\n isStaticAssetRequest,\n startRequestSession,\n} from '@sentry/core/server';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { monitorStream } from './monitorStream';\n\nexport interface ServerRequestHandlerConfig {\n request: Request;\n client: Client;\n /** The isolation scope of this request. */\n isolationScope: Scope;\n /** The options of the runtime's integration for incoming requests. */\n options: ServerRequestOptions<Request, Response> | undefined;\n /** Origin of the span, e.g. `auto.http.deno`. */\n origin: string;\n /** Mechanism of errors that the handler or the response stream throws. Omit to not capture them. */\n mechanism?: Mechanism;\n /** The address and port of the socket, if the runtime knows them. */\n getSocketAddress?: () => { address: string; port?: number } | undefined;\n /** The matched route of the server framework, e.g. `/users/:id`. Sets `http.route` and the span name. */\n routeName?: string;\n /** Span attributes that only the runtime knows, e.g. the route parameters. */\n attributes?: SpanAttributes;\n /**\n * Called in the scope of the continued trace, before the span starts. Lets the runtime continue\n * its own trace, e.g. the trace that Cloudflare exports for the invocation.\n */\n onTraceContinued?: () => void;\n /** Whether the response streams. Return `undefined` to use the default classification. */\n isStreamingResponse?: (response: Response) => boolean | undefined;\n /**\n * Called once when the request is done: when the response is returned, when a streamed body\n * finishes, or when the handler throws (then without a response).\n */\n onDone?: (response: Response | undefined) => void;\n}\n\n/**\n * Wraps a handler of a web `Request`, as used by `Deno.serve`, `Bun.serve` and Cloudflare Workers.\n *\n * It records the request session, attaches the request data and body, continues the incoming\n * trace, creates the `http.server` span, and captures errors that the handler throws. The rules\n * follow core's `node:http` server code:\n *\n * - `OPTIONS` and `HEAD` requests get no span and no body capture.\n * - The static asset filter applies only to `GET`.\n * - The span and the session of a streamed response end when the stream finishes.\n *\n * The handler can return no response, as Bun's `fetch` does after a WebSocket upgrade.\n */\nexport async function wrapServerRequestHandler<R extends Response | undefined = Response>(\n config: ServerRequestHandlerConfig,\n handler: () => R | Promise<R>,\n): Promise<R> {\n const { request, client, isolationScope, options, mechanism } = config;\n\n const method = request.method.toUpperCase();\n const captureError = (error: unknown): void => {\n if (mechanism) {\n captureException(error, { mechanism });\n }\n };\n\n const socketAddress = config.getSocketAddress?.();\n // Without `AsyncLocalStorage`, all requests share one isolation scope, so clear what an earlier\n // request left on it: the merge keeps its body, and its response context would stay set.\n isolationScope.setSDKProcessingMetadata({\n normalizedRequest: { ...winterCGRequestToRequestData(request), data: undefined },\n ipAddress: socketAddress?.address,\n });\n isolationScope.setContext('response', null);\n\n // Tunnel requests get no session, body or span, whether the SDK or the app answers them. The app answers them with\n // `intercept: false`, from its own code, so its errors are still captured.\n if (isServedTunnelRequest(request, client)) {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n config.onDone?.(response);\n }\n }\n\n const endSession = options?.sessions\n ? startRequestSession(client, {\n requestIsolationScope: isolationScope,\n sessionFlushingDelayMS: options.sessionFlushingDelayMS,\n })\n : undefined;\n const finish = (response: Response | undefined): void => {\n endSession?.();\n config.onDone?.(response);\n };\n const isStreamingResponse = (response: Response): boolean => {\n const classification = config.isStreamingResponse?.(response);\n return typeof classification === 'boolean' ? classification : classifyResponseStreaming(response).isStreaming;\n };\n\n if (method === 'OPTIONS' || method === 'HEAD') {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n finish(response);\n }\n }\n\n const dataCollection = client.getDataCollectionOptions();\n const effectiveBodySize =\n options?.maxRequestBodySize ?? (dataCollection.httpBodies.includes('incomingRequest') ? 'medium' : 'none');\n const ignoreRequestBody = options?.ignoreRequestBody;\n if (\n method !== 'GET' &&\n effectiveBodySize !== 'none' &&\n // If the filter throws, skip the body so it cannot leak data the filter was meant to hide.\n !(\n ignoreRequestBody &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreRequestBody`, skipping the body:' : '',\n () => ignoreRequestBody(request.url, request),\n () => true,\n )\n )\n ) {\n await captureBodyFromWinterCGRequest(request, isolationScope, effectiveBodySize);\n }\n\n const urlObject = parseStringToURLObject(request.url);\n const urlPath = urlObject ? `${urlObject.pathname}${urlObject.search}` : '/';\n const createSpan = shouldCreateSpan(client, options, request, urlPath);\n\n return continueTrace(\n {\n sentryTrace: request.headers.get('sentry-trace') || '',\n baggage: request.headers.get('baggage'),\n },\n async () => {\n config.onTraceContinued?.();\n\n if (!createSpan) {\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n captureError(e);\n finish(undefined);\n throw e;\n }\n if (response) {\n isolationScope.setContext('response', { status_code: response.status });\n }\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => finish(response)),\n inRequestScope(captureError),\n );\n }\n\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n config.origin,\n request,\n config.routeName,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !hasSpanStreamingEnabled(client)\n ? rawName\n : method || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes[HTTP_REQUEST_BODY_SIZE] = parseInt(contentLength, 10);\n }\n const userAgent = request.headers.get('user-agent');\n if (userAgent) {\n attributes[USER_AGENT_ORIGINAL] = userAgent;\n }\n\n const headers = winterCGHeadersToDict(request.headers);\n if (dataCollection.userInfo) {\n // `client.address` is the originating client, so a forwarding header wins over the socket, which\n // behind a proxy holds the proxy's address. The socket port is the proxy's too, so `client.port`\n // stays unset then.\n const forwardedAddress = getClientIPAddress(headers);\n if (forwardedAddress) {\n attributes[CLIENT_ADDRESS] = forwardedAddress;\n } else if (socketAddress) {\n attributes[CLIENT_ADDRESS] = socketAddress.address;\n if (socketAddress.port !== undefined) {\n attributes[CLIENT_PORT] = socketAddress.port;\n }\n }\n }\n\n // describes the OSI application-layer protocol (http), not the scheme (might be https)\n attributes[NETWORK_PROTOCOL_NAME] = 'http';\n Object.assign(attributes, httpHeadersToSpanAttributes(headers, dataCollection));\n Object.assign(attributes, config.attributes);\n attributes[SENTRY_OP] = HTTP_SERVER;\n\n return startSpanManual({ name, attributes }, async span => {\n const { onSpanCreated, onSpanEnd } = options ?? {};\n if (onSpanCreated) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanCreated`:' : '',\n () => onSpanCreated(span, request),\n () => undefined,\n );\n }\n\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n span.end();\n captureError(e);\n finish(undefined);\n throw e;\n }\n\n if (response) {\n setHttpStatus(span, response.status);\n isolationScope.setContext('response', { status_code: response.status });\n span.setAttributes(\n httpHeadersToSpanAttributes(responseHeadersToDict(response.headers), dataCollection, 'response'),\n );\n }\n\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => {\n if (onSpanEnd && response) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanEnd`:' : '',\n () => onSpanEnd(span, request, response),\n () => undefined,\n );\n }\n span.end();\n finish(response);\n }),\n inRequestScope((error: unknown) => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureError(error);\n }),\n );\n });\n },\n );\n}\n\n/**\n * Returns a function that binds a callback to the request's isolation scope and the current scope.\n *\n * A streamed body finishes after the handler returns. Without `AsyncLocalStorage` (Cloudflare\n * Workers without `nodejs_compat`), its callbacks then run outside the request's scopes, where\n * `getClient()` finds no client: the segment span would be sent as a transaction, and a captured\n * error would not update the request session.\n */\nfunction bindToRequestScope(\n isolationScope: Scope,\n): <A extends unknown[]>(fn: (...args: A) => void) => (...args: A) => void {\n const scope = getCurrentScope();\n return fn =>\n (...args) =>\n withIsolationScope(isolationScope, () => withScope(scope, () => fn(...args)));\n}\n\nfunction shouldCreateSpan(\n client: Client,\n options: ServerRequestOptions<Request, Response> | undefined,\n request: Request,\n urlPath: string,\n): boolean {\n if (!(options?.spans ?? hasSpansEnabled(client.getOptions()))) {\n return false;\n }\n if (options?.ignoreStaticAssets && request.method.toUpperCase() === 'GET' && isStaticAssetRequest(urlPath)) {\n return false;\n }\n const ignoreIncomingRequests = options?.ignoreIncomingRequests;\n return !(\n ignoreIncomingRequests &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreIncomingRequests`, creating the span:' : '',\n () => ignoreIncomingRequests(urlPath, request),\n () => false,\n )\n );\n}\n\n/**\n * Calls `onDone` when the response is done: at once, or when a streamed body finishes.\n * Returns the response to send.\n */\nfunction onResponseDone<R extends Response | undefined>(\n response: R,\n isStreaming: boolean,\n onDone: () => void,\n onStreamError: (error: unknown) => void,\n): R {\n if (isStreaming && response?.body && !response.body.locked) {\n try {\n // Passing the original response as the init keeps its status, status text and headers, and\n // on Cloudflare also `encodeBody: 'manual'`, so workerd does not compress a compressed body again.\n return new Response(monitorStream(response.body, onDone, onStreamError), response) as R;\n } catch {\n // Workers with a compatibility date before 2022-11-30 and without the\n // `streams_enable_constructors` flag cannot construct a `ReadableStream`, so end at once.\n }\n }\n onDone();\n return response;\n}\n\n// `Headers.forEach` lists each `Set-Cookie` header on its own, so a plain dict keeps only the last one.\nfunction responseHeadersToDict(headers: Headers): Record<string, string | string[]> {\n const dict: Record<string, string | string[]> = winterCGHeadersToDict(headers);\n const setCookie = typeof headers.getSetCookie === 'function' ? headers.getSetCookie() : [];\n if (setCookie.length) {\n dict['set-cookie'] = setCookie;\n }\n return dict;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsFA,eAAsB,yBACpB,QACA,SACY;CACZ,MAAM,EAAE,SAAS,QAAQ,gBAAgB,SAAS,cAAc;CAEhE,MAAM,SAAS,QAAQ,OAAO,YAAY;CAC1C,MAAM,gBAAgB,UAAyB;EAC7C,IAAI,WACF,iBAAiB,OAAO,EAAE,UAAU,CAAC;CAEzC;CAEA,MAAM,gBAAgB,OAAO,mBAAmB;CAGhD,eAAe,yBAAyB;EACtC,mBAAmB;GAAE,GAAG,6BAA6B,OAAO;GAAG,MAAM,KAAA;EAAU;EAC/E,WAAW,eAAe;CAC5B,CAAC;CACD,eAAe,WAAW,YAAY,IAAI;CAI1C,IAAIA,gCAAsB,SAAS,MAAM,GAAG;EAC1C,IAAI;EACJ,IAAI;GACF,WAAW,MAAM,QAAQ;GACzB,OAAO;EACT,SAAS,GAAG;GACV,aAAa,CAAC;GACd,MAAM;EACR,UAAU;GACR,OAAO,SAAS,QAAQ;EAC1B;CACF;CAEA,MAAM,aAAa,SAAS,WACxB,oBAAoB,QAAQ;EAC1B,uBAAuB;EACvB,wBAAwB,QAAQ;CAClC,CAAC,IACD,KAAA;CACJ,MAAM,UAAU,aAAyC;EACvD,aAAa;EACb,OAAO,SAAS,QAAQ;CAC1B;CACA,MAAM,uBAAuB,aAAgC;EAC3D,MAAM,iBAAiB,OAAO,sBAAsB,QAAQ;EAC5D,OAAO,OAAO,mBAAmB,YAAY,iBAAiB,0BAA0B,QAAQ,CAAC,CAAC;CACpG;CAEA,IAAI,WAAW,aAAa,WAAW,QAAQ;EAC7C,IAAI;EACJ,IAAI;GACF,WAAW,MAAM,QAAQ;GACzB,OAAO;E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EF,KAAK,IAAI;IACT,OAAO,QAAQ;GACjB,CAAC,GACD,gBAAgB,UAAmB;IACjC,KAAK,UAAU;KAAE,MAAM;KAAmB,SAAS;IAAiB,CAAC;IACrE,aAAa,KAAK;GACpB,CAAC,CACH;EACF,CAAC;CACH,CACF;AACF;;;;;;;;;AAUA,SAAS,mBACP,gBACyE;CACzE,MAAM,QAAQ,gBAAgB;CAC9B,QAAO,QACJ,GAAG,SACF,mBAAmB,sBAAsB,UAAU,aAAa,GAAG,GAAG,IAAI,CAAC,CAAC;AAClF;AAEA,SAAS,iBACP,QACA,SACA,SACA,SACS;CACT,IAAI,EAAE,SAAS,SAAS,gBAAgB,OAAO,WAAW,CAAC,IACzD,OAAO;CAET,IAAI,SAAS,sBAAsB,QAAQ,OAAO,YAAY,MAAM,SAAS,qBAAqB,OAAO,GACvG,OAAO;CAET,MAAM,yBAAyB,SAAS;CACxC,OAAO,EACL,0BACA,aACE,cAAc,0DAA0D,UAClE,uBAAuB,SAAS,OAAO,SACvC,KACR;AAEJ;;;;;AAMA,SAAS,eACP,UACA,aACA,QACA,eACG;CACH,IAAI,eAAe,UAAU,QAAQ,CAAC,SAAS,KAAK,QAClD,IAAI;EAGF,OAAO,IAAI,SAAS,cAAc,SAAS,MAAM,QAAQ,aAAa,GAAG,QAAQ;CACnF,QAAQ,CAGR;CAEF,OAAO;CACP,OAAO;AACT;AAGA,SAAS,sBAAsB,SAAqD;CAClF,MAAM,OAA0C,sBAAsB,OAAO;CAC7E,MAAM,YAAY,OAAO,QAAQ,iBAAiB,aAAa,QAAQ,aAAa,IAAI,CAAC;CACzF,IAAI,UAAU,QACZ,KAAK,gBAAgB;CAEvB,OAAO;AACT"}
1
+ {"version":3,"file":"wrapServerRequestHandler.js","names":["isServedTunnelRequest"],"sources":["../../../src/utils/wrapServerRequestHandler.ts"],"sourcesContent":["import {\n CLIENT_ADDRESS,\n CLIENT_PORT,\n HTTP_REQUEST_BODY_SIZE,\n NETWORK_PROTOCOL_NAME,\n SENTRY_KIND,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n USER_AGENT_ORIGINAL,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport type { Client, Mechanism, Scope, SpanAttributes } from '@sentry/core';\nimport {\n captureBodyFromWinterCGRequest,\n captureException,\n continueTrace,\n getCurrentScope,\n getHttpSpanDetailsFromUrlObject,\n hasSpansEnabled,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n safeCallback,\n setHttpStatus,\n SPAN_STATUS_ERROR,\n startSpanManual,\n winterCGHeadersToDict,\n winterCGRequestToRequestData,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type { ServerRequestOptions } from '@sentry/core/server';\nimport {\n _INTERNAL_isServedTunnelRequest as isServedTunnelRequest,\n classifyResponseStreaming,\n getClientIPAddress,\n isStaticAssetRequest,\n startRequestSession,\n} from '@sentry/core/server';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { monitorStream } from './monitorStream';\n\nexport interface ServerRequestHandlerConfig {\n request: Request;\n client: Client;\n /** The isolation scope of this request. */\n isolationScope: Scope;\n /** The options of the runtime's integration for incoming requests. */\n options: ServerRequestOptions<Request, Response> | undefined;\n /** Origin of the span, e.g. `auto.http.deno`. */\n origin: string;\n /** Mechanism of errors that the handler or the response stream throws. Omit to not capture them. */\n mechanism?: Mechanism;\n /** The address and port of the socket, if the runtime knows them. */\n getSocketAddress?: () => { address: string; port?: number } | undefined;\n /** The matched route of the server framework, e.g. `/users/:id`. Sets `http.route` and the span name. */\n routeName?: string;\n /** Span attributes that only the runtime knows, e.g. the route parameters. */\n attributes?: SpanAttributes;\n /**\n * Called in the scope of the continued trace, before the span starts. Lets the runtime continue\n * its own trace, e.g. the trace that Cloudflare exports for the invocation.\n */\n onTraceContinued?: () => void;\n /** Whether the response streams. Return `undefined` to use the default classification. */\n isStreamingResponse?: (response: Response) => boolean | undefined;\n /**\n * Called once when the request is done: when the response is returned, when a streamed body\n * finishes, or when the handler throws (then without a response).\n */\n onDone?: (response: Response | undefined) => void;\n}\n\n/**\n * Wraps a handler of a web `Request`, as used by `Deno.serve`, `Bun.serve` and Cloudflare Workers.\n *\n * It records the request session, attaches the request data and body, continues the incoming\n * trace, creates the `http.server` span, and captures errors that the handler throws. The rules\n * follow core's `node:http` server code:\n *\n * - `OPTIONS` and `HEAD` requests get no span and no body capture.\n * - The static asset filter applies only to `GET`.\n * - The span and the session of a streamed response end when the stream finishes.\n *\n * The handler can return no response, as Bun's `fetch` does after a WebSocket upgrade.\n */\nexport async function wrapServerRequestHandler<R extends Response | undefined = Response>(\n config: ServerRequestHandlerConfig,\n handler: () => R | Promise<R>,\n): Promise<R> {\n const { request, client, isolationScope, options, mechanism } = config;\n\n const method = request.method.toUpperCase();\n const captureError = (error: unknown): void => {\n if (mechanism) {\n captureException(error, { mechanism });\n }\n };\n\n const socketAddress = config.getSocketAddress?.();\n // Without `AsyncLocalStorage`, all requests share one isolation scope, so clear what an earlier\n // request left on it: the merge keeps its body, and its response context would stay set.\n isolationScope.setSDKProcessingMetadata({\n normalizedRequest: { ...winterCGRequestToRequestData(request), data: undefined },\n ipAddress: socketAddress?.address,\n });\n isolationScope.setContext('response', null);\n\n // Tunnel requests get no session, body or span, whether the SDK or the app answers them. The app answers them with\n // `intercept: false`, from its own code, so its errors are still captured.\n if (isServedTunnelRequest(request, client)) {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n config.onDone?.(response);\n }\n }\n\n const endSession = options?.sessions\n ? startRequestSession(client, {\n requestIsolationScope: isolationScope,\n sessionFlushingDelayMS: options.sessionFlushingDelayMS,\n })\n : undefined;\n const finish = (response: Response | undefined): void => {\n endSession?.();\n config.onDone?.(response);\n };\n const isStreamingResponse = (response: Response): boolean => {\n const classification = config.isStreamingResponse?.(response);\n return typeof classification === 'boolean' ? classification : classifyResponseStreaming(response).isStreaming;\n };\n\n if (method === 'OPTIONS' || method === 'HEAD') {\n let response: R | undefined;\n try {\n response = await handler();\n return response;\n } catch (e) {\n captureError(e);\n throw e;\n } finally {\n finish(response);\n }\n }\n\n const dataCollection = client.getDataCollectionOptions();\n const effectiveBodySize =\n options?.maxRequestBodySize ?? (dataCollection.httpBodies.includes('incomingRequest') ? 'medium' : 'none');\n const ignoreRequestBody = options?.ignoreRequestBody;\n if (\n method !== 'GET' &&\n effectiveBodySize !== 'none' &&\n // If the filter throws, skip the body so it cannot leak data the filter was meant to hide.\n !(\n ignoreRequestBody &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreRequestBody`, skipping the body:' : '',\n () => ignoreRequestBody(request.url, request),\n () => true,\n )\n )\n ) {\n await captureBodyFromWinterCGRequest(request, isolationScope, effectiveBodySize);\n }\n\n const urlObject = parseStringToURLObject(request.url);\n const urlPath = urlObject ? `${urlObject.pathname}${urlObject.search}` : '/';\n const createSpan = shouldCreateSpan(client, options, request, urlPath);\n\n return continueTrace(\n {\n sentryTrace: request.headers.get('sentry-trace') || '',\n baggage: request.headers.get('baggage'),\n },\n async () => {\n config.onTraceContinued?.();\n\n if (!createSpan) {\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n captureError(e);\n finish(undefined);\n throw e;\n }\n if (response) {\n isolationScope.setContext('response', { status_code: response.status });\n }\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => finish(response)),\n inRequestScope(captureError),\n );\n }\n\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n config.origin,\n request,\n config.routeName,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !hasSpanStreamingEnabled(client)\n ? rawName\n : method || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes[HTTP_REQUEST_BODY_SIZE] = parseInt(contentLength, 10);\n }\n const userAgent = request.headers.get('user-agent');\n if (userAgent) {\n attributes[USER_AGENT_ORIGINAL] = userAgent;\n }\n\n const headers = winterCGHeadersToDict(request.headers);\n if (dataCollection.userInfo) {\n // `client.address` is the originating client, so a forwarding header wins over the socket, which\n // behind a proxy holds the proxy's address. The socket port is the proxy's too, so `client.port`\n // stays unset then.\n const forwardedAddress = getClientIPAddress(headers);\n if (forwardedAddress) {\n attributes[CLIENT_ADDRESS] = forwardedAddress;\n } else if (socketAddress) {\n attributes[CLIENT_ADDRESS] = socketAddress.address;\n if (socketAddress.port !== undefined) {\n attributes[CLIENT_PORT] = socketAddress.port;\n }\n }\n }\n\n // describes the OSI application-layer protocol (http), not the scheme (might be https)\n attributes[NETWORK_PROTOCOL_NAME] = 'http';\n Object.assign(attributes, httpHeadersToSpanAttributes(headers, dataCollection));\n Object.assign(attributes, config.attributes);\n attributes[SENTRY_OP] = HTTP_SERVER;\n attributes[SENTRY_KIND] = 'server';\n\n return startSpanManual({ name, attributes }, async span => {\n const { onSpanCreated, onSpanEnd } = options ?? {};\n if (onSpanCreated) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanCreated`:' : '',\n () => onSpanCreated(span, request),\n () => undefined,\n );\n }\n\n let response: R;\n try {\n response = await handler();\n } catch (e) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n span.end();\n captureError(e);\n finish(undefined);\n throw e;\n }\n\n if (response) {\n setHttpStatus(span, response.status);\n isolationScope.setContext('response', { status_code: response.status });\n span.setAttributes(\n httpHeadersToSpanAttributes(responseHeadersToDict(response.headers), dataCollection, 'response'),\n );\n }\n\n const inRequestScope = bindToRequestScope(isolationScope);\n return onResponseDone(\n response,\n !!response && isStreamingResponse(response),\n inRequestScope(() => {\n if (onSpanEnd && response) {\n safeCallback(\n DEBUG_BUILD ? 'Error in `onSpanEnd`:' : '',\n () => onSpanEnd(span, request, response),\n () => undefined,\n );\n }\n span.end();\n finish(response);\n }),\n inRequestScope((error: unknown) => {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureError(error);\n }),\n );\n });\n },\n );\n}\n\n/**\n * Returns a function that binds a callback to the request's isolation scope and the current scope.\n *\n * A streamed body finishes after the handler returns. Without `AsyncLocalStorage` (Cloudflare\n * Workers without `nodejs_compat`), its callbacks then run outside the request's scopes, where\n * `getClient()` finds no client: the segment span would be sent as a transaction, and a captured\n * error would not update the request session.\n */\nfunction bindToRequestScope(\n isolationScope: Scope,\n): <A extends unknown[]>(fn: (...args: A) => void) => (...args: A) => void {\n const scope = getCurrentScope();\n return fn =>\n (...args) =>\n withIsolationScope(isolationScope, () => withScope(scope, () => fn(...args)));\n}\n\nfunction shouldCreateSpan(\n client: Client,\n options: ServerRequestOptions<Request, Response> | undefined,\n request: Request,\n urlPath: string,\n): boolean {\n if (!(options?.spans ?? hasSpansEnabled(client.getOptions()))) {\n return false;\n }\n if (options?.ignoreStaticAssets && request.method.toUpperCase() === 'GET' && isStaticAssetRequest(urlPath)) {\n return false;\n }\n const ignoreIncomingRequests = options?.ignoreIncomingRequests;\n return !(\n ignoreIncomingRequests &&\n safeCallback(\n DEBUG_BUILD ? 'Error in `ignoreIncomingRequests`, creating the span:' : '',\n () => ignoreIncomingRequests(urlPath, request),\n () => false,\n )\n );\n}\n\n/**\n * Calls `onDone` when the response is done: at once, or when a streamed body finishes.\n * Returns the response to send.\n */\nfunction onResponseDone<R extends Response | undefined>(\n response: R,\n isStreaming: boolean,\n onDone: () => void,\n onStreamError: (error: unknown) => void,\n): R {\n if (isStreaming && response?.body && !response.body.locked) {\n try {\n // Passing the original response as the init keeps its status, status text and headers, and\n // on Cloudflare also `encodeBody: 'manual'`, so workerd does not compress a compressed body again.\n return new Response(monitorStream(response.body, onDone, onStreamError), response) as R;\n } catch {\n // Workers with a compatibility date before 2022-11-30 and without the\n // `streams_enable_constructors` flag cannot construct a `ReadableStream`, so end at once.\n }\n }\n onDone();\n return response;\n}\n\n// `Headers.forEach` lists each `Set-Cookie` header on its own, so a plain dict keeps only the last one.\nfunction responseHeadersToDict(headers: Headers): Record<string, string | string[]> {\n const dict: Record<string, string | string[]> = winterCGHeadersToDict(headers);\n const setCookie = typeof headers.getSetCookie === 'function' ? headers.getSetCookie() : [];\n if (setCookie.length) {\n dict['set-cookie'] = setCookie;\n }\n return dict;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuFA,eAAsB,yBACpB,QACA,SACY;CACZ,MAAM,EAAE,SAAS,QAAQ,gBAAgB,SAAS,cAAc;CAEhE,MAAM,SAAS,QAAQ,OAAO,YAAY;CAC1C,MAAM,gBAAgB,UAAyB;EAC7C,IAAI,WACF,iBAAiB,OAAO,EAAE,UAAU,CAAC;CAEzC;CAEA,MAAM,gBAAgB,OAAO,mBAAmB;CAGhD,eAAe,yBAAyB;EACtC,mBAAmB;GAAE,GAAG,6BAA6B,OAAO;GAAG,MAAM,KAAA;EAAU;EAC/E,WAAW,eAAe;CAC5B,CAAC;CACD,eAAe,WAAW,YAAY,IAAI;CAI1C,IAAIA,gCAAsB,SAAS,MAAM,GAAG;EAC1C,IAAI;EACJ,IAAI;GACF,WAAW,MAAM,QAAQ;GACzB,OAAO;EACT,SAAS,GAAG;GACV,aAAa,CAAC;GACd,MAAM;EACR,UAAU;GACR,OAAO,SAAS,QAAQ;EAC1B;CACF;CAEA,MAAM,aAAa,SAAS,WACxB,oBAAoB,QAAQ;EAC1B,uBAAuB;EACvB,wBAAwB,QAAQ;CAClC,CAAC,IACD,KAAA;CACJ,MAAM,UAAU,aAAyC;EACvD,aAAa;EACb,OAAO,SAAS,QAAQ;CAC1B;CACA,MAAM,uBAAuB,aAAgC;EAC3D,MAAM,iBAAiB,OAAO,sBAAsB,QAAQ;EAC5D,OAAO,OAAO,mBAAmB,YAAY,iBAAiB,0BAA0B,QAAQ,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ot":"","sources":["../../../../src/ai/flue/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAiBjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,KAAK,EAAE,YAAY,EAAiB,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE9F;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAqD/C;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,GAAG,cAAc,CAAC,YAAY,EAAE,eAAe,CAAC,GACtF,IAAI,CA6BN;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAqBtF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/ai/flue/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAiBjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,KAAK,EAAE,YAAY,EAAiB,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE9F;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAqD/C;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,GAAG,cAAc,CAAC,YAAY,EAAE,eAAe,CAAC,GACtF,IAAI,CAiCN;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI,CAqBtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"decisions.d.ts","sourceRoot":"","sources":["../../../../src/ai/google-genai/decisions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAIzC;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAE5F;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI,CAqBzG"}
1
+ {"version":3,"file":"decisions.d.ts","sourceRoot":"","sources":["../../../../src/ai/google-genai/decisions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAKzC;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAE5F;AAwBD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI,CAqBzG"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../../src/ai/openai/mapping.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAG5F;AAED,0FAA0F;AAC1F,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CAEhF"}
1
+ {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../../src/ai/openai/mapping.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAG5F;AA6CD,0FAA0F;AAC1F,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CAEhF"}
@@ -5,6 +5,6 @@ export interface GenAiMessage {
5
5
  finish_reason?: string;
6
6
  }
7
7
  export type GenAiMessagePart = Record<string, unknown> & {
8
- type: 'blob' | 'object' | 'reasoning' | 'text' | 'tool_call' | 'tool_call_response';
8
+ type: 'blob' | 'object' | 'reasoning' | 'text' | 'tool_call' | 'tool_call_response' | 'uri';
9
9
  };
10
10
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ai/types.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/C,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACvD,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,oBAAoB,CAAC;CACrF,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ai/types.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,GAAG,QAA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AAI,CAAC;IAC9B,0FAA0F;IAC1F,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,GAAG,SAAS,CAAC;IAClE;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;CACnD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAAC,CAAC,SAAS,QAAQ,GAAG,SAAS,GAAG,QAAQ,EACtF,MAAM,EAAE,0BAA0B,EAClC,OAAO,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,CAAC,CAAC,CAsNZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/server-utils",
3
- "version": "11.15.0",
3
+ "version": "11.16.0",
4
4
  "description": "Server Utilities for all Sentry JavaScript SDKs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -105,13 +105,13 @@
105
105
  },
106
106
  "dependencies": {
107
107
  "@opentelemetry/api": "^1.9.1",
108
- "@sentry/conventions": "^0.33.0",
109
- "@sentry/core": "11.15.0"
108
+ "@sentry/conventions": "^0.34.0",
109
+ "@sentry/core": "11.16.0"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@apm-js-collab/code-transformer-bundler-plugins": "^0.7.6",
113
113
  "@neondatabase/serverless": "1.2.0",
114
- "@sentry-internal/rollup-utils": "11.15.0",
114
+ "@sentry-internal/rollup-utils": "11.16.0",
115
115
  "@types/node": "^20.19.0",
116
116
  "meriyah": "^6.1.4",
117
117
  "vite": "^8.3.6",