@sentry/server-utils 11.13.0 → 11.14.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 (88) hide show
  1. package/build/cjs/chunks/config.js +19 -5
  2. package/build/cjs/chunks/config.js.map +1 -1
  3. package/build/cjs/chunks/exports.js +72 -26
  4. package/build/cjs/chunks/exports.js.map +1 -1
  5. package/build/cjs/chunks/moduleInjectedTransform.js +6 -5
  6. package/build/cjs/chunks/moduleInjectedTransform.js.map +1 -1
  7. package/build/cjs/index.js +161 -65
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/orchestrion/bundler/rollup.js +4 -4
  10. package/build/cjs/orchestrion/bundler/rollup.js.map +1 -1
  11. package/build/esm/ai/google-genai/constants.js +2 -1
  12. package/build/esm/ai/google-genai/constants.js.map +1 -1
  13. package/build/esm/ai/google-genai/decisions.js +25 -0
  14. package/build/esm/ai/google-genai/decisions.js.map +1 -0
  15. package/build/esm/ai/google-genai/index.js +16 -5
  16. package/build/esm/ai/google-genai/index.js.map +1 -1
  17. package/build/esm/ai/mistral/index.js +9 -8
  18. package/build/esm/ai/mistral/index.js.map +1 -1
  19. package/build/esm/ai/mistral/streaming.js +3 -7
  20. package/build/esm/ai/mistral/streaming.js.map +1 -1
  21. package/build/esm/ai/mistral/utils.js +9 -1
  22. package/build/esm/ai/mistral/utils.js.map +1 -1
  23. package/build/esm/ai/vercel-ai/index.js +3 -1
  24. package/build/esm/ai/vercel-ai/index.js.map +1 -1
  25. package/build/esm/ai/workers-ai/index.js +8 -7
  26. package/build/esm/ai/workers-ai/index.js.map +1 -1
  27. package/build/esm/ai/workers-ai/streaming.js +3 -7
  28. package/build/esm/ai/workers-ai/streaming.js.map +1 -1
  29. package/build/esm/index.js +3 -2
  30. package/build/esm/index.js.map +1 -1
  31. package/build/esm/integrations/cron.js +2 -2
  32. package/build/esm/integrations/cron.js.map +1 -1
  33. package/build/esm/integrations/google-genai.js +10 -6
  34. package/build/esm/integrations/google-genai.js.map +1 -1
  35. package/build/esm/integrations/mistral.js +4 -3
  36. package/build/esm/integrations/mistral.js.map +1 -1
  37. package/build/esm/integrations/node-cron.js +5 -4
  38. package/build/esm/integrations/node-cron.js.map +1 -1
  39. package/build/esm/integrations/node-schedule.js +2 -2
  40. package/build/esm/integrations/node-schedule.js.map +1 -1
  41. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js +9 -1
  42. package/build/esm/integrations/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
  43. package/build/esm/orchestrion/bundler/moduleInjectedTransform.js +6 -5
  44. package/build/esm/orchestrion/bundler/moduleInjectedTransform.js.map +1 -1
  45. package/build/esm/orchestrion/bundler/rollup.js +4 -4
  46. package/build/esm/orchestrion/bundler/rollup.js.map +1 -1
  47. package/build/esm/orchestrion/config/google-genai.js +19 -5
  48. package/build/esm/orchestrion/config/google-genai.js.map +1 -1
  49. package/build/esm/package.json +1 -1
  50. package/build/esm/utils/cronMonitoring.js +128 -50
  51. package/build/esm/utils/cronMonitoring.js.map +1 -1
  52. package/build/types/ai/google-genai/constants.d.ts +3 -0
  53. package/build/types/ai/google-genai/constants.d.ts.map +1 -1
  54. package/build/types/ai/google-genai/decisions.d.ts +8 -0
  55. package/build/types/ai/google-genai/decisions.d.ts.map +1 -0
  56. package/build/types/ai/google-genai/index.d.ts +3 -1
  57. package/build/types/ai/google-genai/index.d.ts.map +1 -1
  58. package/build/types/ai/mistral/index.d.ts.map +1 -1
  59. package/build/types/ai/mistral/streaming.d.ts +1 -1
  60. package/build/types/ai/mistral/streaming.d.ts.map +1 -1
  61. package/build/types/ai/mistral/utils.d.ts +5 -0
  62. package/build/types/ai/mistral/utils.d.ts.map +1 -1
  63. package/build/types/ai/vercel-ai/index.d.ts.map +1 -1
  64. package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts +3 -0
  65. package/build/types/ai/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
  66. package/build/types/ai/workers-ai/index.d.ts.map +1 -1
  67. package/build/types/ai/workers-ai/streaming.d.ts +1 -1
  68. package/build/types/ai/workers-ai/streaming.d.ts.map +1 -1
  69. package/build/types/index.d.ts +3 -1
  70. package/build/types/index.d.ts.map +1 -1
  71. package/build/types/integrations/cron.d.ts.map +1 -1
  72. package/build/types/integrations/google-genai.d.ts +3 -3
  73. package/build/types/integrations/google-genai.d.ts.map +1 -1
  74. package/build/types/integrations/mistral.d.ts.map +1 -1
  75. package/build/types/integrations/node-cron.d.ts +1 -1
  76. package/build/types/integrations/node-cron.d.ts.map +1 -1
  77. package/build/types/integrations/node-schedule.d.ts.map +1 -1
  78. package/build/types/integrations/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
  79. package/build/types/orchestrion/bundler/moduleInjectedTransform.d.ts.map +1 -1
  80. package/build/types/orchestrion/bundler/rollup.d.ts +3 -3
  81. package/build/types/orchestrion/bundler/rollup.d.ts.map +1 -1
  82. package/build/types/orchestrion/channels.d.ts +1 -0
  83. package/build/types/orchestrion/channels.d.ts.map +1 -1
  84. package/build/types/orchestrion/config/google-genai.d.ts +13 -0
  85. package/build/types/orchestrion/config/google-genai.d.ts.map +1 -1
  86. package/build/types/utils/cronMonitoring.d.ts +4 -5
  87. package/build/types/utils/cronMonitoring.d.ts.map +1 -1
  88. package/package.json +3 -3
@@ -489,7 +489,7 @@ const GEN_AI_TOOL_CALL_ID_ATTRIBUTE = "gen_ai.tool.call.id";
489
489
  * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`
490
490
  * so both render the same.
491
491
  */
492
- function getDecisionInputMessages(params) {
492
+ function getDecisionInputMessages$1(params) {
493
493
  const questions = Array.isArray(params.questions) ? params.questions.map(toJevQuestionFormat) : params.questions;
494
494
  return getEvaluationInputMessages({
495
495
  state: params.input,
@@ -846,7 +846,7 @@ function extractRequestAttributes$4(args, operationName, recordInputs) {
846
846
  const params = args[0];
847
847
  if (recordInputs) attributes[_sentry_conventions_attributes.GEN_AI_TOOL_DEFINITIONS] = extractAvailableTools(params);
848
848
  Object.assign(attributes, extractRequestParameters$1(params));
849
- if (recordInputs && operationName === "decide") attributes[_sentry_conventions_attributes.GEN_AI_INPUT_MESSAGES] = getDecisionInputMessages(params);
849
+ if (recordInputs && operationName === "decide") attributes[_sentry_conventions_attributes.GEN_AI_INPUT_MESSAGES] = getDecisionInputMessages$1(params);
850
850
  } else attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] = "unknown";
851
851
  return attributes;
852
852
  }
@@ -1574,9 +1574,29 @@ const GOOGLE_GENAI_METHOD_REGISTRY = {
1574
1574
  "chat.sendMessageStream": {
1575
1575
  operation: "chat",
1576
1576
  streaming: true
1577
- }
1577
+ },
1578
+ "decisions.create": { operation: "decide" }
1578
1579
  };
1579
1580
  const GOOGLE_GENAI_SYSTEM_NAME = "google_genai";
1581
+ // src/ai/google-genai/decisions.ts
1582
+ /**
1583
+ * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state`
1584
+ * so both render the same.
1585
+ */
1586
+ function getDecisionInputMessages(params) {
1587
+ return getEvaluationInputMessages({
1588
+ state: params.input,
1589
+ questions: params.questions
1590
+ });
1591
+ }
1592
+ function addDecisionResponseAttributes(span, response, recordOutputs) {
1593
+ if (!(0, _sentry_core.isObjectLike)(response)) return;
1594
+ if ((0, _sentry_core.isObjectLike)(response.usage)) {
1595
+ const usage = response.usage;
1596
+ span.setAttributes(getTokenUsageAttributes(usage.total_input_tokens, usage.total_output_tokens, void 0, usage.total_cached_tokens, usage.total_tokens));
1597
+ }
1598
+ if (recordOutputs && response.answers !== void 0) span.setAttribute(_sentry_conventions_attributes.GEN_AI_OUTPUT_MESSAGES, getEvaluationOutputMessages(response.answers));
1599
+ }
1580
1600
  // src/ai/google-genai/utils.ts
1581
1601
  function normalizeRole(role) {
1582
1602
  return role === "model" ? "assistant" : role;
@@ -1851,6 +1871,8 @@ function extractRequestAttributes$2(operationName, params, context, recordInputs
1851
1871
  attributes[_sentry_conventions_attributes.GEN_AI_TOOL_DEFINITIONS] = JSON.stringify(functionDeclarations);
1852
1872
  }
1853
1873
  }
1874
+ const decisionInput = recordInputs && operationName === "decide" ? getDecisionInputMessages(params) : void 0;
1875
+ if (decisionInput) attributes[_sentry_conventions_attributes.GEN_AI_INPUT_MESSAGES] = decisionInput;
1854
1876
  } else attributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] = extractModel({}, context);
1855
1877
  return attributes;
1856
1878
  }
@@ -1882,8 +1904,12 @@ function addPrivateRequestAttributes(span, params, operationName) {
1882
1904
  * Add response attributes from the Google GenAI response
1883
1905
  * @see https://github.com/googleapis/js-genai/blob/v1.19.0/src/types.ts#L2313
1884
1906
  */
1885
- function addResponseAttributes$3(span, response, recordOutputs) {
1907
+ function addResponseAttributes$3(span, response, recordOutputs, operationName) {
1886
1908
  if (!response || typeof response !== "object") return;
1909
+ if (operationName === "decide") {
1910
+ addDecisionResponseAttributes(span, response, !!recordOutputs);
1911
+ return;
1912
+ }
1887
1913
  if (response.modelVersion) span.setAttribute(_sentry_conventions_attributes.GEN_AI_RESPONSE_MODEL, response.modelVersion);
1888
1914
  if (response.usageMetadata && typeof response.usageMetadata === "object") {
1889
1915
  const usage = response.usageMetadata;
@@ -1932,6 +1958,10 @@ function resolveChatParams(operationName, params, context) {
1932
1958
  function getAbortSignal(params) {
1933
1959
  return (params?.config)?.abortSignal;
1934
1960
  }
1961
+ /** `decisions.create` takes its abort signal in its request options, not in a `config`. */
1962
+ function getCallAbortSignal(operationName, params, requestOptions) {
1963
+ return operationName === "decide" ? getRequestSignal(requestOptions) : getAbortSignal(params);
1964
+ }
1935
1965
  /**
1936
1966
  * Instrument any async or synchronous genai method with Sentry spans
1937
1967
  * Handles operations like models.generateContent and chat.sendMessage and chats.create
@@ -1943,7 +1973,7 @@ function instrumentMethod$1(originalMethod, methodPath, instrumentedMethod, cont
1943
1973
  const operationName = instrumentedMethod.operation || "unknown";
1944
1974
  const params = args[0];
1945
1975
  const attributeParams = resolveChatParams(operationName, params, context);
1946
- const abortSignal = getAbortSignal(attributeParams);
1976
+ const abortSignal = getCallAbortSignal(operationName, attributeParams, args[1]);
1947
1977
  const requestAttributes = extractRequestAttributes$2(operationName, attributeParams, context, !!options.recordInputs);
1948
1978
  const model = requestAttributes[_sentry_conventions_attributes.GEN_AI_REQUEST_MODEL] || "unknown";
1949
1979
  const client = (0, _sentry_core.getClient)();
@@ -1969,7 +1999,7 @@ function instrumentMethod$1(originalMethod, methodPath, instrumentedMethod, cont
1969
1999
  }, (span) => {
1970
2000
  if (options.recordInputs && attributeParams) addPrivateRequestAttributes(span, attributeParams, operationName);
1971
2001
  return (0, _sentry_core.handleCallbackErrors)(() => target.apply(context, args), () => span.setStatus(getErrorStatus(abortSignal)), () => {}, (result) => {
1972
- if (!isEmbeddings) addResponseAttributes$3(span, result, options.recordOutputs);
2002
+ if (!isEmbeddings) addResponseAttributes$3(span, result, options.recordOutputs, operationName);
1973
2003
  });
1974
2004
  });
1975
2005
  } });
@@ -2094,6 +2124,14 @@ function getSpanName$1(operationName, attributes) {
2094
2124
  return `${operationName} ${model}`;
2095
2125
  }
2096
2126
  /**
2127
+ * Reads the caller's signal from Mistral's request options. The SDK spreads `options` over
2128
+ * `options.fetchOptions`, so a top-level `signal` wins.
2129
+ */
2130
+ function getMistralRequestSignal(requestOptions) {
2131
+ const options = requestOptions;
2132
+ return options?.signal ?? options?.fetchOptions?.signal;
2133
+ }
2134
+ /**
2097
2135
  * Extract request parameters. Mistral request fields are camelCase.
2098
2136
  */
2099
2137
  function extractRequestParameters(params) {
@@ -2286,7 +2324,7 @@ function instrumentedSource(readable) {
2286
2324
  *
2287
2325
  * Returns `false` for a value that is not a stream, leaving it untouched.
2288
2326
  */
2289
- function instrumentEventStream(stream, span, recordOutputs) {
2327
+ function instrumentEventStream(stream, span, recordOutputs, abortSignal) {
2290
2328
  if (!isAsyncIterable(stream)) return false;
2291
2329
  const state = createStreamingState();
2292
2330
  let consumer;
@@ -2302,10 +2340,7 @@ function instrumentEventStream(stream, span, recordOutputs) {
2302
2340
  const settle = (error) => {
2303
2341
  if (settled) return;
2304
2342
  settled = true;
2305
- if (error !== void 0 && !cancelled) span.setStatus({
2306
- code: _sentry_core.SPAN_STATUS_ERROR,
2307
- message: "internal_error"
2308
- });
2343
+ if (error !== void 0 && !cancelled) span.setStatus(getErrorStatus(abortSignal));
2309
2344
  const toolCalls = Object.values(state.toolCalls);
2310
2345
  if (recordOutputs) setOutputMessagesAttribute$1(span, {
2311
2346
  responseText: state.responseTexts.join(""),
@@ -2399,6 +2434,7 @@ function instrumentMethod(originalMethod, instrumentedMethod, context, options)
2399
2434
  const isStreamRequested = !!instrumentedMethod.streaming;
2400
2435
  const requestAttributes = extractRequestAttributes$1(args, operationName, !!options.recordInputs, isStreamRequested);
2401
2436
  const params = args[0];
2437
+ const abortSignal = getMistralRequestSignal(args[1]);
2402
2438
  const spanConfig = {
2403
2439
  name: getSpanName$1(operationName, requestAttributes),
2404
2440
  op: getGenAiSpanOp(operationName),
@@ -2410,13 +2446,10 @@ function instrumentMethod(originalMethod, instrumentedMethod, context, options)
2410
2446
  originalResult = originalMethod.apply(context, args);
2411
2447
  if (options.recordInputs && params) addRequestAttributes$1(span, params, operationName);
2412
2448
  return originalResult.then((result) => {
2413
- if (!instrumentEventStream(result, span, options.recordOutputs ?? false)) span.end();
2449
+ if (!instrumentEventStream(result, span, options.recordOutputs ?? false, abortSignal)) span.end();
2414
2450
  return result;
2415
2451
  }, (error) => {
2416
- span.setStatus({
2417
- code: _sentry_core.SPAN_STATUS_ERROR,
2418
- message: "internal_error"
2419
- });
2452
+ span.setStatus(getErrorStatus(abortSignal));
2420
2453
  span.end();
2421
2454
  throw error;
2422
2455
  });
@@ -2430,6 +2463,9 @@ function instrumentMethod(originalMethod, instrumentedMethod, context, options)
2430
2463
  return originalResult.then((result) => {
2431
2464
  addResponseAttributes$2(span, result, options.recordOutputs);
2432
2465
  return result;
2466
+ }, (error) => {
2467
+ span.setStatus(getErrorStatus(abortSignal));
2468
+ throw error;
2433
2469
  });
2434
2470
  });
2435
2471
  return wrapPromiseWithMethods(originalResult, instrumentedPromise);
@@ -2787,7 +2823,7 @@ function processLine(line, state, recordOutputs, toolCallAccumulator) {
2787
2823
  *
2788
2824
  * The span is ended once the consumer finishes reading (or cancels) the stream.
2789
2825
  */
2790
- function instrumentWorkersAiStream(stream, span, recordOutputs) {
2826
+ function instrumentWorkersAiStream(stream, span, recordOutputs, abortSignal) {
2791
2827
  const reader = stream.getReader();
2792
2828
  const decoder = new TextDecoder();
2793
2829
  const state = {
@@ -2840,10 +2876,7 @@ function instrumentWorkersAiStream(stream, span, recordOutputs) {
2840
2876
  flushBuffer(false);
2841
2877
  controller.enqueue(value);
2842
2878
  } catch (error) {
2843
- span.setStatus({
2844
- code: _sentry_core.SPAN_STATUS_ERROR,
2845
- message: "internal_error"
2846
- });
2879
+ span.setStatus(getErrorStatus(abortSignal));
2847
2880
  finish();
2848
2881
  controller.error(error);
2849
2882
  }
@@ -2865,6 +2898,7 @@ function instrumentRun(originalRun, context, options) {
2865
2898
  const operationName = getOperationName(model, inputs);
2866
2899
  const requestAttributes = extractRequestAttributes(model, inputs, operationName);
2867
2900
  const modelName = typeof model === "string" && model ? model : "unknown";
2901
+ const abortSignal = getRequestSignal(runOptions);
2868
2902
  const client = (0, _sentry_core.getClient)();
2869
2903
  const isStreamRequested = !!inputs && typeof inputs === "object" && inputs.stream === true;
2870
2904
  const returnsRawResponse = !!runOptions && typeof runOptions === "object" && (runOptions.returnRawResponse === true || runOptions.websocket === true);
@@ -2877,10 +2911,7 @@ function instrumentRun(originalRun, context, options) {
2877
2911
  };
2878
2912
  if (isStreamRequested && !returnsRawResponse) return (0, _sentry_core.startSpanManual)(spanConfig, (span) => {
2879
2913
  const handleError = (error) => {
2880
- span.setStatus({
2881
- code: _sentry_core.SPAN_STATUS_ERROR,
2882
- message: "internal_error"
2883
- });
2914
+ span.setStatus(getErrorStatus(abortSignal));
2884
2915
  span.end();
2885
2916
  throw error;
2886
2917
  };
@@ -2892,7 +2923,7 @@ function instrumentRun(originalRun, context, options) {
2892
2923
  }
2893
2924
  if (options.recordInputs) addRequestAttributes(span, inputs, operationName);
2894
2925
  return originalResult.then((result) => {
2895
- if (isReadableStream(result)) return instrumentWorkersAiStream(result, span, options.recordOutputs);
2926
+ if (isReadableStream(result)) return instrumentWorkersAiStream(result, span, options.recordOutputs, abortSignal);
2896
2927
  addResponseAttributes(span, result, options.recordOutputs, operationName);
2897
2928
  span.end();
2898
2929
  return result;
@@ -2904,6 +2935,9 @@ function instrumentRun(originalRun, context, options) {
2904
2935
  return originalResult.then((result) => {
2905
2936
  if (!returnsRawResponse) addResponseAttributes(span, result, options.recordOutputs, operationName);
2906
2937
  return result;
2938
+ }, (error) => {
2939
+ span.setStatus(getErrorStatus(abortSignal));
2940
+ throw error;
2907
2941
  });
2908
2942
  });
2909
2943
  };
@@ -6570,6 +6604,12 @@ Object.defineProperty(exports, "getAbortSignal", {
6570
6604
  return getAbortSignal;
6571
6605
  }
6572
6606
  });
6607
+ Object.defineProperty(exports, "getCallAbortSignal", {
6608
+ enumerable: true,
6609
+ get: function() {
6610
+ return getCallAbortSignal;
6611
+ }
6612
+ });
6573
6613
  Object.defineProperty(exports, "getConversationIdMetadataFromConfig", {
6574
6614
  enumerable: true,
6575
6615
  get: function() {
@@ -6624,6 +6664,12 @@ Object.defineProperty(exports, "getMiddlewareFlags", {
6624
6664
  return getMiddlewareFlags;
6625
6665
  }
6626
6666
  });
6667
+ Object.defineProperty(exports, "getMistralRequestSignal", {
6668
+ enumerable: true,
6669
+ get: function() {
6670
+ return getMistralRequestSignal;
6671
+ }
6672
+ });
6627
6673
  Object.defineProperty(exports, "getOrchestrionInjectedModules", {
6628
6674
  enumerable: true,
6629
6675
  get: function() {