@sentry/server-utils 11.21.0 → 11.23.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.
- package/build/THIRD-PARTY-LICENSES.txt +10 -10
- package/build/cjs/chunks/config.js +4 -2
- package/build/cjs/chunks/config.js.map +1 -1
- package/build/cjs/chunks/core.js +0 -1
- package/build/cjs/chunks/exports.js +76 -28
- package/build/cjs/chunks/exports.js.map +1 -1
- package/build/cjs/chunks/module-details-from-path.js +427 -428
- package/build/cjs/chunks/module-details-from-path.js.map +1 -1
- package/build/cjs/chunks/moduleInjectedTransform.js +419 -421
- package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
- package/build/cjs/chunks/rolldown-runtime.js +8 -6
- package/build/cjs/index.js +95 -41
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/index.request-handler.js +2 -2
- package/build/cjs/orchestrion/bundler/bun.js +1 -1
- package/build/cjs/orchestrion/bundler/esbuild.js +1 -1
- package/build/cjs/orchestrion/bundler/rollup.js +1 -1
- package/build/cjs/orchestrion/bundler/vite.js +2 -2
- package/build/cjs/orchestrion/bundler/webpack-loader.js +2 -2
- package/build/cjs/orchestrion/bundler/webpack.js +4 -4
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/defineProperty.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/assertClassBrand.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/checkPrivateRedeclaration.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldGet2.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldInitSpec.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateFieldSet2.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/classPrivateMethodInitSpec.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/defineProperty.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPrimitive.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/toPropertyKey.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/esm/typeof.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPrimitive.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/toPropertyKey.js +1 -1
- package/build/esm/_virtual/{_@oxc-project_runtime@0.158.0 → _@oxc-project_runtime@0.160.0}/helpers/typeof.js +1 -1
- package/build/esm/_virtual/_rolldown/runtime.js +8 -6
- package/build/esm/ai/anthropic-ai/index.js +2 -2
- package/build/esm/ai/anthropic-ai/streaming.js +11 -2
- package/build/esm/ai/anthropic-ai/streaming.js.map +1 -1
- package/build/esm/ai/anthropic-ai/tool-runner.js +3 -3
- package/build/esm/ai/anthropic-ai/utils.js +2 -2
- package/build/esm/ai/core/span-hooks.js +1 -1
- package/build/esm/ai/core/time-to-first-chunk.js +1 -1
- package/build/esm/ai/core/utils.js +2 -2
- package/build/esm/ai/flue/index.js +2 -2
- package/build/esm/ai/flue/utils.js +2 -2
- package/build/esm/ai/google-genai/decisions.js +1 -1
- package/build/esm/ai/google-genai/index.js +2 -2
- package/build/esm/ai/google-genai/streaming.js +9 -2
- package/build/esm/ai/google-genai/streaming.js.map +1 -1
- package/build/esm/ai/google-genai/utils.js +1 -1
- package/build/esm/ai/langchain/embeddings.js +3 -3
- package/build/esm/ai/langchain/index.js +15 -9
- package/build/esm/ai/langchain/index.js.map +1 -1
- package/build/esm/ai/langchain/typesafe-classifier.js +2 -2
- package/build/esm/ai/langchain/utils.js +3 -4
- package/build/esm/ai/langchain/utils.js.map +1 -1
- package/build/esm/ai/langgraph/agent-span.js +3 -3
- package/build/esm/ai/langgraph/index.js +1 -1
- package/build/esm/ai/langgraph/stream.js +2 -2
- package/build/esm/ai/langgraph/utils.js +3 -3
- package/build/esm/ai/mastra/index.js +2 -2
- package/build/esm/ai/mastra/span-registry.js +1 -1
- package/build/esm/ai/mastra/utils.js +2 -2
- package/build/esm/ai/mistral/index.js +2 -2
- package/build/esm/ai/mistral/streaming.js +18 -9
- package/build/esm/ai/mistral/streaming.js.map +1 -1
- package/build/esm/ai/openai/index.js +2 -2
- package/build/esm/ai/openai/mapping.js +1 -1
- package/build/esm/ai/openai/streaming.js +15 -2
- package/build/esm/ai/openai/streaming.js.map +1 -1
- package/build/esm/ai/openai/utils.js +2 -2
- package/build/esm/ai/pi-ai/chat.js +12 -4
- package/build/esm/ai/pi-ai/chat.js.map +1 -1
- package/build/esm/ai/pi-ai/providers.js +1 -1
- package/build/esm/ai/pi-ai/recording.js +1 -1
- package/build/esm/ai/pi-durable/index.js +2 -2
- package/build/esm/ai/pi-durable/runs.js +3 -3
- package/build/esm/ai/pi-durable/tools.js +3 -3
- package/build/esm/ai/tanstack-ai/index.js +2 -2
- package/build/esm/ai/tanstack-ai/utils.js +2 -2
- package/build/esm/ai/typesafe/index.js +3 -3
- package/build/esm/ai/workers-ai/index.js +2 -2
- package/build/esm/ai/workers-ai/streaming.js +7 -5
- package/build/esm/ai/workers-ai/streaming.js.map +1 -1
- package/build/esm/ai/workers-ai/utils.js +7 -4
- package/build/esm/ai/workers-ai/utils.js.map +1 -1
- package/build/esm/async-context.js +1 -1
- package/build/esm/cron/common.js +1 -1
- package/build/esm/cron/cron.js +1 -1
- package/build/esm/cron/node-cron.js +1 -1
- package/build/esm/cron/node-schedule.js +1 -1
- package/build/esm/eve.js +1 -1
- package/build/esm/integrations/amqplib.js +3 -3
- package/build/esm/integrations/anthropic.js +3 -4
- package/build/esm/integrations/anthropic.js.map +1 -1
- package/build/esm/integrations/aws-sdk/index.js +3 -3
- package/build/esm/integrations/aws-sdk/services/MessageAttributes.js +1 -1
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime-content.js +2 -2
- package/build/esm/integrations/aws-sdk/services/bedrock-runtime.js +3 -3
- package/build/esm/integrations/aws-sdk/services/dynamodb.js +1 -1
- package/build/esm/integrations/aws-sdk/services/lambda.js +2 -2
- package/build/esm/integrations/aws-sdk/services/sns.js +3 -3
- package/build/esm/integrations/aws-sdk/services/sqs.js +2 -2
- package/build/esm/integrations/bullmq/meter.js +2 -2
- package/build/esm/integrations/bullmq/tracer.js +2 -2
- package/build/esm/integrations/clickhouse.js +3 -3
- package/build/esm/integrations/cron.js +1 -1
- package/build/esm/integrations/dataloader.js +3 -3
- package/build/esm/integrations/express/error-handler.js +1 -1
- package/build/esm/integrations/express/index.js +1 -1
- package/build/esm/integrations/express/instrumentation.js +3 -3
- package/build/esm/integrations/fastify/errors.js +1 -1
- package/build/esm/integrations/fastify/index.js +1 -1
- package/build/esm/integrations/fastify/instrumentation.js +8 -4
- package/build/esm/integrations/fastify/instrumentation.js.map +1 -1
- package/build/esm/integrations/firebase/firestore.js +2 -2
- package/build/esm/integrations/firebase/functions.js +1 -1
- package/build/esm/integrations/firebase/index.js +1 -1
- package/build/esm/integrations/flue.js +1 -1
- package/build/esm/integrations/generic-pool.js +3 -3
- package/build/esm/integrations/google-genai.js +2 -2
- package/build/esm/integrations/graphql/graphql-dc-subscriber.js +3 -3
- package/build/esm/integrations/graphql/index.js +1 -1
- package/build/esm/integrations/graphql/resolvers.js +2 -2
- package/build/esm/integrations/graphql/spans.js +3 -3
- package/build/esm/integrations/groq.js +1 -1
- package/build/esm/integrations/hapi/hapi-error-handler.js +1 -1
- package/build/esm/integrations/hapi/hapi-utils.js +4 -5
- package/build/esm/integrations/hapi/hapi-utils.js.map +1 -1
- package/build/esm/integrations/hapi/index.js +1 -1
- package/build/esm/integrations/hono/applyPatches.js +1 -1
- package/build/esm/integrations/hono/createHonoMiddleware.js +1 -1
- package/build/esm/integrations/hono/honoIntegration.js +3 -3
- package/build/esm/integrations/hono/matchResult.js +1 -1
- package/build/esm/integrations/hono/middlewareHandlers.js +2 -2
- package/build/esm/integrations/hono/patchAppRequest.js +3 -3
- package/build/esm/integrations/hono/patchAppUse.js +1 -1
- package/build/esm/integrations/hono/patchRoute.js +1 -1
- package/build/esm/integrations/hono/wrapMiddlewareSpan.js +3 -3
- package/build/esm/integrations/kafkajs/consumer.js +2 -2
- package/build/esm/integrations/kafkajs/index.js +1 -1
- package/build/esm/integrations/kafkajs/spans.js +2 -2
- package/build/esm/integrations/knex.js +3 -3
- package/build/esm/integrations/koa/index.js +3 -3
- package/build/esm/integrations/langchain.js +1 -1
- package/build/esm/integrations/langgraph.js +1 -1
- package/build/esm/integrations/lru-memoizer.js +1 -1
- package/build/esm/integrations/mastra-classifier.js +2 -2
- package/build/esm/integrations/mastra.js +4 -4
- package/build/esm/integrations/mcp-server.js +2 -2
- package/build/esm/integrations/mistral.js +2 -2
- package/build/esm/integrations/mongodb/index.js +1 -1
- package/build/esm/integrations/mongodb/mongodb-span.js +1 -1
- package/build/esm/integrations/mongoose/index.js +1 -1
- package/build/esm/integrations/mongoose/mongoose-dc-subscriber.js +3 -3
- package/build/esm/integrations/mongoose/mongoose-legacy-span.js +1 -1
- package/build/esm/integrations/mysql.js +3 -3
- package/build/esm/integrations/mysql2/index.js +1 -1
- package/build/esm/integrations/mysql2/mysql2-dc-subscriber.js +3 -3
- package/build/esm/integrations/neon.js +13 -5
- package/build/esm/integrations/neon.js.map +1 -1
- package/build/esm/integrations/nitro/captureStorageEvents.js +3 -3
- package/build/esm/integrations/nitro/captureTracingEvents.js +3 -3
- package/build/esm/integrations/nitro/index.js +1 -1
- package/build/esm/integrations/nitro/setServerTimingHeaders.js +1 -1
- package/build/esm/integrations/node-cron.js +1 -1
- package/build/esm/integrations/node-schedule.js +1 -1
- package/build/esm/integrations/openai-compatible.js +2 -2
- package/build/esm/integrations/openai.js +2 -2
- package/build/esm/integrations/pg.js +43 -16
- package/build/esm/integrations/pg.js.map +1 -1
- package/build/esm/integrations/pi-ai.js +1 -1
- package/build/esm/integrations/pi-durable.js +1 -1
- package/build/esm/integrations/pino.js +1 -1
- package/build/esm/integrations/pino.js.map +1 -1
- package/build/esm/integrations/postgresjs/index.js +3 -3
- package/build/esm/integrations/postgresjs/postgresjs-dc-subscriber.js +3 -3
- package/build/esm/integrations/postgresjs-wrapper.js +1 -1
- package/build/esm/integrations/prisma/index.js +1 -1
- package/build/esm/integrations/prisma/orchestrion.js +8 -12
- package/build/esm/integrations/prisma/orchestrion.js.map +1 -1
- package/build/esm/integrations/prisma/tracing-helper.js +2 -2
- package/build/esm/integrations/redis/index.js +3 -3
- package/build/esm/integrations/redis/ioredis-channel-subscriber.js +3 -3
- package/build/esm/integrations/redis/redis-cache.js +1 -1
- package/build/esm/integrations/redis/redis-dc-subscriber.js +3 -3
- package/build/esm/integrations/serveTunnel.js +2 -2
- package/build/esm/integrations/tanstack-ai.js +1 -1
- package/build/esm/integrations/tedious.js +4 -4
- package/build/esm/integrations/together-ai.js +1 -1
- package/build/esm/integrations/typesafe.js +1 -1
- package/build/esm/integrations/vercel-ai/extract.js +2 -3
- package/build/esm/integrations/vercel-ai/extract.js.map +1 -1
- package/build/esm/integrations/vercel-ai/index.js +1 -1
- package/build/esm/integrations/vercel-ai/util.js +21 -2
- package/build/esm/integrations/vercel-ai/util.js.map +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +3 -3
- package/build/esm/integrations/vercel-ai/vercel-ai-orchestrion-subscriber.js +1 -1
- package/build/esm/integrations/vercel-ai/vercel-ai-tool-telemetry.js +3 -3
- package/build/esm/integrations/winston.js +1 -1
- package/build/esm/opentelemetry.js +1 -1
- package/build/esm/orchestrion/bundler/esbuild.js +1 -1
- package/build/esm/orchestrion/bundler/externalRequire.js +1 -1
- package/build/esm/orchestrion/bundler/rollup.js +1 -1
- package/build/esm/orchestrion/bundler/webpack-loader.js +1 -1
- package/build/esm/orchestrion/bundler/webpack.js +1 -1
- package/build/esm/orchestrion/config/index.js +1 -1
- package/build/esm/orchestrion/config/mistral.js +1 -1
- package/build/esm/orchestrion/config/mistral.js.map +1 -1
- package/build/esm/orchestrion/config/prisma.js +2 -0
- package/build/esm/orchestrion/config/prisma.js.map +1 -1
- package/build/esm/orchestrion/detect.js +1 -1
- package/build/esm/orchestrion/instrumentation.js +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tracing-channel.js +1 -2
- package/build/esm/tracing-channel.js.map +1 -1
- package/build/esm/utils/cronMonitoring.js +1 -1
- package/build/esm/utils/diagnosticsChannel.js +1 -1
- package/build/esm/utils/module.js +2 -2
- package/build/esm/utils/module.js.map +1 -1
- package/build/esm/utils/monitorStream.js +1 -1
- package/build/esm/utils/serverTimingTraceHeader.js +1 -1
- package/build/esm/utils/tunnelServer.js +1 -1
- package/build/esm/utils/wrapServerRequestHandler.js +4 -4
- package/build/esm/vendored/@apm-js-collab/code-transformer/lib/matcher.js +3 -3
- package/build/esm/vendored/@apm-js-collab/code-transformer/lib/transformer.js +5 -5
- package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/core-BiWIBBjf.js +1 -1
- package/build/esm/vendored/@apm-js-collab/code-transformer-bundler-plugins/dist/esm/webpack-loader-factory.js +1 -1
- package/build/esm/vendored/esquery/dist/esquery.min.js +1 -0
- package/build/esm/vendored/esquery/dist/esquery.min.js.map +1 -1
- package/build/esm/vendored/meriyah/dist/meriyah.js +416 -418
- package/build/esm/vendored/meriyah/dist/meriyah.js.map +1 -1
- package/build/esm/vendored/meriyah/dist/meriyah2.js +416 -418
- package/build/esm/vendored/meriyah/dist/meriyah2.js.map +1 -1
- package/build/esm/vendored/source-map/lib/base64-vlq.js +1 -1
- package/build/esm/vendored/source-map/lib/base64-vlq.js.map +1 -1
- package/build/types/ai/anthropic-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/anthropic-ai/types.d.ts +1 -0
- package/build/types/ai/anthropic-ai/types.d.ts.map +1 -1
- package/build/types/ai/google-genai/streaming.d.ts.map +1 -1
- package/build/types/ai/langchain/index.d.ts.map +1 -1
- package/build/types/ai/mistral/streaming.d.ts.map +1 -1
- package/build/types/ai/openai/streaming.d.ts.map +1 -1
- package/build/types/ai/pi-ai/chat.d.ts.map +1 -1
- package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
- package/build/types/ai/workers-ai/utils.d.ts.map +1 -1
- package/build/types/integrations/fastify/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/neon.d.ts.map +1 -1
- package/build/types/integrations/pg.d.ts +6 -1
- package/build/types/integrations/pg.d.ts.map +1 -1
- package/build/types/integrations/pino.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/extract.d.ts +2 -5
- package/build/types/integrations/vercel-ai/extract.d.ts.map +1 -1
- package/build/types/integrations/vercel-ai/util.d.ts.map +1 -1
- package/build/types/orchestrion/channels.d.ts +1 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/mistral.d.ts +3 -3
- package/build/types/orchestrion/config/prisma.d.ts +2 -1
- package/build/types/orchestrion/config/prisma.d.ts.map +1 -1
- package/build/types/tracing-channel.d.ts.map +1 -1
- package/package.json +4 -4
package/build/cjs/chunks/core.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const require_debug_build = require("./debug-build.js");
|
|
2
|
-
const require_pi_ai = require("./pi-ai.js");
|
|
3
1
|
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
|
|
4
2
|
let _sentry_core = require("@sentry/core");
|
|
5
3
|
let node_async_hooks = require("node:async_hooks");
|
|
6
4
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
5
|
+
const require_debug_build = require("./debug-build.js");
|
|
7
6
|
let _sentry_conventions_op = require("@sentry/conventions/op");
|
|
7
|
+
const require_pi_ai = require("./pi-ai.js");
|
|
8
8
|
let _sentry_core_server = require("@sentry/core/server");
|
|
9
9
|
// src/utils/setHttpServerSpanRouteAttribute.ts
|
|
10
10
|
/**
|
|
@@ -869,6 +869,19 @@ function processResponsesApiEvent(streamEvent, state, recordOutputs, span) {
|
|
|
869
869
|
}
|
|
870
870
|
}
|
|
871
871
|
/**
|
|
872
|
+
* Whether an event carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
873
|
+
* Role-only, usage-only, finish and lifecycle (`response.created`, ...) events do not.
|
|
874
|
+
*/
|
|
875
|
+
function hasOutput$4(event) {
|
|
876
|
+
if (isChatCompletionChunk(event)) return (event.choices ?? []).some(({ delta }) => !!(delta?.content || delta?.refusal || delta?.tool_calls?.length || delta?.function_call));
|
|
877
|
+
if (isResponsesApiStreamEvent(event)) {
|
|
878
|
+
const { type } = event;
|
|
879
|
+
if (type.endsWith(".delta")) return !!event.delta;
|
|
880
|
+
return type === "response.output_item.added" && event.item?.type === "function_call";
|
|
881
|
+
}
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
872
885
|
* Instruments a stream of OpenAI events, updating the provided span with relevant attributes and
|
|
873
886
|
* optionally recording output text. This function yields each event from the input stream as it is processed.
|
|
874
887
|
*
|
|
@@ -897,7 +910,7 @@ async function* instrumentStream$1(stream, span, recordOutputs, beforeSpanEnd) {
|
|
|
897
910
|
const result = {};
|
|
898
911
|
try {
|
|
899
912
|
for await (const event of stream) {
|
|
900
|
-
recordTimeToFirstChunk(span);
|
|
913
|
+
if (hasOutput$4(event)) recordTimeToFirstChunk(span);
|
|
901
914
|
if (isChatCompletionChunk(event)) processChatCompletionChunk(event, state, recordOutputs);
|
|
902
915
|
else if (isResponsesApiStreamEvent(event)) processResponsesApiEvent(event, state, recordOutputs, span);
|
|
903
916
|
yield event;
|
|
@@ -1302,6 +1315,15 @@ function handleContentBlockStop(event, state) {
|
|
|
1302
1315
|
delete state.activeToolBlocks[event.index];
|
|
1303
1316
|
}
|
|
1304
1317
|
/**
|
|
1318
|
+
* Whether an event carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
1319
|
+
* `message_start`, `ping`, empty block starts, signatures and stop events do not.
|
|
1320
|
+
*/
|
|
1321
|
+
function hasOutput$3(event) {
|
|
1322
|
+
if (event.type === "content_block_start") return !!(event.content_block?.name || event.content_block?.type === "redacted_thinking");
|
|
1323
|
+
if (event.type === "content_block_delta") return !!(event.delta?.text || event.delta?.partial_json || event.delta?.thinking);
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1305
1327
|
* Processes an event
|
|
1306
1328
|
* @param event - The event to process
|
|
1307
1329
|
* @param state - The state of the streaming process
|
|
@@ -1311,7 +1333,7 @@ function handleContentBlockStop(event, state) {
|
|
|
1311
1333
|
function processEvent$1(event, state, recordOutputs, span) {
|
|
1312
1334
|
if (!(event && typeof event === "object")) return;
|
|
1313
1335
|
if (isErrorEvent(event, span)) return;
|
|
1314
|
-
recordTimeToFirstChunk(span);
|
|
1336
|
+
if (hasOutput$3(event)) recordTimeToFirstChunk(span);
|
|
1315
1337
|
handleMessageMetadata(event, state);
|
|
1316
1338
|
handleContentBlockStart(event, state);
|
|
1317
1339
|
handleContentBlockDelta(event, state, recordOutputs);
|
|
@@ -1958,6 +1980,13 @@ function handleCandidateContent(chunk, state, recordOutputs) {
|
|
|
1958
1980
|
}
|
|
1959
1981
|
}
|
|
1960
1982
|
/**
|
|
1983
|
+
* Whether a chunk carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
1984
|
+
* Chunks with only usage, a finish reason or a thought signature do not.
|
|
1985
|
+
*/
|
|
1986
|
+
function hasOutput$2(chunk) {
|
|
1987
|
+
return (chunk.candidates ?? []).some((candidate) => (candidate?.content?.parts ?? []).some((part) => !!(part.text || part.functionCall || part.inlineData)));
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1961
1990
|
* Processes a single chunk from the Google GenAI stream
|
|
1962
1991
|
* @param chunk - The chunk to process
|
|
1963
1992
|
* @param state - The state of the streaming process
|
|
@@ -1966,7 +1995,7 @@ function handleCandidateContent(chunk, state, recordOutputs) {
|
|
|
1966
1995
|
*/
|
|
1967
1996
|
function processChunk$1(chunk, state, recordOutputs, span) {
|
|
1968
1997
|
if (!chunk || isErrorChunk(chunk, span)) return;
|
|
1969
|
-
recordTimeToFirstChunk(span);
|
|
1998
|
+
if (hasOutput$2(chunk)) recordTimeToFirstChunk(span);
|
|
1970
1999
|
handleResponseMetadata(chunk, state);
|
|
1971
2000
|
handleCandidateContent(chunk, state, recordOutputs);
|
|
1972
2001
|
}
|
|
@@ -2419,15 +2448,25 @@ function processChunk(chunk, state, recordOutputs) {
|
|
|
2419
2448
|
if (choice.finishReason) state.finishReasons.push(choice.finishReason);
|
|
2420
2449
|
}
|
|
2421
2450
|
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Whether a chunk carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
2453
|
+
* Role-only, usage-only and finish chunks do not.
|
|
2454
|
+
*/
|
|
2455
|
+
function hasOutput$1(chunk) {
|
|
2456
|
+
return (chunk.choices ?? []).some(({ delta }) => !!(contentToString(delta?.content) || delta?.toolCalls?.length));
|
|
2457
|
+
}
|
|
2422
2458
|
/** Mistral yields `CompletionEvent` objects that wrap the chunk under `data`. */
|
|
2423
|
-
function processEvent(event, state, recordOutputs) {
|
|
2459
|
+
function processEvent(event, state, recordOutputs, span) {
|
|
2424
2460
|
const chunk = event?.data;
|
|
2425
|
-
if (chunk && typeof chunk === "object")
|
|
2461
|
+
if (chunk && typeof chunk === "object") {
|
|
2462
|
+
if (hasOutput$1(chunk)) recordTimeToFirstChunk(span);
|
|
2463
|
+
processChunk(chunk, state, recordOutputs);
|
|
2464
|
+
}
|
|
2426
2465
|
}
|
|
2427
|
-
async function* instrumentIterator(iterate, state, recordOutputs, claim, settle) {
|
|
2466
|
+
async function* instrumentIterator(iterate, state, recordOutputs, span, claim, settle) {
|
|
2428
2467
|
try {
|
|
2429
2468
|
for await (const event of { [Symbol.asyncIterator]: iterate }) {
|
|
2430
|
-
if (claim("iterator")) processEvent(event, state, recordOutputs);
|
|
2469
|
+
if (claim("iterator")) processEvent(event, state, recordOutputs, span);
|
|
2431
2470
|
yield event;
|
|
2432
2471
|
}
|
|
2433
2472
|
} catch (error) {
|
|
@@ -2437,7 +2476,7 @@ async function* instrumentIterator(iterate, state, recordOutputs, claim, settle)
|
|
|
2437
2476
|
settle();
|
|
2438
2477
|
}
|
|
2439
2478
|
}
|
|
2440
|
-
function wrapReader(reader, state, recordOutputs, claim, settle, markCancelled) {
|
|
2479
|
+
function wrapReader(reader, state, recordOutputs, span, claim, settle, markCancelled) {
|
|
2441
2480
|
const originalRead = reader.read;
|
|
2442
2481
|
const originalCancel = reader.cancel;
|
|
2443
2482
|
const read = () => originalRead.call(reader);
|
|
@@ -2447,7 +2486,7 @@ function wrapReader(reader, state, recordOutputs, claim, settle, markCancelled)
|
|
|
2447
2486
|
try {
|
|
2448
2487
|
const result = await read();
|
|
2449
2488
|
if (result.done) settle();
|
|
2450
|
-
else if (claim("reader")) processEvent(result.value, state, recordOutputs);
|
|
2489
|
+
else if (claim("reader")) processEvent(result.value, state, recordOutputs, span);
|
|
2451
2490
|
return result;
|
|
2452
2491
|
} catch (error) {
|
|
2453
2492
|
settle(error);
|
|
@@ -2517,7 +2556,6 @@ function instrumentEventStream(stream, span, recordOutputs, abortSignal, beforeS
|
|
|
2517
2556
|
let settled = false;
|
|
2518
2557
|
let cancelled = false;
|
|
2519
2558
|
const claim = (candidate) => {
|
|
2520
|
-
recordTimeToFirstChunk(span);
|
|
2521
2559
|
consumer ?? (consumer = candidate);
|
|
2522
2560
|
return consumer === candidate;
|
|
2523
2561
|
};
|
|
@@ -2539,12 +2577,12 @@ function instrumentEventStream(stream, span, recordOutputs, abortSignal, beforeS
|
|
|
2539
2577
|
toolCalls
|
|
2540
2578
|
}, recordOutputs, () => beforeSpanEnd?.(error !== void 0 && !cancelled ? { error } : {}));
|
|
2541
2579
|
};
|
|
2542
|
-
const instrumented = instrumentIterator(stream[Symbol.asyncIterator].bind(stream), state, recordOutputs, claim, settle);
|
|
2580
|
+
const instrumented = instrumentIterator(stream[Symbol.asyncIterator].bind(stream), state, recordOutputs, span, claim, settle);
|
|
2543
2581
|
stream[Symbol.asyncIterator] = () => instrumented;
|
|
2544
2582
|
const readable = stream;
|
|
2545
2583
|
if (typeof readable.getReader === "function") {
|
|
2546
2584
|
const getReader = readable.getReader.bind(readable);
|
|
2547
|
-
readable.getReader = (...args) => wrapReader(getReader(...args), state, recordOutputs, claim, settle, markCancelled);
|
|
2585
|
+
readable.getReader = (...args) => wrapReader(getReader(...args), state, recordOutputs, span, claim, settle, markCancelled);
|
|
2548
2586
|
}
|
|
2549
2587
|
if (typeof readable.cancel === "function") {
|
|
2550
2588
|
const cancel = readable.cancel.bind(readable);
|
|
@@ -2890,7 +2928,10 @@ function addRequestAttributes(span, inputs, operationName) {
|
|
|
2890
2928
|
}
|
|
2891
2929
|
if (operationName === "extract") {
|
|
2892
2930
|
const { model: _model, ...request } = inputs;
|
|
2893
|
-
|
|
2931
|
+
for (const key of ["images", "documents"]) {
|
|
2932
|
+
const blobs = request[key];
|
|
2933
|
+
if (Array.isArray(blobs)) request[key] = blobs.map(() => BLOB_SUBSTITUTE);
|
|
2934
|
+
}
|
|
2894
2935
|
span.setAttribute(_sentry_conventions_attributes.GEN_AI_INPUT_MESSAGES, (0, _sentry_core.stringify)([request]));
|
|
2895
2936
|
return;
|
|
2896
2937
|
}
|
|
@@ -2995,17 +3036,19 @@ function accumulateStreamingToolCalls(toolCalls, accumulator) {
|
|
|
2995
3036
|
* Handles both the native Workers AI shape (top-level `response`/`tool_calls`) and the
|
|
2996
3037
|
* OpenAI-compatible shape (`choices[].delta.content`/`choices[].delta.tool_calls`), because
|
|
2997
3038
|
* the same `run()` call transparently yields either format depending on the model.
|
|
3039
|
+
*
|
|
3040
|
+
* Returns whether the line carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
2998
3041
|
*/
|
|
2999
3042
|
function processLine(line, state, recordOutputs, toolCallAccumulator) {
|
|
3000
3043
|
const trimmed = line.trim();
|
|
3001
|
-
if (!trimmed.startsWith("data:")) return;
|
|
3044
|
+
if (!trimmed.startsWith("data:")) return false;
|
|
3002
3045
|
const data = trimmed.slice(5).trim();
|
|
3003
|
-
if (!data || data === "[DONE]") return;
|
|
3046
|
+
if (!data || data === "[DONE]") return false;
|
|
3004
3047
|
let parsed;
|
|
3005
3048
|
try {
|
|
3006
3049
|
parsed = JSON.parse(data);
|
|
3007
3050
|
} catch {
|
|
3008
|
-
return;
|
|
3051
|
+
return false;
|
|
3009
3052
|
}
|
|
3010
3053
|
if (parsed.usage) {
|
|
3011
3054
|
if (typeof parsed.usage.prompt_tokens === "number") state.promptTokens = parsed.usage.prompt_tokens;
|
|
@@ -3023,6 +3066,7 @@ function processLine(line, state, recordOutputs, toolCallAccumulator) {
|
|
|
3023
3066
|
if (typeof choice.finish_reason === "string") state.finishReasons.push(choice.finish_reason);
|
|
3024
3067
|
}
|
|
3025
3068
|
}
|
|
3069
|
+
return !!(typeof parsed.response === "string" && parsed.response || Array.isArray(parsed.tool_calls) && parsed.tool_calls.length || parsed.choices?.some(({ delta }) => typeof delta?.content === "string" && delta.content || delta?.tool_calls?.length));
|
|
3026
3070
|
}
|
|
3027
3071
|
/**
|
|
3028
3072
|
* Wrap a Workers AI streaming response (a server-sent-events `ReadableStream`) so we can
|
|
@@ -3066,7 +3110,7 @@ function instrumentWorkersAiStream(stream, span, recordOutputs, abortSignal, bef
|
|
|
3066
3110
|
const flushBuffer = (isDone) => {
|
|
3067
3111
|
const lines = buffer.split("\n");
|
|
3068
3112
|
buffer = isDone ? "" : lines.pop() ?? "";
|
|
3069
|
-
for (const line of lines) processLine(line, state, recordOutputs, toolCallAccumulator);
|
|
3113
|
+
for (const line of lines) if (processLine(line, state, recordOutputs, toolCallAccumulator)) recordTimeToFirstChunk(span);
|
|
3070
3114
|
};
|
|
3071
3115
|
return new ReadableStream({
|
|
3072
3116
|
async pull(controller) {
|
|
@@ -3079,7 +3123,6 @@ function instrumentWorkersAiStream(stream, span, recordOutputs, abortSignal, bef
|
|
|
3079
3123
|
controller.close();
|
|
3080
3124
|
return;
|
|
3081
3125
|
}
|
|
3082
|
-
recordTimeToFirstChunk(span);
|
|
3083
3126
|
buffer += decoder.decode(value, { stream: true });
|
|
3084
3127
|
flushBuffer(false);
|
|
3085
3128
|
controller.enqueue(value);
|
|
@@ -3350,8 +3393,7 @@ function baseRequestAttributes(system, modelName, serialized, invocationParams,
|
|
|
3350
3393
|
* messages to align with the chat schema used elsewhere.
|
|
3351
3394
|
*/
|
|
3352
3395
|
function extractLLMRequestAttributes(llm, prompts, recordInputs, invocationParams, langSmithMetadata) {
|
|
3353
|
-
const
|
|
3354
|
-
const attrs = baseRequestAttributes(system, invocationParams?.model ?? langSmithMetadata?.ls_model_name ?? "unknown", llm, invocationParams, langSmithMetadata);
|
|
3396
|
+
const attrs = baseRequestAttributes(langSmithMetadata?.ls_provider, invocationParams?.model ?? langSmithMetadata?.ls_model_name ?? "unknown", llm, invocationParams, langSmithMetadata);
|
|
3355
3397
|
if (recordInputs && Array.isArray(prompts) && prompts.length > 0) {
|
|
3356
3398
|
const messages = prompts.map((p) => ({
|
|
3357
3399
|
role: "user",
|
|
@@ -3724,6 +3766,14 @@ function instrumentLangChainEmbeddings(instance, options) {
|
|
|
3724
3766
|
}
|
|
3725
3767
|
// src/ai/langchain/index.ts
|
|
3726
3768
|
/**
|
|
3769
|
+
* Whether a streamed token carries new model output, which is what `gen_ai.response.time_to_first_chunk` measures.
|
|
3770
|
+
* Chat models report tool-call chunks with an empty token.
|
|
3771
|
+
*/
|
|
3772
|
+
function hasOutput(token, fields) {
|
|
3773
|
+
const toolCallChunks = fields?.chunk?.message?.tool_call_chunks;
|
|
3774
|
+
return !!(token || toolCallChunks?.length);
|
|
3775
|
+
}
|
|
3776
|
+
/**
|
|
3727
3777
|
* Creates a Sentry callback handler for LangChain
|
|
3728
3778
|
* Returns a plain object that LangChain will call via duck-typing
|
|
3729
3779
|
*
|
|
@@ -3761,10 +3811,8 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3761
3811
|
return ancestors;
|
|
3762
3812
|
};
|
|
3763
3813
|
const getParentRunSpan = (ancestors, activeSpan) => {
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
if (!(0, _sentry_core.spanIsIgnored)(run.span) || (0, _sentry_core.getRootSpan)(run.span) === run.span) return run.span;
|
|
3767
|
-
}
|
|
3814
|
+
const [run] = ancestors;
|
|
3815
|
+
return run && run.activeSpan === activeSpan ? run.span : void 0;
|
|
3768
3816
|
};
|
|
3769
3817
|
const startRunSpan = (call, recordOutputs, start) => {
|
|
3770
3818
|
const { runId, parentRunId } = call;
|
|
@@ -3877,9 +3925,9 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3877
3925
|
}
|
|
3878
3926
|
}));
|
|
3879
3927
|
},
|
|
3880
|
-
handleLLMNewToken(
|
|
3928
|
+
handleLLMNewToken(token, _idx, runId, _parentRunId, _tags, fields) {
|
|
3881
3929
|
const span = runs.get(runId)?.span;
|
|
3882
|
-
if (span) recordTimeToFirstChunk(span);
|
|
3930
|
+
if (span && hasOutput(token, fields)) recordTimeToFirstChunk(span);
|
|
3883
3931
|
},
|
|
3884
3932
|
handleLLMEnd(output, runId, _parentRunId, _tags, _extraParams) {
|
|
3885
3933
|
const run = runs.get(runId);
|