@sentry/server-utils 11.16.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.
Files changed (92) hide show
  1. package/build/cjs/chunks/config.js +60 -0
  2. package/build/cjs/chunks/config.js.map +1 -1
  3. package/build/cjs/chunks/exports.js +116 -56
  4. package/build/cjs/chunks/exports.js.map +1 -1
  5. package/build/cjs/chunks/moduleInjectedTransform.js +8 -0
  6. package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
  7. package/build/cjs/index.js +299 -168
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/esm/ai/langchain/embeddings.js +23 -8
  10. package/build/esm/ai/langchain/embeddings.js.map +1 -1
  11. package/build/esm/ai/langchain/index.js +41 -30
  12. package/build/esm/ai/langchain/index.js.map +1 -1
  13. package/build/esm/ai/langgraph/agent-span.js +6 -2
  14. package/build/esm/ai/langgraph/agent-span.js.map +1 -1
  15. package/build/esm/ai/langgraph/index.js +5 -1
  16. package/build/esm/ai/langgraph/index.js.map +1 -1
  17. package/build/esm/ai/langgraph/stream.js +4 -1
  18. package/build/esm/ai/langgraph/stream.js.map +1 -1
  19. package/build/esm/ai/pi-durable/index.js +10 -13
  20. package/build/esm/ai/pi-durable/index.js.map +1 -1
  21. package/build/esm/ai/pi-durable/runs.js +6 -5
  22. package/build/esm/ai/pi-durable/runs.js.map +1 -1
  23. package/build/esm/ai/pi-durable/tools.js +21 -17
  24. package/build/esm/ai/pi-durable/tools.js.map +1 -1
  25. package/build/esm/index.js +3 -2
  26. package/build/esm/index.js.map +1 -1
  27. package/build/esm/integrations/clickhouse-sql.js +31 -0
  28. package/build/esm/integrations/clickhouse-sql.js.map +1 -0
  29. package/build/esm/integrations/clickhouse.js +88 -0
  30. package/build/esm/integrations/clickhouse.js.map +1 -0
  31. package/build/esm/integrations/express/instrumentation.js +1 -0
  32. package/build/esm/integrations/express/instrumentation.js.map +1 -1
  33. package/build/esm/integrations/fastify/instrumentation.js +3 -1
  34. package/build/esm/integrations/fastify/instrumentation.js.map +1 -1
  35. package/build/esm/integrations/hapi/index.js +15 -1
  36. package/build/esm/integrations/hapi/index.js.map +1 -1
  37. package/build/esm/integrations/index.js +2 -0
  38. package/build/esm/integrations/index.js.map +1 -1
  39. package/build/esm/integrations/langchain.js +10 -3
  40. package/build/esm/integrations/langchain.js.map +1 -1
  41. package/build/esm/orchestrion/channels.js +2 -0
  42. package/build/esm/orchestrion/channels.js.map +1 -1
  43. package/build/esm/orchestrion/config/channel-integration-definitions.js +8 -0
  44. package/build/esm/orchestrion/config/channel-integration-definitions.js.map +1 -1
  45. package/build/esm/orchestrion/config/clickhouse.js +51 -0
  46. package/build/esm/orchestrion/config/clickhouse.js.map +1 -0
  47. package/build/esm/orchestrion/config/index.js +2 -0
  48. package/build/esm/orchestrion/config/index.js.map +1 -1
  49. package/build/esm/package.json +1 -1
  50. package/build/esm/utils/sql.js +37 -16
  51. package/build/esm/utils/sql.js.map +1 -1
  52. package/build/types/ai/langchain/embeddings.d.ts +2 -2
  53. package/build/types/ai/langchain/embeddings.d.ts.map +1 -1
  54. package/build/types/ai/langchain/index.d.ts.map +1 -1
  55. package/build/types/ai/langchain/types.d.ts +8 -4
  56. package/build/types/ai/langchain/types.d.ts.map +1 -1
  57. package/build/types/ai/langgraph/agent-span.d.ts +5 -2
  58. package/build/types/ai/langgraph/agent-span.d.ts.map +1 -1
  59. package/build/types/ai/langgraph/index.d.ts.map +1 -1
  60. package/build/types/ai/langgraph/stream.d.ts.map +1 -1
  61. package/build/types/ai/langgraph/types.d.ts +10 -2
  62. package/build/types/ai/langgraph/types.d.ts.map +1 -1
  63. package/build/types/ai/pi-durable/index.d.ts.map +1 -1
  64. package/build/types/ai/pi-durable/runs.d.ts +4 -2
  65. package/build/types/ai/pi-durable/runs.d.ts.map +1 -1
  66. package/build/types/ai/pi-durable/tools.d.ts +4 -6
  67. package/build/types/ai/pi-durable/tools.d.ts.map +1 -1
  68. package/build/types/ai/pi-durable/types.d.ts +10 -1
  69. package/build/types/ai/pi-durable/types.d.ts.map +1 -1
  70. package/build/types/index.d.ts +2 -1
  71. package/build/types/index.d.ts.map +1 -1
  72. package/build/types/integrations/clickhouse-sql.d.ts +8 -0
  73. package/build/types/integrations/clickhouse-sql.d.ts.map +1 -0
  74. package/build/types/integrations/clickhouse.d.ts +11 -0
  75. package/build/types/integrations/clickhouse.d.ts.map +1 -0
  76. package/build/types/integrations/express/types.d.ts +1 -0
  77. package/build/types/integrations/express/types.d.ts.map +1 -1
  78. package/build/types/integrations/fastify/instrumentation.d.ts.map +1 -1
  79. package/build/types/integrations/hapi/index.d.ts +12 -0
  80. package/build/types/integrations/hapi/index.d.ts.map +1 -1
  81. package/build/types/integrations/index.d.ts.map +1 -1
  82. package/build/types/integrations/langchain.d.ts.map +1 -1
  83. package/build/types/orchestrion/channels.d.ts +12 -0
  84. package/build/types/orchestrion/channels.d.ts.map +1 -1
  85. package/build/types/orchestrion/config/channel-integration-definitions.d.ts +3 -0
  86. package/build/types/orchestrion/config/channel-integration-definitions.d.ts.map +1 -1
  87. package/build/types/orchestrion/config/clickhouse.d.ts +18 -0
  88. package/build/types/orchestrion/config/clickhouse.d.ts.map +1 -0
  89. package/build/types/orchestrion/config/index.d.ts.map +1 -1
  90. package/build/types/utils/sql.d.ts +28 -3
  91. package/build/types/utils/sql.d.ts.map +1 -1
  92. package/package.json +4 -4
@@ -3662,11 +3662,9 @@ function extractEmbeddingAttributes(instance) {
3662
3662
  * @internal Exported so the diagnostics-channel (orchestrion) instrumentation can build the same
3663
3663
  * span as the prototype-patching path below.
3664
3664
  */
3665
- function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance, input, options = {}) {
3666
- const { recordInputs } = resolveGenAiCallRecording(options, {
3667
- operation: "embeddings",
3668
- input
3669
- });
3665
+ function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance, call, options = {}) {
3666
+ const { input } = call;
3667
+ const { recordInputs } = resolveGenAiCallRecording(options, call);
3670
3668
  const attributes = extractEmbeddingAttributes(instance);
3671
3669
  const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
3672
3670
  const client = (0, _sentry_core.getClient)();
@@ -3683,8 +3681,24 @@ function _INTERNAL_getLangChainEmbeddingsSpanOptions(instance, input, options =
3683
3681
  */
3684
3682
  function instrumentEmbeddingMethod(originalMethod, options = {}) {
3685
3683
  return new Proxy(originalMethod, { apply(target, thisArg, args) {
3686
- return (0, _sentry_core.startSpan)(_INTERNAL_getLangChainEmbeddingsSpanOptions(thisArg, args[0], options), () => {
3687
- return Reflect.apply(target, thisArg, args);
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
+ }
3688
3702
  });
3689
3703
  } });
3690
3704
  }
@@ -3726,9 +3740,12 @@ function createLangChainCallbackHandler(options = {}) {
3726
3740
  /**
3727
3741
  * Exit a span and clean up
3728
3742
  */
3729
- const exitSpan = (runId) => {
3730
- const span = runs.remove(runId)?.span;
3731
- if (span?.isRecording()) span.end();
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
+ }
3732
3749
  };
3733
3750
  let warnedFull = false;
3734
3751
  const trackRun = (runId, run) => {
@@ -3744,7 +3761,7 @@ function createLangChainCallbackHandler(options = {}) {
3744
3761
  };
3745
3762
  const getAncestors = (parentRunId) => {
3746
3763
  const ancestors = [];
3747
- 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);
3748
3765
  return ancestors;
3749
3766
  };
3750
3767
  const getParentRunSpan = (ancestors, activeSpan) => {
@@ -3753,7 +3770,8 @@ function createLangChainCallbackHandler(options = {}) {
3753
3770
  if (!(0, _sentry_core.spanIsIgnored)(run.span) || (0, _sentry_core.getRootSpan)(run.span) === run.span) return run.span;
3754
3771
  }
3755
3772
  };
3756
- const startRunSpan = (runId, parentRunId, recordOutputs, start) => {
3773
+ const startRunSpan = (call, recordOutputs, start) => {
3774
+ const { runId, parentRunId } = call;
3757
3775
  const ancestors = getAncestors(parentRunId);
3758
3776
  const activeSpan = (0, _sentry_core.getActiveSpan)();
3759
3777
  const parentSpan = getParentRunSpan(ancestors, activeSpan);
@@ -3763,7 +3781,7 @@ function createLangChainCallbackHandler(options = {}) {
3763
3781
  if (conversationId && conversationId !== ownId) span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, conversationId);
3764
3782
  const run = {
3765
3783
  span,
3766
- parentRunId,
3784
+ call,
3767
3785
  activeSpan,
3768
3786
  conversationId,
3769
3787
  recordOutputs
@@ -3774,6 +3792,7 @@ function createLangChainCallbackHandler(options = {}) {
3774
3792
  ancestor.conversationId = conversationId;
3775
3793
  ancestor.span.setAttribute(_sentry_conventions_attributes.GEN_AI_CONVERSATION_ID, conversationId);
3776
3794
  }
3795
+ runGenAiSpanStart(options, span, call);
3777
3796
  return run;
3778
3797
  };
3779
3798
  /**
@@ -3807,7 +3826,7 @@ function createLangChainCallbackHandler(options = {}) {
3807
3826
  awaitHandlers: true,
3808
3827
  handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, _runName) {
3809
3828
  const serialized = llm;
3810
- const { recordInputs, recordOutputs } = resolveRecording({
3829
+ const call = {
3811
3830
  operation: "chat",
3812
3831
  serialized,
3813
3832
  prompts,
@@ -3816,12 +3835,13 @@ function createLangChainCallbackHandler(options = {}) {
3816
3835
  extraParams,
3817
3836
  tags,
3818
3837
  metadata
3819
- });
3838
+ };
3839
+ const { recordInputs, recordOutputs } = resolveRecording(call);
3820
3840
  const attributes = extractLLMRequestAttributes(serialized, prompts, recordInputs, getInvocationParams(tags), metadata);
3821
3841
  const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
3822
3842
  const operationName = typeof attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] === "string" ? attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] : "unknown";
3823
3843
  const client = (0, _sentry_core.getClient)();
3824
- startRunSpan(runId, parentRunId, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3844
+ startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3825
3845
  name: typeof modelName === "string" && modelName !== "unknown" || !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `${operationName} ${modelName}` : operationName,
3826
3846
  attributes: {
3827
3847
  ...getAgentNameFromMetadata(metadata),
@@ -3834,7 +3854,7 @@ function createLangChainCallbackHandler(options = {}) {
3834
3854
  handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, _runName) {
3835
3855
  const serialized = llm;
3836
3856
  const chatMessages = messages;
3837
- const { recordInputs, recordOutputs } = resolveRecording({
3857
+ const call = {
3838
3858
  operation: "chat",
3839
3859
  serialized,
3840
3860
  messages: chatMessages,
@@ -3843,14 +3863,15 @@ function createLangChainCallbackHandler(options = {}) {
3843
3863
  extraParams,
3844
3864
  tags,
3845
3865
  metadata
3846
- });
3866
+ };
3867
+ const { recordInputs, recordOutputs } = resolveRecording(call);
3847
3868
  const attributes = extractChatModelRequestAttributes(serialized, chatMessages, recordInputs, getInvocationParams(tags), metadata);
3848
3869
  const toolDefsJson = recordInputs ? extractToolDefinitions(extraParams) : void 0;
3849
3870
  if (toolDefsJson) attributes[_sentry_conventions_attributes.GEN_AI_TOOL_DEFINITIONS] = toolDefsJson;
3850
3871
  const modelName = attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
3851
3872
  const operationName = typeof attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] === "string" ? attributes[_sentry_conventions_attributes.GEN_AI_OPERATION_NAME] : "unknown";
3852
3873
  const client = (0, _sentry_core.getClient)();
3853
- startRunSpan(runId, parentRunId, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3874
+ startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3854
3875
  name: typeof modelName === "string" && modelName !== "unknown" || !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `${operationName} ${modelName}` : operationName,
3855
3876
  attributes: {
3856
3877
  ...getAgentNameFromMetadata(metadata),
@@ -3871,19 +3892,19 @@ function createLangChainCallbackHandler(options = {}) {
3871
3892
  const attributes = extractLlmResponseAttributes(output, run.recordOutputs);
3872
3893
  if (attributes) span.setAttributes(attributes);
3873
3894
  }
3874
- exitSpan(runId);
3895
+ exitSpan(runId, { response: output });
3875
3896
  },
3876
- handleLLMError(_error, runId) {
3897
+ handleLLMError(error, runId) {
3877
3898
  const span = runs.get(runId)?.span;
3878
3899
  if (span?.isRecording()) span.setStatus({
3879
3900
  code: _sentry_core.SPAN_STATUS_ERROR,
3880
3901
  message: "internal_error"
3881
3902
  });
3882
- exitSpan(runId);
3903
+ exitSpan(runId, { error });
3883
3904
  },
3884
3905
  handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, _runType, runName) {
3885
3906
  if (isTypeSafeClassifier(chain)) {
3886
- const { recordInputs, recordOutputs } = resolveRecording({
3907
+ const call = {
3887
3908
  operation: "decide",
3888
3909
  serialized: chain,
3889
3910
  inputs,
@@ -3891,12 +3912,13 @@ function createLangChainCallbackHandler(options = {}) {
3891
3912
  parentRunId,
3892
3913
  tags,
3893
3914
  metadata
3894
- });
3895
- startRunSpan(runId, parentRunId, recordOutputs, () => startTypeSafeClassifierSpan(chain, inputs, metadata, recordInputs)).decide = true;
3915
+ };
3916
+ const { recordInputs, recordOutputs } = resolveRecording(call);
3917
+ startRunSpan(call, recordOutputs, () => startTypeSafeClassifierSpan(chain, inputs, metadata, recordInputs)).decide = true;
3896
3918
  return;
3897
3919
  }
3898
3920
  if (metadata?.__sentry_langgraph__) return;
3899
- const { recordInputs, recordOutputs } = resolveRecording({
3921
+ const call = {
3900
3922
  operation: "invoke_agent",
3901
3923
  serialized: chain,
3902
3924
  inputs,
@@ -3904,7 +3926,8 @@ function createLangChainCallbackHandler(options = {}) {
3904
3926
  parentRunId,
3905
3927
  tags,
3906
3928
  metadata
3907
- });
3929
+ };
3930
+ const { recordInputs, recordOutputs } = resolveRecording(call);
3908
3931
  const chainName = runName || chain.name;
3909
3932
  const attributes = {
3910
3933
  ...getConversationIdFromMetadata(metadata),
@@ -3914,7 +3937,7 @@ function createLangChainCallbackHandler(options = {}) {
3914
3937
  if (chainName) attributes[_sentry_conventions_attributes.GEN_AI_PIPELINE_NAME] = chainName;
3915
3938
  if (recordInputs) attributes["langchain.chain.inputs"] = JSON.stringify(inputs);
3916
3939
  const client = (0, _sentry_core.getClient)();
3917
- startRunSpan(runId, parentRunId, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3940
+ startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3918
3941
  name: !(client && (0, _sentry_core.hasSpanStreamingEnabled)(client)) ? `chain ${chainName || "unknown_chain"}` : chainName ? `invoke_agent ${chainName}` : "invoke_agent",
3919
3942
  attributes: {
3920
3943
  ...attributes,
@@ -3929,19 +3952,19 @@ function createLangChainCallbackHandler(options = {}) {
3929
3952
  if (run.decide) addTypeSafeClassifierResponseAttributes(span, outputs, run.recordOutputs);
3930
3953
  else if (run.recordOutputs) span.setAttributes({ "langchain.chain.outputs": JSON.stringify(outputs) });
3931
3954
  }
3932
- exitSpan(runId);
3955
+ exitSpan(runId, { response: outputs });
3933
3956
  },
3934
- handleChainError(_error, runId) {
3957
+ handleChainError(error, runId) {
3935
3958
  const span = runs.get(runId)?.span;
3936
3959
  if (span?.isRecording()) span.setStatus({
3937
3960
  code: _sentry_core.SPAN_STATUS_ERROR,
3938
3961
  message: "internal_error"
3939
3962
  });
3940
- exitSpan(runId);
3963
+ exitSpan(runId, { error });
3941
3964
  },
3942
3965
  handleToolStart(tool, input, runId, parentRunId, tags, metadata, runName) {
3943
3966
  if (metadata?.__sentry_langgraph__) return;
3944
- const { recordInputs, recordOutputs } = resolveRecording({
3967
+ const call = {
3945
3968
  operation: "execute_tool",
3946
3969
  serialized: tool,
3947
3970
  input,
@@ -3949,7 +3972,8 @@ function createLangChainCallbackHandler(options = {}) {
3949
3972
  parentRunId,
3950
3973
  tags,
3951
3974
  metadata
3952
- });
3975
+ };
3976
+ const { recordInputs, recordOutputs } = resolveRecording(call);
3953
3977
  const toolName = runName || tool.name || "unknown_tool";
3954
3978
  const attributes = {
3955
3979
  ...getAgentNameFromMetadata(metadata),
@@ -3959,7 +3983,7 @@ function createLangChainCallbackHandler(options = {}) {
3959
3983
  [_sentry_conventions_attributes.GEN_AI_TOOL_NAME]: toolName
3960
3984
  };
3961
3985
  if (recordInputs) attributes[_sentry_conventions_attributes.GEN_AI_TOOL_CALL_ARGUMENTS] = input;
3962
- startRunSpan(runId, parentRunId, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3986
+ startRunSpan(call, recordOutputs, () => (0, _sentry_core.startInactiveSpan)({
3963
3987
  name: `execute_tool ${toolName}`,
3964
3988
  attributes: {
3965
3989
  ...attributes,
@@ -3977,15 +4001,15 @@ function createLangChainCallbackHandler(options = {}) {
3977
4001
  span.setAttributes({ [_sentry_conventions_attributes.GEN_AI_TOOL_CALL_RESULT]: (0, _sentry_core.stringify)(content, String) });
3978
4002
  }
3979
4003
  }
3980
- exitSpan(runId);
4004
+ exitSpan(runId, { response: output });
3981
4005
  },
3982
- handleToolError(_error, runId) {
4006
+ handleToolError(error, runId) {
3983
4007
  const span = runs.get(runId)?.span;
3984
4008
  if (span?.isRecording()) span.setStatus({
3985
4009
  code: _sentry_core.SPAN_STATUS_ERROR,
3986
4010
  message: "internal_error"
3987
4011
  });
3988
- exitSpan(runId);
4012
+ exitSpan(runId, { error });
3989
4013
  },
3990
4014
  copy() {
3991
4015
  return handler;
@@ -4228,11 +4252,15 @@ function getAgentSpanOptions(args, extraAttributes) {
4228
4252
  }
4229
4253
  /** Decides for one `invoke()`/`stream()` call, from its arguments as passed. */
4230
4254
  function resolveGraphCallRecording(options, args) {
4231
- return resolveGenAiCallRecording(options, {
4255
+ const call = {
4232
4256
  operation: "invoke_agent",
4233
4257
  input: args[0],
4234
4258
  config: args[1]
4235
- });
4259
+ };
4260
+ return {
4261
+ call,
4262
+ recording: resolveGenAiCallRecording(options, call)
4263
+ };
4236
4264
  }
4237
4265
  /** Sets the request attributes on an agent span and injects the callback handler into the call's config. */
4238
4266
  function prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler) {
@@ -4286,7 +4314,7 @@ function prepareAgentSpan(span, args, graphInstance, compileOptions, recording,
4286
4314
  function instrumentCompiledGraphStream(originalStream, graphInstance, compileOptions, options, llm, sentryCallbackHandler) {
4287
4315
  return new Proxy(originalStream, { apply(target, thisArg, args) {
4288
4316
  if (isInvokeInternalStream(graphInstance)) return Reflect.apply(target, thisArg, args);
4289
- const recording = resolveGraphCallRecording(options, args);
4317
+ const { call, recording } = resolveGraphCallRecording(options, args);
4290
4318
  return (0, _sentry_core.startSpanManual)(getAgentSpanOptions(args, { [_sentry_conventions_attributes.GEN_AI_RESPONSE_STREAMING]: true }), async (span) => {
4291
4319
  let inputMessages = null;
4292
4320
  let stream;
@@ -4302,6 +4330,7 @@ function instrumentCompiledGraphStream(originalStream, graphInstance, compileOpt
4302
4330
  });
4303
4331
  } else if (outcome && recording.recordOutputs) setResponseAttributes(span, inputMessages, outcome.outputs);
4304
4332
  } catch {}
4333
+ runGenAiSpanEnd(options, span, call, outcome && "error" in outcome ? { error: outcome.error } : { response: outcome?.outputs });
4305
4334
  span.end();
4306
4335
  inputMessages = null;
4307
4336
  };
@@ -4324,6 +4353,7 @@ function instrumentCompiledGraphStream(originalStream, graphInstance, compileOpt
4324
4353
  };
4325
4354
  try {
4326
4355
  inputMessages = prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler);
4356
+ runGenAiSpanStart(options, span, call);
4327
4357
  const config = args[1];
4328
4358
  config.callbacks = _INTERNAL_addLangChainCallbackHandler(config.callbacks, listener);
4329
4359
  stream = await Reflect.apply(target, thisArg, args);
@@ -4412,18 +4442,21 @@ function instrumentCompiledGraph(graph, compileOptions, options, llm, sentryCall
4412
4442
  */
4413
4443
  function instrumentCompiledGraphInvoke(originalInvoke, graphInstance, compileOptions, options, llm, sentryCallbackHandler) {
4414
4444
  return new Proxy(originalInvoke, { apply(target, thisArg, args) {
4415
- const recording = resolveGraphCallRecording(options, args);
4445
+ const { call, recording } = resolveGraphCallRecording(options, args);
4416
4446
  return (0, _sentry_core.startSpan)(getAgentSpanOptions(args), async (span) => {
4417
4447
  try {
4418
4448
  const inputMessages = prepareAgentSpan(span, args, graphInstance, compileOptions, recording, llm, sentryCallbackHandler);
4449
+ runGenAiSpanStart(options, span, call);
4419
4450
  const result = await callInvoke(graphInstance, () => Reflect.apply(target, thisArg, args));
4420
4451
  if (recording.recordOutputs) setResponseAttributes(span, inputMessages, result);
4452
+ runGenAiSpanEnd(options, span, call, { response: result });
4421
4453
  return result;
4422
4454
  } catch (error) {
4423
4455
  span.setStatus({
4424
4456
  code: _sentry_core.SPAN_STATUS_ERROR,
4425
4457
  message: "internal_error"
4426
4458
  });
4459
+ runGenAiSpanEnd(options, span, call, { error });
4427
4460
  throw error;
4428
4461
  }
4429
4462
  });
@@ -5420,7 +5453,7 @@ const MAX_SUMMARY_LENGTH = 255;
5420
5453
  const IDENTIFIER = "(?:\"[^\"]*\"|'[^']*'|`[^`]*`|[^\\s(,;).'\"`]+)";
5421
5454
  const TABLE_NAME = `${IDENTIFIER}(?:\\.${IDENTIFIER})*`;
5422
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");
5423
- const INSERT_RE = new RegExp(`^\\s*(?<operation>INSERT|REPLACE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+INTO\\s+(?<table>${TABLE_NAME})`, "i");
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");
5424
5457
  const UPDATE_RE = new RegExp(`^\\s*(?<operation>UPDATE)(?:\\s+OR\\s+(?:ROLLBACK|ABORT|FAIL|IGNORE|REPLACE))?\\s+(?<table>${TABLE_NAME})`, "i");
5425
5458
  const DELETE_RE = new RegExp(`^\\s*(?<operation>DELETE)\\s+FROM\\s+(?<table>${TABLE_NAME})`, "i");
5426
5459
  const SELECT_RE = /^\s*(?:\(\s*)?(?<operation>SELECT)\b/i;
@@ -5563,6 +5596,7 @@ function toSqlDialect(system) {
5563
5596
  if (system === "mssql" || system === "sqlserver" || system === "microsoft.sql_server") return "mssql";
5564
5597
  return "standard";
5565
5598
  }
5599
+ const NO_RULES = {};
5566
5600
  const DOLLAR_QUOTE_RE = /\$(?:[A-Za-z_]\w*)?\$/y;
5567
5601
  /**
5568
5602
  * Returns the index just past the run's closing `delimiter`, or -1 if the run never closes. The
@@ -5583,6 +5617,18 @@ function findQuotedRunEnd(sql, start, delimiter, backslashEscapes) {
5583
5617
  }
5584
5618
  return -1;
5585
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
+ }
5586
5632
  /**
5587
5633
  * Replaces every string literal with `?` and drops every comment, in one pass.
5588
5634
  *
@@ -5595,24 +5641,25 @@ function findQuotedRunEnd(sql, start, delimiter, backslashEscapes) {
5595
5641
  * built from.
5596
5642
  */
5597
5643
  function stripLiteralsAndComments(sql, dialect) {
5598
- const isMysql = dialect === "mysql";
5644
+ const [base, rules] = typeof dialect === "string" ? [dialect, NO_RULES] : ["standard", dialect];
5645
+ const isMysql = base === "mysql";
5646
+ const backslashEscapes = !!rules.backslashEscapes;
5599
5647
  const out = [];
5600
5648
  let i = 0;
5601
5649
  while (i < sql.length) {
5602
5650
  const char = sql[i];
5603
5651
  const next = sql[i + 1];
5604
- if (char === "-" && next === "-" || isMysql && char === "#") {
5652
+ if (char === "-" && next === "-" || (isMysql || rules.hashComments) && char === "#") {
5605
5653
  const lineEnd = sql.indexOf("\n", i);
5606
5654
  i = lineEnd === -1 ? sql.length : lineEnd;
5607
5655
  continue;
5608
5656
  }
5609
5657
  if (char === "/" && next === "*") {
5610
- const commentEnd = sql.indexOf("*/", i + 2);
5611
- i = commentEnd === -1 ? sql.length : commentEnd + 2;
5658
+ i = findBlockCommentEnd(sql, i, !!rules.nestedComments);
5612
5659
  continue;
5613
5660
  }
5614
- if (dialect === "standard" && char === "$" && !isIdentifierChar(sql[i - 1])) {
5615
- const tag = matchDollarQuoteTag(sql, i);
5661
+ if (base === "standard" && char === "$" && !isIdentifierChar(sql[i - 1])) {
5662
+ const tag = matchDollarQuoteTag(sql, i, rules.dollarQuote);
5616
5663
  if (tag) {
5617
5664
  const bodyEnd = sql.indexOf(tag, i + tag.length);
5618
5665
  i = bodyEnd === -1 ? sql.length : bodyEnd + tag.length;
@@ -5620,21 +5667,28 @@ function stripLiteralsAndComments(sql, dialect) {
5620
5667
  continue;
5621
5668
  }
5622
5669
  }
5623
- const identifierCloser = getIdentifierCloser(char, dialect);
5670
+ const identifierCloser = getIdentifierCloser(char, base);
5624
5671
  if (identifierCloser) {
5625
- const runEnd = findQuotedRunEnd(sql, i, identifierCloser, false);
5672
+ const runEnd = findQuotedRunEnd(sql, i, identifierCloser, backslashEscapes);
5626
5673
  out.push(runEnd === -1 ? "?" : sql.slice(i, runEnd));
5627
5674
  i = runEnd === -1 ? sql.length : runEnd;
5628
5675
  continue;
5629
5676
  }
5630
5677
  if (char === "'" || char === "\"" && isMysql) {
5631
- const prefix = char === "'" ? getLiteralPrefix(out, dialect) : void 0;
5678
+ const prefix = char === "'" ? getLiteralPrefix(out, base) : void 0;
5632
5679
  if (prefix) out.pop();
5633
- const runEnd = findQuotedRunEnd(sql, i, char, isMysql || prefix === "E");
5680
+ const runEnd = findQuotedRunEnd(sql, i, char, isMysql || backslashEscapes || prefix === "E");
5634
5681
  i = runEnd === -1 ? sql.length : runEnd;
5635
5682
  out.push("?");
5636
5683
  continue;
5637
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;
5638
5692
  out.push(char);
5639
5693
  i++;
5640
5694
  }
@@ -5655,9 +5709,9 @@ function isIdentifierChar(char) {
5655
5709
  return char !== void 0 && /[\w$]/.test(char);
5656
5710
  }
5657
5711
  /** Returns the opening dollar-quote tag at `start` (`$$` or `$tag$`), or undefined if there is none. */
5658
- function matchDollarQuoteTag(sql, start) {
5659
- DOLLAR_QUOTE_RE.lastIndex = start;
5660
- return DOLLAR_QUOTE_RE.exec(sql)?.[0];
5712
+ function matchDollarQuoteTag(sql, start, pattern = DOLLAR_QUOTE_RE) {
5713
+ pattern.lastIndex = start;
5714
+ return pattern.exec(sql)?.[0];
5661
5715
  }
5662
5716
  /**
5663
5717
  * Returns the literal-prefix character immediately before a `'`, if there is one: `X`/`B` for
@@ -5680,7 +5734,7 @@ function getLiteralPrefix(out, dialect) {
5680
5734
  * booleans) are sanitized.
5681
5735
  *
5682
5736
  * Pass `dialect` when the statement comes from a driver whose literals are not standard-quoted;
5683
- * see {@link SqlDialect}.
5737
+ * see {@link SqlDialect} and {@link SqlLexerRules}.
5684
5738
  */
5685
5739
  function sanitizeSqlQuery(sqlQuery, dialect = "standard") {
5686
5740
  if (!sqlQuery) return "Unknown SQL Query";
@@ -7223,6 +7277,12 @@ Object.defineProperty(exports, "isDeno", {
7223
7277
  return isDeno;
7224
7278
  }
7225
7279
  });
7280
+ Object.defineProperty(exports, "isIdentifierChar", {
7281
+ enumerable: true,
7282
+ get: function() {
7283
+ return isIdentifierChar;
7284
+ }
7285
+ });
7226
7286
  Object.defineProperty(exports, "isInsideManualLangGraphInstrumentation", {
7227
7287
  enumerable: true,
7228
7288
  get: function() {