@sentry/server-utils 11.15.0 → 11.17.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/cjs/chunks/config.js +60 -0
- package/build/cjs/chunks/config.js.map +1 -1
- package/build/cjs/chunks/exports.js +194 -58
- package/build/cjs/chunks/exports.js.map +1 -1
- package/build/cjs/chunks/moduleInjectedTransform.js +8 -0
- package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
- package/build/cjs/index.js +299 -168
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/index.request-handler.js +1 -0
- package/build/cjs/index.request-handler.js.map +1 -1
- package/build/esm/ai/flue/utils.js +1 -0
- package/build/esm/ai/flue/utils.js.map +1 -1
- package/build/esm/ai/google-genai/decisions.js +29 -1
- package/build/esm/ai/google-genai/decisions.js.map +1 -1
- package/build/esm/ai/langchain/embeddings.js +23 -8
- package/build/esm/ai/langchain/embeddings.js.map +1 -1
- package/build/esm/ai/langchain/index.js +41 -30
- package/build/esm/ai/langchain/index.js.map +1 -1
- package/build/esm/ai/langgraph/agent-span.js +6 -2
- package/build/esm/ai/langgraph/agent-span.js.map +1 -1
- package/build/esm/ai/langgraph/index.js +5 -1
- package/build/esm/ai/langgraph/index.js.map +1 -1
- package/build/esm/ai/langgraph/stream.js +4 -1
- package/build/esm/ai/langgraph/stream.js.map +1 -1
- package/build/esm/ai/openai/mapping.js +48 -1
- package/build/esm/ai/openai/mapping.js.map +1 -1
- package/build/esm/ai/pi-durable/index.js +10 -13
- package/build/esm/ai/pi-durable/index.js.map +1 -1
- package/build/esm/ai/pi-durable/runs.js +6 -5
- package/build/esm/ai/pi-durable/runs.js.map +1 -1
- package/build/esm/ai/pi-durable/tools.js +21 -17
- package/build/esm/ai/pi-durable/tools.js.map +1 -1
- package/build/esm/index.js +3 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/clickhouse-sql.js +31 -0
- package/build/esm/integrations/clickhouse-sql.js.map +1 -0
- package/build/esm/integrations/clickhouse.js +88 -0
- package/build/esm/integrations/clickhouse.js.map +1 -0
- package/build/esm/integrations/express/instrumentation.js +1 -0
- package/build/esm/integrations/express/instrumentation.js.map +1 -1
- package/build/esm/integrations/fastify/instrumentation.js +3 -1
- package/build/esm/integrations/fastify/instrumentation.js.map +1 -1
- package/build/esm/integrations/hapi/index.js +15 -1
- package/build/esm/integrations/hapi/index.js.map +1 -1
- package/build/esm/integrations/index.js +2 -0
- package/build/esm/integrations/index.js.map +1 -1
- package/build/esm/integrations/langchain.js +10 -3
- package/build/esm/integrations/langchain.js.map +1 -1
- package/build/esm/orchestrion/channels.js +2 -0
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config/channel-integration-definitions.js +8 -0
- package/build/esm/orchestrion/config/channel-integration-definitions.js.map +1 -1
- package/build/esm/orchestrion/config/clickhouse.js +51 -0
- package/build/esm/orchestrion/config/clickhouse.js.map +1 -0
- package/build/esm/orchestrion/config/index.js +2 -0
- package/build/esm/orchestrion/config/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/utils/sql.js +37 -16
- package/build/esm/utils/sql.js.map +1 -1
- package/build/esm/utils/wrapServerRequestHandler.js +2 -1
- package/build/esm/utils/wrapServerRequestHandler.js.map +1 -1
- package/build/types/ai/flue/utils.d.ts.map +1 -1
- package/build/types/ai/google-genai/decisions.d.ts.map +1 -1
- package/build/types/ai/langchain/embeddings.d.ts +2 -2
- package/build/types/ai/langchain/embeddings.d.ts.map +1 -1
- package/build/types/ai/langchain/index.d.ts.map +1 -1
- package/build/types/ai/langchain/types.d.ts +8 -4
- package/build/types/ai/langchain/types.d.ts.map +1 -1
- package/build/types/ai/langgraph/agent-span.d.ts +5 -2
- package/build/types/ai/langgraph/agent-span.d.ts.map +1 -1
- package/build/types/ai/langgraph/index.d.ts.map +1 -1
- package/build/types/ai/langgraph/stream.d.ts.map +1 -1
- package/build/types/ai/langgraph/types.d.ts +10 -2
- package/build/types/ai/langgraph/types.d.ts.map +1 -1
- package/build/types/ai/openai/mapping.d.ts.map +1 -1
- package/build/types/ai/pi-durable/index.d.ts.map +1 -1
- package/build/types/ai/pi-durable/runs.d.ts +4 -2
- package/build/types/ai/pi-durable/runs.d.ts.map +1 -1
- package/build/types/ai/pi-durable/tools.d.ts +4 -6
- package/build/types/ai/pi-durable/tools.d.ts.map +1 -1
- package/build/types/ai/pi-durable/types.d.ts +10 -1
- package/build/types/ai/pi-durable/types.d.ts.map +1 -1
- package/build/types/ai/types.d.ts +1 -1
- package/build/types/ai/types.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/clickhouse-sql.d.ts +8 -0
- package/build/types/integrations/clickhouse-sql.d.ts.map +1 -0
- package/build/types/integrations/clickhouse.d.ts +11 -0
- package/build/types/integrations/clickhouse.d.ts.map +1 -0
- package/build/types/integrations/express/types.d.ts +1 -0
- package/build/types/integrations/express/types.d.ts.map +1 -1
- package/build/types/integrations/fastify/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/hapi/index.d.ts +12 -0
- package/build/types/integrations/hapi/index.d.ts.map +1 -1
- package/build/types/integrations/index.d.ts.map +1 -1
- package/build/types/integrations/langchain.d.ts.map +1 -1
- package/build/types/orchestrion/channels.d.ts +12 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/channel-integration-definitions.d.ts +3 -0
- package/build/types/orchestrion/config/channel-integration-definitions.d.ts.map +1 -1
- package/build/types/orchestrion/config/clickhouse.d.ts +18 -0
- package/build/types/orchestrion/config/clickhouse.d.ts.map +1 -0
- package/build/types/orchestrion/config/index.d.ts.map +1 -1
- package/build/types/utils/sql.d.ts +28 -3
- package/build/types/utils/sql.d.ts.map +1 -1
- package/build/types/utils/wrapServerRequestHandler.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -544,10 +544,57 @@ const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = "gen_ai.tool.call.id";
|
|
|
544
544
|
function getDecisionInputMessages$1(params) {
|
|
545
545
|
const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;
|
|
546
546
|
return getEvaluationInputMessages({
|
|
547
|
-
state: params.input,
|
|
547
|
+
state: toStateMessages$1(params.input),
|
|
548
548
|
questions: keyByName(questions)
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Lay out evidence messages as gen_ai messages, so they render like Google's. Other input items (tool calls and
|
|
553
|
+
* their outputs) keep their layout, with output parts mapped like message parts.
|
|
554
|
+
*/
|
|
555
|
+
function toStateMessages$1(input) {
|
|
556
|
+
if (!Array.isArray(input)) return input;
|
|
557
|
+
return input.map((item) => {
|
|
558
|
+
if (!(0, _sentry_core.isObjectLike)(item)) return item;
|
|
559
|
+
if (typeof item.role === "string") return {
|
|
560
|
+
role: item.role === "developer" ? "system" : item.role,
|
|
561
|
+
parts: Array.isArray(item.content) ? item.content.filter(_sentry_core.isObjectLike).map(toMessagePart) : [{
|
|
562
|
+
type: "text",
|
|
563
|
+
content: item.content
|
|
564
|
+
}]
|
|
565
|
+
};
|
|
566
|
+
return Array.isArray(item.output) ? {
|
|
567
|
+
...item,
|
|
568
|
+
output: item.output.filter(_sentry_core.isObjectLike).map(toMessagePart)
|
|
569
|
+
} : item;
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* An image in a data URL is reported by its media type only: the URL holds base64, which the conventions require to be
|
|
574
|
+
* dropped.
|
|
575
|
+
*/
|
|
576
|
+
function toMessagePart(part) {
|
|
577
|
+
if (part.type === "input_image" && typeof part.image_url === "string") {
|
|
578
|
+
const dataUrlMimeType = /^data:([^;,]+)/.exec(part.image_url)?.[1];
|
|
579
|
+
return part.image_url.startsWith("data:") ? {
|
|
580
|
+
type: "blob",
|
|
581
|
+
modality: "image",
|
|
582
|
+
mime_type: dataUrlMimeType
|
|
583
|
+
} : {
|
|
584
|
+
type: "uri",
|
|
585
|
+
modality: "image",
|
|
586
|
+
uri: part.image_url
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (part.type === "input_json") return {
|
|
590
|
+
type: "object",
|
|
591
|
+
content: part.data
|
|
592
|
+
};
|
|
593
|
+
return {
|
|
594
|
+
type: "text",
|
|
595
|
+
content: part.text ?? part.refusal
|
|
596
|
+
};
|
|
597
|
+
}
|
|
551
598
|
/** Serialize the answers of a decisions response, laid out and keyed like Jev answers. */
|
|
552
599
|
function getDecisionOutputMessages(answers) {
|
|
553
600
|
return getEvaluationOutputMessages(keyByName(answers.map(toJevAnswerFormat)));
|
|
@@ -1681,10 +1728,38 @@ const GOOGLE_GENAI_SYSTEM_NAME = "google_genai";
|
|
|
1681
1728
|
*/
|
|
1682
1729
|
function getDecisionInputMessages(params) {
|
|
1683
1730
|
return getEvaluationInputMessages({
|
|
1684
|
-
state: params.input,
|
|
1731
|
+
state: toStateMessages(params.input),
|
|
1685
1732
|
questions: params.questions
|
|
1686
1733
|
});
|
|
1687
1734
|
}
|
|
1735
|
+
/**
|
|
1736
|
+
* Multimodal evidence is one part or a list of parts, recorded as one user message so it renders like OpenAI's.
|
|
1737
|
+
* Inline media is reported by modality and media type only: its `data` is base64, which the conventions require
|
|
1738
|
+
* to be dropped.
|
|
1739
|
+
*/
|
|
1740
|
+
function toStateMessages(input) {
|
|
1741
|
+
if (typeof input === "string") return input;
|
|
1742
|
+
return [{
|
|
1743
|
+
role: "user",
|
|
1744
|
+
parts: (Array.isArray(input) ? input : [input]).filter(_sentry_core.isObjectLike).map((part) => {
|
|
1745
|
+
if (part.type === "text") return {
|
|
1746
|
+
type: "text",
|
|
1747
|
+
content: part.text
|
|
1748
|
+
};
|
|
1749
|
+
if (typeof part.uri === "string") return {
|
|
1750
|
+
type: "uri",
|
|
1751
|
+
modality: part.type,
|
|
1752
|
+
mime_type: part.mime_type,
|
|
1753
|
+
uri: part.uri
|
|
1754
|
+
};
|
|
1755
|
+
return {
|
|
1756
|
+
type: "blob",
|
|
1757
|
+
modality: part.type,
|
|
1758
|
+
mime_type: part.mime_type
|
|
1759
|
+
};
|
|
1760
|
+
})
|
|
1761
|
+
}];
|
|
1762
|
+
}
|
|
1688
1763
|
function addDecisionResponseAttributes(span, response, recordOutputs) {
|
|
1689
1764
|
if (!(0, _sentry_core.isObjectLike)(response)) return;
|
|
1690
1765
|
if ((0, _sentry_core.isObjectLike)(response.usage)) {
|
|
@@ -3587,11 +3662,9 @@ function extractEmbeddingAttributes(instance) {
|
|
|
3587
3662
|
* @internal Exported so the diagnostics-channel (orchestrion) instrumentation can build the same
|
|
3588
3663
|
* span as the prototype-patching path below.
|
|
3589
3664
|
*/
|
|
3590
|
-
function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance,
|
|
3591
|
-
const {
|
|
3592
|
-
|
|
3593
|
-
input
|
|
3594
|
-
});
|
|
3665
|
+
function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance, call, options = {}) {
|
|
3666
|
+
const { input } = call;
|
|
3667
|
+
const { recordInputs } = resolveGenAiCallRecording(options, call);
|
|
3595
3668
|
const attributes = extractEmbeddingAttributes(instance);
|
|
3596
3669
|
const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
|
|
3597
3670
|
const client = (0, _sentry_core.getClient)();
|
|
@@ -3608,8 +3681,24 @@ function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance, input, options =
|
|
|
3608
3681
|
*/
|
|
3609
3682
|
function instrumentEmbeddingMethod(originalMethod, options = {}) {
|
|
3610
3683
|
return new Proxy(originalMethod, { apply(target, thisArg, args) {
|
|
3611
|
-
|
|
3612
|
-
|
|
3684
|
+
const call = {
|
|
3685
|
+
operation: "embeddings",
|
|
3686
|
+
input: args[0]
|
|
3687
|
+
};
|
|
3688
|
+
return (0, _sentry_core.startSpan)(_INTERNAL_getLangChainEmbeddingsSpanOptions(thisArg, call, options), async (span) => {
|
|
3689
|
+
runGenAiSpanStart(options, span, call);
|
|
3690
|
+
try {
|
|
3691
|
+
const response = await Reflect.apply(target, thisArg, args);
|
|
3692
|
+
runGenAiSpanEnd(options, span, call, { response });
|
|
3693
|
+
return response;
|
|
3694
|
+
} catch (error) {
|
|
3695
|
+
span.setStatus({
|
|
3696
|
+
code: _sentry_core.SPAN_STATUS_ERROR,
|
|
3697
|
+
message: "internal_error"
|
|
3698
|
+
});
|
|
3699
|
+
runGenAiSpanEnd(options, span, call, { error });
|
|
3700
|
+
throw error;
|
|
3701
|
+
}
|
|
3613
3702
|
});
|
|
3614
3703
|
} });
|
|
3615
3704
|
}
|
|
@@ -3651,9 +3740,12 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3651
3740
|
/**
|
|
3652
3741
|
* Exit a span and clean up
|
|
3653
3742
|
*/
|
|
3654
|
-
const exitSpan = (runId) => {
|
|
3655
|
-
const
|
|
3656
|
-
if (span
|
|
3743
|
+
const exitSpan = (runId, result = {}) => {
|
|
3744
|
+
const run = runs.remove(runId);
|
|
3745
|
+
if (run?.span.isRecording()) {
|
|
3746
|
+
runGenAiSpanEnd(options, run.span, run.call, result);
|
|
3747
|
+
run.span.end();
|
|
3748
|
+
}
|
|
3657
3749
|
};
|
|
3658
3750
|
let warnedFull = false;
|
|
3659
3751
|
const trackRun = (runId, run) => {
|
|
@@ -3669,7 +3761,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3669
3761
|
};
|
|
3670
3762
|
const getAncestors = (parentRunId) => {
|
|
3671
3763
|
const ancestors = [];
|
|
3672
|
-
for (let run = getRun(parentRunId); run; run = getRun(run.parentRunId)) ancestors.push(run);
|
|
3764
|
+
for (let run = getRun(parentRunId); run; run = getRun(run.call.parentRunId)) ancestors.push(run);
|
|
3673
3765
|
return ancestors;
|
|
3674
3766
|
};
|
|
3675
3767
|
const getParentRunSpan = (ancestors, activeSpan) => {
|
|
@@ -3678,7 +3770,8 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3678
3770
|
if (!(0, _sentry_core.spanIsIgnored)(run.span) || (0, _sentry_core.getRootSpan)(run.span) === run.span) return run.span;
|
|
3679
3771
|
}
|
|
3680
3772
|
};
|
|
3681
|
-
const startRunSpan = (
|
|
3773
|
+
const startRunSpan = (call, recordOutputs, start) => {
|
|
3774
|
+
const { runId, parentRunId } = call;
|
|
3682
3775
|
const ancestors = getAncestors(parentRunId);
|
|
3683
3776
|
const activeSpan = (0, _sentry_core.getActiveSpan)();
|
|
3684
3777
|
const parentSpan = getParentRunSpan(ancestors, activeSpan);
|
|
@@ -3688,7 +3781,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3688
3781
|
if (conversationId && conversationId !== ownId) span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, conversationId);
|
|
3689
3782
|
const run = {
|
|
3690
3783
|
span,
|
|
3691
|
-
|
|
3784
|
+
call,
|
|
3692
3785
|
activeSpan,
|
|
3693
3786
|
conversationId,
|
|
3694
3787
|
recordOutputs
|
|
@@ -3699,6 +3792,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3699
3792
|
ancestor.conversationId = conversationId;
|
|
3700
3793
|
ancestor.span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, conversationId);
|
|
3701
3794
|
}
|
|
3795
|
+
runGenAiSpanStart(options, span, call);
|
|
3702
3796
|
return run;
|
|
3703
3797
|
};
|
|
3704
3798
|
/**
|
|
@@ -3732,7 +3826,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3732
3826
|
awaitHandlers: true,
|
|
3733
3827
|
handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, _runName) {
|
|
3734
3828
|
const serialized = llm;
|
|
3735
|
-
const
|
|
3829
|
+
const call = {
|
|
3736
3830
|
operation: "chat",
|
|
3737
3831
|
serialized,
|
|
3738
3832
|
prompts,
|
|
@@ -3741,12 +3835,13 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3741
3835
|
extraParams,
|
|
3742
3836
|
tags,
|
|
3743
3837
|
metadata
|
|
3744
|
-
}
|
|
3838
|
+
};
|
|
3839
|
+
const { recordInputs, recordOutputs } = resolveRecording(call);
|
|
3745
3840
|
const attributes = extractLLMRequestAttributes(serialized, prompts, recordInputs, getInvocationParams(tags), metadata);
|
|
3746
3841
|
const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
|
|
3747
3842
|
const operationName = typeof attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] === "string" ? attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] : "unknown";
|
|
3748
3843
|
const client = (0, _sentry_core.getClient)();
|
|
3749
|
-
startRunSpan(
|
|
3844
|
+
startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
|
|
3750
3845
|
name: typeof modelName === "string" && modelName !== "unknown" || !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `${operationName} ${modelName}` : operationName,
|
|
3751
3846
|
attributes: {
|
|
3752
3847
|
...getAgentNameFromMetadata(metadata),
|
|
@@ -3759,7 +3854,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3759
3854
|
handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, _runName) {
|
|
3760
3855
|
const serialized = llm;
|
|
3761
3856
|
const chatMessages = messages;
|
|
3762
|
-
const
|
|
3857
|
+
const call = {
|
|
3763
3858
|
operation: "chat",
|
|
3764
3859
|
serialized,
|
|
3765
3860
|
messages: chatMessages,
|
|
@@ -3768,14 +3863,15 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3768
3863
|
extraParams,
|
|
3769
3864
|
tags,
|
|
3770
3865
|
metadata
|
|
3771
|
-
}
|
|
3866
|
+
};
|
|
3867
|
+
const { recordInputs, recordOutputs } = resolveRecording(call);
|
|
3772
3868
|
const attributes = extractChatModelRequestAttributes(serialized, chatMessages, recordInputs, getInvocationParams(tags), metadata);
|
|
3773
3869
|
const toolDefsJson = recordInputs ? extractToolDefinitions(extraParams) : void 0;
|
|
3774
3870
|
if (toolDefsJson) attributes[_sentry_conventions_attributes.GEN_AI_TOOL_DEFINITIONS] = toolDefsJson;
|
|
3775
3871
|
const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
|
|
3776
3872
|
const operationName = typeof attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] === "string" ? attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] : "unknown";
|
|
3777
3873
|
const client = (0, _sentry_core.getClient)();
|
|
3778
|
-
startRunSpan(
|
|
3874
|
+
startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
|
|
3779
3875
|
name: typeof modelName === "string" && modelName !== "unknown" || !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `${operationName} ${modelName}` : operationName,
|
|
3780
3876
|
attributes: {
|
|
3781
3877
|
...getAgentNameFromMetadata(metadata),
|
|
@@ -3796,19 +3892,19 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3796
3892
|
const attributes = extractLlmResponseAttributes(output, run.recordOutputs);
|
|
3797
3893
|
if (attributes) span.setAttributes(attributes);
|
|
3798
3894
|
}
|
|
3799
|
-
exitSpan(runId);
|
|
3895
|
+
exitSpan(runId, { response: output });
|
|
3800
3896
|
},
|
|
3801
|
-
handleLLMError(
|
|
3897
|
+
handleLLMError(error, runId) {
|
|
3802
3898
|
const span = runs.get(runId)?.span;
|
|
3803
3899
|
if (span?.isRecording()) span.setStatus({
|
|
3804
3900
|
code: _sentry_core.SPAN_STATUS_ERROR,
|
|
3805
3901
|
message: "internal_error"
|
|
3806
3902
|
});
|
|
3807
|
-
exitSpan(runId);
|
|
3903
|
+
exitSpan(runId, { error });
|
|
3808
3904
|
},
|
|
3809
3905
|
handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, _runType, runName) {
|
|
3810
3906
|
if (isTypeSafeClassifier(chain)) {
|
|
3811
|
-
const
|
|
3907
|
+
const call = {
|
|
3812
3908
|
operation: "decide",
|
|
3813
3909
|
serialized: chain,
|
|
3814
3910
|
inputs,
|
|
@@ -3816,12 +3912,13 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3816
3912
|
parentRunId,
|
|
3817
3913
|
tags,
|
|
3818
3914
|
metadata
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3915
|
+
};
|
|
3916
|
+
const { recordInputs, recordOutputs } = resolveRecording(call);
|
|
3917
|
+
startRunSpan(call, recordOutputs, () => startTypeSafeClassifierSpan(chain, inputs, metadata, recordInputs)).decide = true;
|
|
3821
3918
|
return;
|
|
3822
3919
|
}
|
|
3823
3920
|
if (metadata?.__sentry_langgraph__) return;
|
|
3824
|
-
const
|
|
3921
|
+
const call = {
|
|
3825
3922
|
operation: "invoke_agent",
|
|
3826
3923
|
serialized: chain,
|
|
3827
3924
|
inputs,
|
|
@@ -3829,7 +3926,8 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3829
3926
|
parentRunId,
|
|
3830
3927
|
tags,
|
|
3831
3928
|
metadata
|
|
3832
|
-
}
|
|
3929
|
+
};
|
|
3930
|
+
const { recordInputs, recordOutputs } = resolveRecording(call);
|
|
3833
3931
|
const chainName = runName || chain.name;
|
|
3834
3932
|
const attributes = {
|
|
3835
3933
|
...getConversationIdFromMetadata(metadata),
|
|
@@ -3839,7 +3937,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3839
3937
|
if (chainName) attributes[_sentry_conventions_attributes.GEN_AI_PIPELINE_NAME] = chainName;
|
|
3840
3938
|
if (recordInputs) attributes["langchain.chain.inputs"] = JSON.stringify(inputs);
|
|
3841
3939
|
const client = (0, _sentry_core.getClient)();
|
|
3842
|
-
startRunSpan(
|
|
3940
|
+
startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
|
|
3843
3941
|
name: !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `chain ${chainName || "unknown_chain"}` : chainName ? `invoke_agent ${chainName}` : "invoke_agent",
|
|
3844
3942
|
attributes: {
|
|
3845
3943
|
...attributes,
|
|
@@ -3854,19 +3952,19 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3854
3952
|
if (run.decide) addTypeSafeClassifierResponseAttributes(span, outputs, run.recordOutputs);
|
|
3855
3953
|
else if (run.recordOutputs) span.setAttributes({ "langchain.chain.outputs": JSON.stringify(outputs) });
|
|
3856
3954
|
}
|
|
3857
|
-
exitSpan(runId);
|
|
3955
|
+
exitSpan(runId, { response: outputs });
|
|
3858
3956
|
},
|
|
3859
|
-
handleChainError(
|
|
3957
|
+
handleChainError(error, runId) {
|
|
3860
3958
|
const span = runs.get(runId)?.span;
|
|
3861
3959
|
if (span?.isRecording()) span.setStatus({
|
|
3862
3960
|
code: _sentry_core.SPAN_STATUS_ERROR,
|
|
3863
3961
|
message: "internal_error"
|
|
3864
3962
|
});
|
|
3865
|
-
exitSpan(runId);
|
|
3963
|
+
exitSpan(runId, { error });
|
|
3866
3964
|
},
|
|
3867
3965
|
handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName) {
|
|
3868
3966
|
if (metadata?.__sentry_langgraph__) return;
|
|
3869
|
-
const
|
|
3967
|
+
const call = {
|
|
3870
3968
|
operation: "execute_tool",
|
|
3871
3969
|
serialized: tool,
|
|
3872
3970
|
input,
|
|
@@ -3874,7 +3972,8 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3874
3972
|
parentRunId,
|
|
3875
3973
|
tags,
|
|
3876
3974
|
metadata
|
|
3877
|
-
}
|
|
3975
|
+
};
|
|
3976
|
+
const { recordInputs, recordOutputs } = resolveRecording(call);
|
|
3878
3977
|
const toolName = runName || tool.name || "unknown_tool";
|
|
3879
3978
|
const attributes = {
|
|
3880
3979
|
...getAgentNameFromMetadata(metadata),
|
|
@@ -3884,7 +3983,7 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3884
3983
|
[_sentry_conventions_attributes.GEN_AI_TOOL_NAME]: toolName
|
|
3885
3984
|
};
|
|
3886
3985
|
if (recordInputs) attributes[_sentry_conventions_attributes.GEN_AI_TOOL_CALL_ARGUMENTS] = input;
|
|
3887
|
-
startRunSpan(
|
|
3986
|
+
startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
|
|
3888
3987
|
name: `execute_tool ${toolName}`,
|
|
3889
3988
|
attributes: {
|
|
3890
3989
|
...attributes,
|
|
@@ -3902,15 +4001,15 @@ function createLangChainCallbackHandler(options = {}) {
|
|
|
3902
4001
|
span.setAttributes({ [_sentry_conventions_attributes.GEN_AI_TOOL_CALL_RESULT]: (0, _sentry_core.stringify)(content, String) });
|
|
3903
4002
|
}
|
|
3904
4003
|
}
|
|
3905
|
-
exitSpan(runId);
|
|
4004
|
+
exitSpan(runId, { response: output });
|
|
3906
4005
|
},
|
|
3907
|
-
handleToolError(
|
|
4006
|
+
handleToolError(error, runId) {
|
|
3908
4007
|
const span = runs.get(runId)?.span;
|
|
3909
4008
|
if (span?.isRecording()) span.setStatus({
|
|
3910
4009
|
code: _sentry_core.SPAN_STATUS_ERROR,
|
|
3911
4010
|
message: "internal_error"
|
|
3912
4011
|
});
|
|
3913
|
-
exitSpan(runId);
|
|
4012
|
+
exitSpan(runId, { error });
|
|
3914
4013
|
},
|
|
3915
4014
|
copy() {
|
|
3916
4015
|
return handler;
|
|
@@ -4153,11 +4252,15 @@ function getAgentSpanOptions(args, extraAttributes) {
|
|
|
4153
4252
|
}
|
|
4154
4253
|
/** Decides for one `invoke()`/`stream()` call, from its arguments as passed. */
|
|
4155
4254
|
function resolveGraphCallRecording(options, args) {
|
|
4156
|
-
|
|
4255
|
+
const call = {
|
|
4157
4256
|
operation: "invoke_agent",
|
|
4158
4257
|
input: args[0],
|
|
4159
4258
|
config: args[1]
|
|
4160
|
-
}
|
|
4259
|
+
};
|
|
4260
|
+
return {
|
|
4261
|
+
call,
|
|
4262
|
+
recording: resolveGenAiCallRecording(options, call)
|
|
4263
|
+
};
|
|
4161
4264
|
}
|
|
4162
4265
|
/** Sets the request attributes on an agent span and injects the callback handler into the call's config. */
|
|
4163
4266
|
function prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler) {
|
|
@@ -4211,7 +4314,7 @@ function prepareAgentSpan(span, args, graphInstance, compileOptions, recording,
|
|
|
4211
4314
|
function instrumentCompiledGraphStream(originalStream, graphInstance, compileOptions, options, llm, sentryCallbackHandler) {
|
|
4212
4315
|
return new Proxy(originalStream, { apply(target, thisArg, args) {
|
|
4213
4316
|
if (isInvokeInternalStream(graphInstance)) return Reflect.apply(target, thisArg, args);
|
|
4214
|
-
const recording = resolveGraphCallRecording(options, args);
|
|
4317
|
+
const { call, recording } = resolveGraphCallRecording(options, args);
|
|
4215
4318
|
return (0, _sentry_core.startSpanManual)(getAgentSpanOptions(args, { [_sentry_conventions_attributes.GEN_AI_RESPONSE_STREAMING]: true }), async (span) => {
|
|
4216
4319
|
let inputMessages = null;
|
|
4217
4320
|
let stream;
|
|
@@ -4227,6 +4330,7 @@ function instrumentCompiledGraphStream(originalStream, graphInstance, compileOpt
|
|
|
4227
4330
|
});
|
|
4228
4331
|
} else if (outcome && recording.recordOutputs) setResponseAttributes(span, inputMessages, outcome.outputs);
|
|
4229
4332
|
} catch {}
|
|
4333
|
+
runGenAiSpanEnd(options, span, call, outcome && "error" in outcome ? { error: outcome.error } : { response: outcome?.outputs });
|
|
4230
4334
|
span.end();
|
|
4231
4335
|
inputMessages = null;
|
|
4232
4336
|
};
|
|
@@ -4249,6 +4353,7 @@ function instrumentCompiledGraphStream(originalStream, graphInstance, compileOpt
|
|
|
4249
4353
|
};
|
|
4250
4354
|
try {
|
|
4251
4355
|
inputMessages = prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler);
|
|
4356
|
+
runGenAiSpanStart(options, span, call);
|
|
4252
4357
|
const config = args[1];
|
|
4253
4358
|
config.callbacks = _INTERNAL_addLangChainCallbackHandler(config.callbacks, listener);
|
|
4254
4359
|
stream = await Reflect.apply(target, thisArg, args);
|
|
@@ -4337,18 +4442,21 @@ function instrumentCompiledGraph(graph, compileOptions, options, llm, sentryCall
|
|
|
4337
4442
|
*/
|
|
4338
4443
|
function instrumentCompiledGraphInvoke(originalInvoke, graphInstance, compileOptions, options, llm, sentryCallbackHandler) {
|
|
4339
4444
|
return new Proxy(originalInvoke, { apply(target, thisArg, args) {
|
|
4340
|
-
const recording = resolveGraphCallRecording(options, args);
|
|
4445
|
+
const { call, recording } = resolveGraphCallRecording(options, args);
|
|
4341
4446
|
return (0, _sentry_core.startSpan)(getAgentSpanOptions(args), async (span) => {
|
|
4342
4447
|
try {
|
|
4343
4448
|
const inputMessages = prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler);
|
|
4449
|
+
runGenAiSpanStart(options, span, call);
|
|
4344
4450
|
const result = await callInvoke(graphInstance, () => Reflect.apply(target, thisArg, args));
|
|
4345
4451
|
if (recording.recordOutputs) setResponseAttributes(span, inputMessages, result);
|
|
4452
|
+
runGenAiSpanEnd(options, span, call, { response: result });
|
|
4346
4453
|
return result;
|
|
4347
4454
|
} catch (error) {
|
|
4348
4455
|
span.setStatus({
|
|
4349
4456
|
code: _sentry_core.SPAN_STATUS_ERROR,
|
|
4350
4457
|
message: "internal_error"
|
|
4351
4458
|
});
|
|
4459
|
+
runGenAiSpanEnd(options, span, call, { error });
|
|
4352
4460
|
throw error;
|
|
4353
4461
|
}
|
|
4354
4462
|
});
|
|
@@ -5163,6 +5271,7 @@ function startToolSpan(observation, context, toolSpans, options) {
|
|
|
5163
5271
|
...recordInputs && observation.args !== void 0 ? { [_sentry_conventions_attributes.GEN_AI_TOOL_CALL_ARGUMENTS]: (0, _sentry_core.stringify)(observation.args) } : {}
|
|
5164
5272
|
}
|
|
5165
5273
|
});
|
|
5274
|
+
if (observation.conversationId) span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, observation.conversationId);
|
|
5166
5275
|
if (recordOutputs) TOOL_SPANS_RECORDING_OUTPUTS.add(span);
|
|
5167
5276
|
runGenAiSpanStart(options, span, call);
|
|
5168
5277
|
TOOL_SPAN_END_HOOKS.set(span, (end) => runGenAiSpanEnd(options, span, call, end.isError ? {
|
|
@@ -5344,7 +5453,7 @@ const MAX_SUMMARY_LENGTH = 255;
|
|
|
5344
5453
|
const IDENTIFIER = "(?:\"[^\"]*\"|'[^']*'|`[^`]*`|[^\\s(,;).'\"`]+)";
|
|
5345
5454
|
const TABLE_NAME = `${IDENTIFIER}(?:\\.${IDENTIFIER})*`;
|
|
5346
5455
|
const DDL_RE = new RegExp(`^\\s*(?<operation>(?:CREATE|DROP)\\s+(?:TABLE|INDEX)|ALTER\\s+TABLE)(?:\\s+IF\\s+(?:NOT\\s+)?EXISTS)?\\s+(?<table>${TABLE_NAME})`, "i");
|
|
5347
|
-
const INSERT_RE = new RegExp(`^\\s*(?<operation>INSERT|REPLACE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+INTO
|
|
5456
|
+
const INSERT_RE = new RegExp(`^\\s*(?<operation>INSERT|REPLACE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+INTO(?:\\s+TABLE)?\\s+(?<table>${TABLE_NAME})`, "i");
|
|
5348
5457
|
const UPDATE_RE = new RegExp(`^\\s*(?<operation>UPDATE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+(?<table>${TABLE_NAME})`, "i");
|
|
5349
5458
|
const DELETE_RE = new RegExp(`^\\s*(?<operation>DELETE)\\s+FROM\\s+(?<table>${TABLE_NAME})`, "i");
|
|
5350
5459
|
const SELECT_RE = /^\s*(?:\(\s*)?(?<operation>SELECT)\b/i;
|
|
@@ -5487,6 +5596,7 @@ function toSqlDialect(system) {
|
|
|
5487
5596
|
if (system === "mssql" || system === "sqlserver" || system === "microsoft.sql_server") return "mssql";
|
|
5488
5597
|
return "standard";
|
|
5489
5598
|
}
|
|
5599
|
+
const NO_RULES = {};
|
|
5490
5600
|
const DOLLAR_QUOTE_RE = /\$(?:[A-Za-z_]\w*)?\$/y;
|
|
5491
5601
|
/**
|
|
5492
5602
|
* Returns the index just past the run's closing `delimiter`, or -1 if the run never closes. The
|
|
@@ -5507,6 +5617,18 @@ function findQuotedRunEnd(sql, start, delimiter, backslashEscapes) {
|
|
|
5507
5617
|
}
|
|
5508
5618
|
return -1;
|
|
5509
5619
|
}
|
|
5620
|
+
function findBlockCommentEnd(sql, start, nested) {
|
|
5621
|
+
let depth = 1;
|
|
5622
|
+
let i = start + 2;
|
|
5623
|
+
while (i < sql.length && depth > 0) if (sql[i] === "*" && sql[i + 1] === "/") {
|
|
5624
|
+
depth--;
|
|
5625
|
+
i += 2;
|
|
5626
|
+
} else if (nested && sql[i] === "/" && sql[i + 1] === "*") {
|
|
5627
|
+
depth++;
|
|
5628
|
+
i += 2;
|
|
5629
|
+
} else i++;
|
|
5630
|
+
return i;
|
|
5631
|
+
}
|
|
5510
5632
|
/**
|
|
5511
5633
|
* Replaces every string literal with `?` and drops every comment, in one pass.
|
|
5512
5634
|
*
|
|
@@ -5519,24 +5641,25 @@ function findQuotedRunEnd(sql, start, delimiter, backslashEscapes) {
|
|
|
5519
5641
|
* built from.
|
|
5520
5642
|
*/
|
|
5521
5643
|
function stripLiteralsAndComments(sql, dialect) {
|
|
5522
|
-
const
|
|
5644
|
+
const [base, rules] = typeof dialect === "string" ? [dialect, NO_RULES] : ["standard", dialect];
|
|
5645
|
+
const isMysql = base === "mysql";
|
|
5646
|
+
const backslashEscapes = !!rules.backslashEscapes;
|
|
5523
5647
|
const out = [];
|
|
5524
5648
|
let i = 0;
|
|
5525
5649
|
while (i < sql.length) {
|
|
5526
5650
|
const char = sql[i];
|
|
5527
5651
|
const next = sql[i + 1];
|
|
5528
|
-
if (char === "-" && next === "-" || isMysql && char === "#") {
|
|
5652
|
+
if (char === "-" && next === "-" || (isMysql || rules.hashComments) && char === "#") {
|
|
5529
5653
|
const lineEnd = sql.indexOf("\n", i);
|
|
5530
5654
|
i = lineEnd === -1 ? sql.length : lineEnd;
|
|
5531
5655
|
continue;
|
|
5532
5656
|
}
|
|
5533
5657
|
if (char === "/" && next === "*") {
|
|
5534
|
-
|
|
5535
|
-
i = commentEnd === -1 ? sql.length : commentEnd + 2;
|
|
5658
|
+
i = findBlockCommentEnd(sql, i, !!rules.nestedComments);
|
|
5536
5659
|
continue;
|
|
5537
5660
|
}
|
|
5538
|
-
if (
|
|
5539
|
-
const tag = matchDollarQuoteTag(sql, i);
|
|
5661
|
+
if (base === "standard" && char === "$" && !isIdentifierChar(sql[i - 1])) {
|
|
5662
|
+
const tag = matchDollarQuoteTag(sql, i, rules.dollarQuote);
|
|
5540
5663
|
if (tag) {
|
|
5541
5664
|
const bodyEnd = sql.indexOf(tag, i + tag.length);
|
|
5542
5665
|
i = bodyEnd === -1 ? sql.length : bodyEnd + tag.length;
|
|
@@ -5544,21 +5667,28 @@ function stripLiteralsAndComments(sql, dialect) {
|
|
|
5544
5667
|
continue;
|
|
5545
5668
|
}
|
|
5546
5669
|
}
|
|
5547
|
-
const identifierCloser = getIdentifierCloser(char,
|
|
5670
|
+
const identifierCloser = getIdentifierCloser(char, base);
|
|
5548
5671
|
if (identifierCloser) {
|
|
5549
|
-
const runEnd = findQuotedRunEnd(sql, i, identifierCloser,
|
|
5672
|
+
const runEnd = findQuotedRunEnd(sql, i, identifierCloser, backslashEscapes);
|
|
5550
5673
|
out.push(runEnd === -1 ? "?" : sql.slice(i, runEnd));
|
|
5551
5674
|
i = runEnd === -1 ? sql.length : runEnd;
|
|
5552
5675
|
continue;
|
|
5553
5676
|
}
|
|
5554
5677
|
if (char === "'" || char === "\"" && isMysql) {
|
|
5555
|
-
const prefix = char === "'" ? getLiteralPrefix(out,
|
|
5678
|
+
const prefix = char === "'" ? getLiteralPrefix(out, base) : void 0;
|
|
5556
5679
|
if (prefix) out.pop();
|
|
5557
|
-
const runEnd = findQuotedRunEnd(sql, i, char, isMysql || prefix === "E");
|
|
5680
|
+
const runEnd = findQuotedRunEnd(sql, i, char, isMysql || backslashEscapes || prefix === "E");
|
|
5558
5681
|
i = runEnd === -1 ? sql.length : runEnd;
|
|
5559
5682
|
out.push("?");
|
|
5560
5683
|
continue;
|
|
5561
5684
|
}
|
|
5685
|
+
const literalLength = rules.matchLiteral?.(sql, i);
|
|
5686
|
+
if (literalLength) {
|
|
5687
|
+
out.push("?");
|
|
5688
|
+
i += literalLength;
|
|
5689
|
+
continue;
|
|
5690
|
+
}
|
|
5691
|
+
if (rules.isInlineData?.(sql, i, out)) break;
|
|
5562
5692
|
out.push(char);
|
|
5563
5693
|
i++;
|
|
5564
5694
|
}
|
|
@@ -5579,9 +5709,9 @@ function isIdentifierChar(char) {
|
|
|
5579
5709
|
return char !== void 0 && /[\w$]/.test(char);
|
|
5580
5710
|
}
|
|
5581
5711
|
/** Returns the opening dollar-quote tag at `start` (`$$` or `$tag$`), or undefined if there is none. */
|
|
5582
|
-
function matchDollarQuoteTag(sql, start) {
|
|
5583
|
-
|
|
5584
|
-
return
|
|
5712
|
+
function matchDollarQuoteTag(sql, start, pattern = DOLLAR_QUOTE_RE) {
|
|
5713
|
+
pattern.lastIndex = start;
|
|
5714
|
+
return pattern.exec(sql)?.[0];
|
|
5585
5715
|
}
|
|
5586
5716
|
/**
|
|
5587
5717
|
* Returns the literal-prefix character immediately before a `'`, if there is one: `X`/`B` for
|
|
@@ -5604,7 +5734,7 @@ function getLiteralPrefix(out, dialect) {
|
|
|
5604
5734
|
* booleans) are sanitized.
|
|
5605
5735
|
*
|
|
5606
5736
|
* Pass `dialect` when the statement comes from a driver whose literals are not standard-quoted;
|
|
5607
|
-
* see {@link SqlDialect}.
|
|
5737
|
+
* see {@link SqlDialect} and {@link SqlLexerRules}.
|
|
5608
5738
|
*/
|
|
5609
5739
|
function sanitizeSqlQuery(sqlQuery, dialect = "standard") {
|
|
5610
5740
|
if (!sqlQuery) return "Unknown SQL Query";
|
|
@@ -7147,6 +7277,12 @@ Object.defineProperty(exports, "isDeno", {
|
|
|
7147
7277
|
return isDeno;
|
|
7148
7278
|
}
|
|
7149
7279
|
});
|
|
7280
|
+
Object.defineProperty(exports, "isIdentifierChar", {
|
|
7281
|
+
enumerable: true,
|
|
7282
|
+
get: function() {
|
|
7283
|
+
return isIdentifierChar;
|
|
7284
|
+
}
|
|
7285
|
+
});
|
|
7150
7286
|
Object.defineProperty(exports, "isInsideManualLangGraphInstrumentation", {
|
|
7151
7287
|
enumerable: true,
|
|
7152
7288
|
get: function() {
|