@sentry/node 9.8.0 → 9.10.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 (139) hide show
  1. package/build/cjs/index.js +2 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/anr/index.js +1 -1
  4. package/build/cjs/integrations/console.js +1 -1
  5. package/build/cjs/integrations/console.js.map +1 -1
  6. package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  7. package/build/cjs/integrations/tracing/connect.js +1 -1
  8. package/build/cjs/integrations/tracing/connect.js.map +1 -1
  9. package/build/cjs/integrations/tracing/dataloader.js +24 -18
  10. package/build/cjs/integrations/tracing/dataloader.js.map +1 -1
  11. package/build/cjs/integrations/tracing/fastify.js +28 -8
  12. package/build/cjs/integrations/tracing/fastify.js.map +1 -1
  13. package/build/cjs/integrations/tracing/genericPool.js +16 -11
  14. package/build/cjs/integrations/tracing/genericPool.js.map +1 -1
  15. package/build/cjs/integrations/tracing/knex.js +14 -9
  16. package/build/cjs/integrations/tracing/knex.js.map +1 -1
  17. package/build/cjs/integrations/tracing/prisma.js +19 -7
  18. package/build/cjs/integrations/tracing/prisma.js.map +1 -1
  19. package/build/cjs/integrations/tracing/tedious.js +18 -13
  20. package/build/cjs/integrations/tracing/tedious.js.map +1 -1
  21. package/build/cjs/integrations/tracing/vercelai/index.js +135 -134
  22. package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -1
  23. package/build/cjs/integrations/tracing/vercelai/instrumentation.js +20 -5
  24. package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -1
  25. package/build/cjs/log.js +200 -0
  26. package/build/cjs/log.js.map +1 -0
  27. package/build/cjs/otel/instrument.js +54 -3
  28. package/build/cjs/otel/instrument.js.map +1 -1
  29. package/build/cjs/sdk/index.js +15 -33
  30. package/build/cjs/sdk/index.js.map +1 -1
  31. package/build/esm/index.js +2 -0
  32. package/build/esm/index.js.map +1 -1
  33. package/build/esm/integrations/anr/index.js +1 -1
  34. package/build/esm/integrations/anr/worker-script.js +2 -2
  35. package/build/esm/integrations/console.js +2 -2
  36. package/build/esm/integrations/console.js.map +1 -1
  37. package/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  38. package/build/esm/integrations/local-variables/worker-script.js +2 -2
  39. package/build/esm/integrations/tracing/connect.js +1 -1
  40. package/build/esm/integrations/tracing/connect.js.map +1 -1
  41. package/build/esm/integrations/tracing/dataloader.js +26 -20
  42. package/build/esm/integrations/tracing/dataloader.js.map +1 -1
  43. package/build/esm/integrations/tracing/fastify.js +28 -8
  44. package/build/esm/integrations/tracing/fastify.js.map +1 -1
  45. package/build/esm/integrations/tracing/genericPool.js +17 -12
  46. package/build/esm/integrations/tracing/genericPool.js.map +1 -1
  47. package/build/esm/integrations/tracing/knex.js +15 -10
  48. package/build/esm/integrations/tracing/knex.js.map +1 -1
  49. package/build/esm/integrations/tracing/prisma.js +19 -7
  50. package/build/esm/integrations/tracing/prisma.js.map +1 -1
  51. package/build/esm/integrations/tracing/tedious.js +19 -14
  52. package/build/esm/integrations/tracing/tedious.js.map +1 -1
  53. package/build/esm/integrations/tracing/vercelai/index.js +136 -135
  54. package/build/esm/integrations/tracing/vercelai/index.js.map +1 -1
  55. package/build/esm/integrations/tracing/vercelai/instrumentation.js +21 -6
  56. package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -1
  57. package/build/esm/log.js +193 -0
  58. package/build/esm/log.js.map +1 -0
  59. package/build/esm/otel/instrument.js +54 -4
  60. package/build/esm/otel/instrument.js.map +1 -1
  61. package/build/esm/package.json +1 -1
  62. package/build/esm/sdk/index.js +16 -34
  63. package/build/esm/sdk/index.js.map +1 -1
  64. package/build/types/index.d.ts +2 -0
  65. package/build/types/index.d.ts.map +1 -1
  66. package/build/types/integrations/console.d.ts.map +1 -1
  67. package/build/types/integrations/http/index.d.ts +1 -1
  68. package/build/types/integrations/tracing/amqplib.d.ts +2 -1
  69. package/build/types/integrations/tracing/amqplib.d.ts.map +1 -1
  70. package/build/types/integrations/tracing/connect.d.ts +2 -1
  71. package/build/types/integrations/tracing/connect.d.ts.map +1 -1
  72. package/build/types/integrations/tracing/dataloader.d.ts +2 -1
  73. package/build/types/integrations/tracing/dataloader.d.ts.map +1 -1
  74. package/build/types/integrations/tracing/express.d.ts +4 -2
  75. package/build/types/integrations/tracing/express.d.ts.map +1 -1
  76. package/build/types/integrations/tracing/fastify.d.ts +60 -3
  77. package/build/types/integrations/tracing/fastify.d.ts.map +1 -1
  78. package/build/types/integrations/tracing/genericPool.d.ts +2 -1
  79. package/build/types/integrations/tracing/genericPool.d.ts.map +1 -1
  80. package/build/types/integrations/tracing/graphql.d.ts +1 -1
  81. package/build/types/integrations/tracing/hapi/index.d.ts +2 -1
  82. package/build/types/integrations/tracing/hapi/index.d.ts.map +1 -1
  83. package/build/types/integrations/tracing/kafka.d.ts +2 -1
  84. package/build/types/integrations/tracing/kafka.d.ts.map +1 -1
  85. package/build/types/integrations/tracing/knex.d.ts +2 -1
  86. package/build/types/integrations/tracing/knex.d.ts.map +1 -1
  87. package/build/types/integrations/tracing/koa.d.ts +2 -1
  88. package/build/types/integrations/tracing/koa.d.ts.map +1 -1
  89. package/build/types/integrations/tracing/lrumemoizer.d.ts +2 -1
  90. package/build/types/integrations/tracing/lrumemoizer.d.ts.map +1 -1
  91. package/build/types/integrations/tracing/mongo.d.ts +2 -1
  92. package/build/types/integrations/tracing/mongo.d.ts.map +1 -1
  93. package/build/types/integrations/tracing/mongoose.d.ts +2 -1
  94. package/build/types/integrations/tracing/mongoose.d.ts.map +1 -1
  95. package/build/types/integrations/tracing/mysql.d.ts +2 -1
  96. package/build/types/integrations/tracing/mysql.d.ts.map +1 -1
  97. package/build/types/integrations/tracing/mysql2.d.ts +2 -1
  98. package/build/types/integrations/tracing/mysql2.d.ts.map +1 -1
  99. package/build/types/integrations/tracing/postgres.d.ts +2 -1
  100. package/build/types/integrations/tracing/postgres.d.ts.map +1 -1
  101. package/build/types/integrations/tracing/prisma.d.ts +1 -1
  102. package/build/types/integrations/tracing/prisma.d.ts.map +1 -1
  103. package/build/types/integrations/tracing/tedious.d.ts +2 -1
  104. package/build/types/integrations/tracing/tedious.d.ts.map +1 -1
  105. package/build/types/integrations/tracing/vercelai/index.d.ts +2 -1
  106. package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -1
  107. package/build/types/integrations/tracing/vercelai/instrumentation.d.ts +7 -1
  108. package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -1
  109. package/build/types/log.d.ts +151 -0
  110. package/build/types/log.d.ts.map +1 -0
  111. package/build/types/otel/instrument.d.ts +14 -1
  112. package/build/types/otel/instrument.d.ts.map +1 -1
  113. package/build/types/sdk/index.d.ts.map +1 -1
  114. package/build/types-ts3.8/index.d.ts +2 -0
  115. package/build/types-ts3.8/integrations/http/index.d.ts +1 -1
  116. package/build/types-ts3.8/integrations/tracing/amqplib.d.ts +2 -1
  117. package/build/types-ts3.8/integrations/tracing/connect.d.ts +2 -1
  118. package/build/types-ts3.8/integrations/tracing/dataloader.d.ts +2 -1
  119. package/build/types-ts3.8/integrations/tracing/express.d.ts +4 -2
  120. package/build/types-ts3.8/integrations/tracing/fastify.d.ts +60 -3
  121. package/build/types-ts3.8/integrations/tracing/genericPool.d.ts +2 -1
  122. package/build/types-ts3.8/integrations/tracing/graphql.d.ts +1 -1
  123. package/build/types-ts3.8/integrations/tracing/hapi/index.d.ts +2 -1
  124. package/build/types-ts3.8/integrations/tracing/kafka.d.ts +2 -1
  125. package/build/types-ts3.8/integrations/tracing/knex.d.ts +2 -1
  126. package/build/types-ts3.8/integrations/tracing/koa.d.ts +2 -1
  127. package/build/types-ts3.8/integrations/tracing/lrumemoizer.d.ts +2 -1
  128. package/build/types-ts3.8/integrations/tracing/mongo.d.ts +2 -1
  129. package/build/types-ts3.8/integrations/tracing/mongoose.d.ts +2 -1
  130. package/build/types-ts3.8/integrations/tracing/mysql.d.ts +2 -1
  131. package/build/types-ts3.8/integrations/tracing/mysql2.d.ts +2 -1
  132. package/build/types-ts3.8/integrations/tracing/postgres.d.ts +2 -1
  133. package/build/types-ts3.8/integrations/tracing/prisma.d.ts +1 -1
  134. package/build/types-ts3.8/integrations/tracing/tedious.d.ts +2 -1
  135. package/build/types-ts3.8/integrations/tracing/vercelai/index.d.ts +2 -1
  136. package/build/types-ts3.8/integrations/tracing/vercelai/instrumentation.d.ts +7 -1
  137. package/build/types-ts3.8/log.d.ts +158 -0
  138. package/build/types-ts3.8/otel/instrument.d.ts +14 -1
  139. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { defineIntegration, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
2
2
  import { generateInstrumentOnce } from '../../../otel/instrument.js';
3
3
  import { addOriginToSpan } from '../../../utils/addOriginToSpan.js';
4
- import { SentryVercelAiInstrumentation, sentryVercelAiPatched } from './instrumentation.js';
4
+ import { SentryVercelAiInstrumentation } from './instrumentation.js';
5
5
 
6
6
  /* eslint-disable complexity */
7
7
 
@@ -10,145 +10,146 @@ const INTEGRATION_NAME = 'VercelAI';
10
10
  const instrumentVercelAi = generateInstrumentOnce(INTEGRATION_NAME, () => new SentryVercelAiInstrumentation({}));
11
11
 
12
12
  const _vercelAIIntegration = (() => {
13
+ let instrumentation;
14
+
13
15
  return {
14
16
  name: INTEGRATION_NAME,
15
17
  setupOnce() {
16
- instrumentVercelAi();
17
- },
18
- processEvent(event) {
19
- if (event.type === 'transaction' && event.spans?.length) {
20
- for (const span of event.spans) {
21
- const { data: attributes, description: name } = span;
22
-
23
- if (!name || span.origin !== 'auto.vercelai.otel') {
24
- continue;
25
- }
26
-
27
- if (attributes['ai.usage.completionTokens'] != undefined) {
28
- attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];
29
- }
30
- if (attributes['ai.usage.promptTokens'] != undefined) {
31
- attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];
32
- }
33
- if (
34
- typeof attributes['ai.usage.completionTokens'] == 'number' &&
35
- typeof attributes['ai.usage.promptTokens'] == 'number'
36
- ) {
37
- attributes['ai.total_tokens.used'] =
38
- attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];
39
- }
40
- }
41
- }
42
-
43
- return event;
18
+ instrumentation = instrumentVercelAi();
44
19
  },
45
20
  setup(client) {
46
- client.on('spanStart', span => {
47
- if (!sentryVercelAiPatched) {
48
- return;
49
- }
50
-
51
- const { data: attributes, description: name } = spanToJSON(span);
52
-
53
- if (!name) {
54
- return;
55
- }
56
-
57
- // The id of the model
58
- const aiModelId = attributes['ai.model.id'];
59
-
60
- // the provider of the model
61
- const aiModelProvider = attributes['ai.model.provider'];
62
-
63
- // both of these must be defined for the integration to work
64
- if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {
65
- return;
66
- }
67
-
68
- let isPipelineSpan = false;
69
-
70
- switch (name) {
71
- case 'ai.generateText': {
72
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');
73
- isPipelineSpan = true;
74
- break;
75
- }
76
- case 'ai.generateText.doGenerate': {
77
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
78
- break;
79
- }
80
- case 'ai.streamText': {
81
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');
82
- isPipelineSpan = true;
83
- break;
84
- }
85
- case 'ai.streamText.doStream': {
86
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
87
- break;
88
- }
89
- case 'ai.generateObject': {
90
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');
91
- isPipelineSpan = true;
92
- break;
93
- }
94
- case 'ai.generateObject.doGenerate': {
95
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
96
- break;
97
- }
98
- case 'ai.streamObject': {
99
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');
100
- isPipelineSpan = true;
101
- break;
102
- }
103
- case 'ai.streamObject.doStream': {
104
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
105
- break;
106
- }
107
- case 'ai.embed': {
108
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');
109
- isPipelineSpan = true;
110
- break;
111
- }
112
- case 'ai.embed.doEmbed': {
113
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
114
- break;
115
- }
116
- case 'ai.embedMany': {
117
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');
118
- isPipelineSpan = true;
119
- break;
120
- }
121
- case 'ai.embedMany.doEmbed': {
122
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
123
- break;
124
- }
125
- case 'ai.toolCall':
126
- case 'ai.stream.firstChunk':
127
- case 'ai.stream.finish':
128
- span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');
129
- break;
130
- }
131
-
132
- addOriginToSpan(span, 'auto.vercelai.otel');
133
-
134
- const nameWthoutAi = name.replace('ai.', '');
135
- span.setAttribute('ai.pipeline.name', nameWthoutAi);
136
- span.updateName(nameWthoutAi);
137
-
138
- // If a Telemetry name is set and it is a pipeline span, use that as the operation name
139
- const functionId = attributes['ai.telemetry.functionId'];
140
- if (functionId && typeof functionId === 'string' && isPipelineSpan) {
141
- span.updateName(functionId);
142
- span.setAttribute('ai.pipeline.name', functionId);
143
- }
144
-
145
- if (attributes['ai.prompt']) {
146
- span.setAttribute('ai.input_messages', attributes['ai.prompt']);
147
- }
148
- if (attributes['ai.model.id']) {
149
- span.setAttribute('ai.model_id', attributes['ai.model.id']);
150
- }
151
- span.setAttribute('ai.streaming', name.includes('stream'));
21
+ instrumentation?.callWhenPatched(() => {
22
+ client.on('spanStart', span => {
23
+ const { data: attributes, description: name } = spanToJSON(span);
24
+
25
+ if (!name) {
26
+ return;
27
+ }
28
+
29
+ // The id of the model
30
+ const aiModelId = attributes['ai.model.id'];
31
+
32
+ // the provider of the model
33
+ const aiModelProvider = attributes['ai.model.provider'];
34
+
35
+ // both of these must be defined for the integration to work
36
+ if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {
37
+ return;
38
+ }
39
+
40
+ let isPipelineSpan = false;
41
+
42
+ switch (name) {
43
+ case 'ai.generateText': {
44
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');
45
+ isPipelineSpan = true;
46
+ break;
47
+ }
48
+ case 'ai.generateText.doGenerate': {
49
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
50
+ break;
51
+ }
52
+ case 'ai.streamText': {
53
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');
54
+ isPipelineSpan = true;
55
+ break;
56
+ }
57
+ case 'ai.streamText.doStream': {
58
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
59
+ break;
60
+ }
61
+ case 'ai.generateObject': {
62
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');
63
+ isPipelineSpan = true;
64
+ break;
65
+ }
66
+ case 'ai.generateObject.doGenerate': {
67
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
68
+ break;
69
+ }
70
+ case 'ai.streamObject': {
71
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');
72
+ isPipelineSpan = true;
73
+ break;
74
+ }
75
+ case 'ai.streamObject.doStream': {
76
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
77
+ break;
78
+ }
79
+ case 'ai.embed': {
80
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');
81
+ isPipelineSpan = true;
82
+ break;
83
+ }
84
+ case 'ai.embed.doEmbed': {
85
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
86
+ break;
87
+ }
88
+ case 'ai.embedMany': {
89
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');
90
+ isPipelineSpan = true;
91
+ break;
92
+ }
93
+ case 'ai.embedMany.doEmbed': {
94
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
95
+ break;
96
+ }
97
+ case 'ai.toolCall':
98
+ case 'ai.stream.firstChunk':
99
+ case 'ai.stream.finish':
100
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');
101
+ break;
102
+ }
103
+
104
+ addOriginToSpan(span, 'auto.vercelai.otel');
105
+
106
+ const nameWthoutAi = name.replace('ai.', '');
107
+ span.setAttribute('ai.pipeline.name', nameWthoutAi);
108
+ span.updateName(nameWthoutAi);
109
+
110
+ // If a Telemetry name is set and it is a pipeline span, use that as the operation name
111
+ const functionId = attributes['ai.telemetry.functionId'];
112
+ if (functionId && typeof functionId === 'string' && isPipelineSpan) {
113
+ span.updateName(functionId);
114
+ span.setAttribute('ai.pipeline.name', functionId);
115
+ }
116
+
117
+ if (attributes['ai.prompt']) {
118
+ span.setAttribute('ai.input_messages', attributes['ai.prompt']);
119
+ }
120
+ if (attributes['ai.model.id']) {
121
+ span.setAttribute('ai.model_id', attributes['ai.model.id']);
122
+ }
123
+ span.setAttribute('ai.streaming', name.includes('stream'));
124
+ });
125
+
126
+ client.addEventProcessor(event => {
127
+ if (event.type === 'transaction' && event.spans?.length) {
128
+ for (const span of event.spans) {
129
+ const { data: attributes, description: name } = span;
130
+
131
+ if (!name || span.origin !== 'auto.vercelai.otel') {
132
+ continue;
133
+ }
134
+
135
+ if (attributes['ai.usage.completionTokens'] != undefined) {
136
+ attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];
137
+ }
138
+ if (attributes['ai.usage.promptTokens'] != undefined) {
139
+ attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];
140
+ }
141
+ if (
142
+ typeof attributes['ai.usage.completionTokens'] == 'number' &&
143
+ typeof attributes['ai.usage.promptTokens'] == 'number'
144
+ ) {
145
+ attributes['ai.total_tokens.used'] =
146
+ attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];
147
+ }
148
+ }
149
+ }
150
+
151
+ return event;
152
+ });
152
153
  });
153
154
  },
154
155
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/vercelai/index.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../../otel/instrument';\nimport { addOriginToSpan } from '../../../utils/addOriginToSpan';\nimport { SentryVercelAiInstrumentation, sentryVercelAiPatched } from './instrumentation';\n\nconst INTEGRATION_NAME = 'VercelAI';\n\nexport const instrumentVercelAi = generateInstrumentOnce(INTEGRATION_NAME, () => new SentryVercelAiInstrumentation({}));\n\nconst _vercelAIIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentVercelAi();\n },\n processEvent(event) {\n if (event.type === 'transaction' && event.spans?.length) {\n for (const span of event.spans) {\n const { data: attributes, description: name } = span;\n\n if (!name || span.origin !== 'auto.vercelai.otel') {\n continue;\n }\n\n if (attributes['ai.usage.completionTokens'] != undefined) {\n attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];\n }\n if (attributes['ai.usage.promptTokens'] != undefined) {\n attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];\n }\n if (\n typeof attributes['ai.usage.completionTokens'] == 'number' &&\n typeof attributes['ai.usage.promptTokens'] == 'number'\n ) {\n attributes['ai.total_tokens.used'] =\n attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];\n }\n }\n }\n\n return event;\n },\n setup(client) {\n client.on('spanStart', span => {\n if (!sentryVercelAiPatched) {\n return;\n }\n\n const { data: attributes, description: name } = spanToJSON(span);\n\n if (!name) {\n return;\n }\n\n // The id of the model\n const aiModelId = attributes['ai.model.id'];\n\n // the provider of the model\n const aiModelProvider = attributes['ai.model.provider'];\n\n // both of these must be defined for the integration to work\n if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {\n return;\n }\n\n let isPipelineSpan = false;\n\n switch (name) {\n case 'ai.generateText': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');\n isPipelineSpan = true;\n break;\n }\n case 'ai.generateText.doGenerate': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');\n break;\n }\n case 'ai.streamText': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');\n isPipelineSpan = true;\n break;\n }\n case 'ai.streamText.doStream': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');\n break;\n }\n case 'ai.generateObject': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');\n isPipelineSpan = true;\n break;\n }\n case 'ai.generateObject.doGenerate': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');\n break;\n }\n case 'ai.streamObject': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');\n isPipelineSpan = true;\n break;\n }\n case 'ai.streamObject.doStream': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');\n break;\n }\n case 'ai.embed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');\n isPipelineSpan = true;\n break;\n }\n case 'ai.embed.doEmbed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');\n break;\n }\n case 'ai.embedMany': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');\n isPipelineSpan = true;\n break;\n }\n case 'ai.embedMany.doEmbed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');\n break;\n }\n case 'ai.toolCall':\n case 'ai.stream.firstChunk':\n case 'ai.stream.finish':\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');\n break;\n }\n\n addOriginToSpan(span, 'auto.vercelai.otel');\n\n const nameWthoutAi = name.replace('ai.', '');\n span.setAttribute('ai.pipeline.name', nameWthoutAi);\n span.updateName(nameWthoutAi);\n\n // If a Telemetry name is set and it is a pipeline span, use that as the operation name\n const functionId = attributes['ai.telemetry.functionId'];\n if (functionId && typeof functionId === 'string' && isPipelineSpan) {\n span.updateName(functionId);\n span.setAttribute('ai.pipeline.name', functionId);\n }\n\n if (attributes['ai.prompt']) {\n span.setAttribute('ai.input_messages', attributes['ai.prompt']);\n }\n if (attributes['ai.model.id']) {\n span.setAttribute('ai.model_id', attributes['ai.model.id']);\n }\n span.setAttribute('ai.streaming', name.includes('stream'));\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [ai](https://www.npmjs.com/package/ai) library.\n *\n * For more information, see the [`ai` documentation](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.vercelAIIntegration()],\n * });\n * ```\n *\n * By default this integration adds tracing support to all `ai` function calls. If you need to disable\n * collecting spans for a specific call, you can do so by setting `experimental_telemetry.isEnabled` to\n * `false` in the first argument of the function call.\n *\n * ```javascript\n * const result = await generateText({\n * model: openai('gpt-4-turbo'),\n * experimental_telemetry: { isEnabled: false },\n * });\n * ```\n *\n * If you want to collect inputs and outputs for a specific call, you must specifically opt-in to each\n * function call by setting `experimental_telemetry.recordInputs` and `experimental_telemetry.recordOutputs`\n * to `true`.\n *\n * ```javascript\n * const result = await generateText({\n * model: openai('gpt-4-turbo'),\n * experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true },\n * });\n */\nexport const vercelAIIntegration = defineIntegration(_vercelAIIntegration);\n"],"names":[],"mappings":";;;;;AAAA;;AAOA,MAAM,gBAAA,GAAmB,UAAU;;MAEtB,kBAAmB,GAAE,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAI,6BAA6B,CAAC,EAAE,CAAC;;AAEtH,MAAM,oBAAqB,IAAG,MAAM;AACpC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,kBAAkB,EAAE;AAC1B,KAAK;AACL,IAAI,YAAY,CAAC,KAAK,EAAE;AACxB,MAAM,IAAI,KAAK,CAAC,IAAK,KAAI,aAAc,IAAG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE;AAC/D,QAAQ,KAAK,MAAM,IAAA,IAAQ,KAAK,CAAC,KAAK,EAAE;AACxC,UAAU,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,IAAA,EAAO,GAAE,IAAI;;AAE9D,UAAU,IAAI,CAAC,IAAK,IAAG,IAAI,CAAC,MAAA,KAAW,oBAAoB,EAAE;AAC7D,YAAY;AACZ;;AAEA,UAAU,IAAI,UAAU,CAAC,2BAA2B,CAAE,IAAG,SAAS,EAAE;AACpE,YAAY,UAAU,CAAC,2BAA2B,CAAA,GAAI,UAAU,CAAC,2BAA2B,CAAC;AAC7F;AACA,UAAU,IAAI,UAAU,C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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,mBAAoB,GAAE,iBAAiB,CAAC,oBAAoB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/vercelai/index.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../../otel/instrument';\nimport { addOriginToSpan } from '../../../utils/addOriginToSpan';\nimport { SentryVercelAiInstrumentation } from './instrumentation';\n\nconst INTEGRATION_NAME = 'VercelAI';\n\nexport const instrumentVercelAi = generateInstrumentOnce(INTEGRATION_NAME, () => new SentryVercelAiInstrumentation({}));\n\nconst _vercelAIIntegration = (() => {\n let instrumentation: undefined | SentryVercelAiInstrumentation;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentation = instrumentVercelAi();\n },\n setup(client) {\n instrumentation?.callWhenPatched(() => {\n client.on('spanStart', span => {\n const { data: attributes, description: name } = spanToJSON(span);\n\n if (!name) {\n return;\n }\n\n // The id of the model\n const aiModelId = attributes['ai.model.id'];\n\n // the provider of the model\n const aiModelProvider = attributes['ai.model.provider'];\n\n // both of these must be defined for the integration to work\n if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {\n return;\n }\n\n let isPipelineSpan = false;\n\n switch (name) {\n case 'ai.generateText': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');\n isPipelineSpan = true;\n break;\n }\n case 'ai.generateText.doGenerate': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');\n break;\n }\n case 'ai.streamText': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');\n isPipelineSpan = true;\n break;\n }\n case 'ai.streamText.doStream': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');\n break;\n }\n case 'ai.generateObject': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');\n isPipelineSpan = true;\n break;\n }\n case 'ai.generateObject.doGenerate': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');\n break;\n }\n case 'ai.streamObject': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');\n isPipelineSpan = true;\n break;\n }\n case 'ai.streamObject.doStream': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');\n break;\n }\n case 'ai.embed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');\n isPipelineSpan = true;\n break;\n }\n case 'ai.embed.doEmbed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');\n break;\n }\n case 'ai.embedMany': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');\n isPipelineSpan = true;\n break;\n }\n case 'ai.embedMany.doEmbed': {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');\n break;\n }\n case 'ai.toolCall':\n case 'ai.stream.firstChunk':\n case 'ai.stream.finish':\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');\n break;\n }\n\n addOriginToSpan(span, 'auto.vercelai.otel');\n\n const nameWthoutAi = name.replace('ai.', '');\n span.setAttribute('ai.pipeline.name', nameWthoutAi);\n span.updateName(nameWthoutAi);\n\n // If a Telemetry name is set and it is a pipeline span, use that as the operation name\n const functionId = attributes['ai.telemetry.functionId'];\n if (functionId && typeof functionId === 'string' && isPipelineSpan) {\n span.updateName(functionId);\n span.setAttribute('ai.pipeline.name', functionId);\n }\n\n if (attributes['ai.prompt']) {\n span.setAttribute('ai.input_messages', attributes['ai.prompt']);\n }\n if (attributes['ai.model.id']) {\n span.setAttribute('ai.model_id', attributes['ai.model.id']);\n }\n span.setAttribute('ai.streaming', name.includes('stream'));\n });\n\n client.addEventProcessor(event => {\n if (event.type === 'transaction' && event.spans?.length) {\n for (const span of event.spans) {\n const { data: attributes, description: name } = span;\n\n if (!name || span.origin !== 'auto.vercelai.otel') {\n continue;\n }\n\n if (attributes['ai.usage.completionTokens'] != undefined) {\n attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];\n }\n if (attributes['ai.usage.promptTokens'] != undefined) {\n attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];\n }\n if (\n typeof attributes['ai.usage.completionTokens'] == 'number' &&\n typeof attributes['ai.usage.promptTokens'] == 'number'\n ) {\n attributes['ai.total_tokens.used'] =\n attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];\n }\n }\n }\n\n return event;\n });\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [ai](https://www.npmjs.com/package/ai) library.\n *\n * For more information, see the [`ai` documentation](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.vercelAIIntegration()],\n * });\n * ```\n *\n * By default this integration adds tracing support to all `ai` function calls. If you need to disable\n * collecting spans for a specific call, you can do so by setting `experimental_telemetry.isEnabled` to\n * `false` in the first argument of the function call.\n *\n * ```javascript\n * const result = await generateText({\n * model: openai('gpt-4-turbo'),\n * experimental_telemetry: { isEnabled: false },\n * });\n * ```\n *\n * If you want to collect inputs and outputs for a specific call, you must specifically opt-in to each\n * function call by setting `experimental_telemetry.recordInputs` and `experimental_telemetry.recordOutputs`\n * to `true`.\n *\n * ```javascript\n * const result = await generateText({\n * model: openai('gpt-4-turbo'),\n * experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true },\n * });\n */\nexport const vercelAIIntegration = defineIntegration(_vercelAIIntegration);\n"],"names":[],"mappings":";;;;;AAAA;;AAOA,MAAM,gBAAA,GAAmB,UAAU;;MAEtB,kBAAmB,GAAE,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAI,6BAA6B,CAAC,EAAE,CAAC;;AAEtH,MAAM,oBAAqB,IAAG,MAAM;AACpC,EAAE,IAAI,eAAe;;AAErB,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,eAAgB,GAAE,kBAAkB,EAAE;AAC5C,KAAK;AACL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,eAAe,EAAE,eAAe,CAAC,MAAM;AAC7C,QAAQ,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACvC,UAAU,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,IAAA,EAAO,GAAE,UAAU,CAAC,IAAI,CAAC;;AAE1E,UAAU,IAAI,CAAC,IAAI,EAAE;AACrB,YAAY;AACZ;;AAEA;AACA,UAAU,MAAM,SAAU,GAAE,UAAU,CAAC,aAAa,CAAC;;AAErD;AACA,UAAU,MAAM,eAAgB,GAAE,UAAU,CAAC,mBAAmB,CAAC;;AAEjE;AACA,UAAU,IAAI,OAAO,SAAU,KAAI,YAAY,OAAO,eAAgB,KAAI,YAAY,CAAC,aAAa,CAAC,eAAe,EAAE;AACtH,YAAY;AACZ;;AAEA,UAAU,IAAI,cAAe,GAAE,KAAK;;AAEpC,UAAU,QAAQ,IAAI;AACtB,YAAY,KAAK,iBAAiB,EAAE;AACpC,cAAc,IAAI,CAAC,YAAY,CAAC,4BAA4B,EAAE,0BAA0B,CAAC;AACzF,cAAc,cAAA,GAAiB,IAAI;AACnC,cAAc;AACd;AACA,YAA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METHODS = [
12
12
  'embedMany',
13
13
  ] ;
14
14
 
15
- let sentryVercelAiPatched = false;
16
-
17
15
  /**
18
16
  * This detects is added by the Sentry Vercel AI Integration to detect if the integration should
19
17
  * be enabled.
@@ -21,9 +19,11 @@ let sentryVercelAiPatched = false;
21
19
  * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.
22
20
  */
23
21
  class SentryVercelAiInstrumentation extends InstrumentationBase {
22
+ __init() {this._isPatched = false;}
23
+ __init2() {this._callbacks = [];}
24
+
24
25
  constructor(config = {}) {
25
- super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);
26
- }
26
+ super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);SentryVercelAiInstrumentation.prototype.__init.call(this);SentryVercelAiInstrumentation.prototype.__init2.call(this); }
27
27
 
28
28
  /**
29
29
  * Initializes the instrumentation by defining the modules to be patched.
@@ -33,11 +33,26 @@ class SentryVercelAiInstrumentation extends InstrumentationBase {
33
33
  return module;
34
34
  }
35
35
 
36
+ /**
37
+ * Call the provided callback when the module is patched.
38
+ * If it has already been patched, the callback will be called immediately.
39
+ */
40
+ callWhenPatched(callback) {
41
+ if (this._isPatched) {
42
+ callback();
43
+ } else {
44
+ this._callbacks.push(callback);
45
+ }
46
+ }
47
+
36
48
  /**
37
49
  * Patches module exports to enable Vercel AI telemetry.
38
50
  */
39
51
  _patch(moduleExports) {
40
- sentryVercelAiPatched = true;
52
+ this._isPatched = true;
53
+
54
+ this._callbacks.forEach(callback => callback());
55
+ this._callbacks = [];
41
56
 
42
57
  function generatePatch(name) {
43
58
  return (...args) => {
@@ -69,5 +84,5 @@ class SentryVercelAiInstrumentation extends InstrumentationBase {
69
84
  }
70
85
  }
71
86
 
72
- export { SentryVercelAiInstrumentation, sentryVercelAiPatched };
87
+ export { SentryVercelAiInstrumentation };
73
88
  //# sourceMappingURL=instrumentation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/vercelai/instrumentation.ts"],"sourcesContent":["import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { SDK_VERSION } from '@sentry/core';\nimport type { TelemetrySettings } from './types';\n\n// List of patched methods\n// From: https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\nconst INSTRUMENTED_METHODS = [\n 'generateText',\n 'streamText',\n 'generateObject',\n 'streamObject',\n 'embed',\n 'embedMany',\n] as const;\n\ninterface MethodFirstArg extends Record<string, unknown> {\n experimental_telemetry?: TelemetrySettings;\n}\n\ntype MethodArgs = [MethodFirstArg, ...unknown[]];\n\ntype PatchedModuleExports = Record<(typeof INSTRUMENTED_METHODS)[number], (...args: MethodArgs) => unknown> &\n Record<string, unknown>;\n\nexport let sentryVercelAiPatched = false;\n\n/**\n * This detects is added by the Sentry Vercel AI Integration to detect if the integration should\n * be enabled.\n *\n * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.\n */\nexport class SentryVercelAiInstrumentation extends InstrumentationBase {\n public constructor(config: InstrumentationConfig = {}) {\n super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('ai', ['>=3.0.0 <5'], this._patch.bind(this));\n return module;\n }\n\n /**\n * Patches module exports to enable Vercel AI telemetry.\n */\n private _patch(moduleExports: PatchedModuleExports): unknown {\n sentryVercelAiPatched = true;\n\n function generatePatch(name: string) {\n return (...args: MethodArgs) => {\n const existingExperimentalTelemetry = args[0].experimental_telemetry || {};\n const isEnabled = existingExperimentalTelemetry.isEnabled;\n\n // if `isEnabled` is not explicitly set to `true` or `false`, enable telemetry\n // but disable capturing inputs and outputs by default\n if (isEnabled === undefined) {\n args[0].experimental_telemetry = {\n isEnabled: true,\n recordInputs: false,\n recordOutputs: false,\n ...existingExperimentalTelemetry,\n };\n }\n\n // @ts-expect-error we know that the method exists\n return moduleExports[name].apply(this, args);\n };\n }\n\n const patchedModuleExports = INSTRUMENTED_METHODS.reduce((acc, curr) => {\n acc[curr] = generatePatch(curr);\n return acc;\n }, {} as PatchedModuleExports);\n\n return { ...moduleExports, ...patchedModuleExports };\n }\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA,MAAM,uBAAuB;AAC7B,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,EAAE,gBAAgB;AAClB,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAE;;AAWK,IAAI,qBAAsB,GAAE;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,6BAA8B,SAAQ,mBAAoB,CAAA;AACvE,GAAS,WAAW,CAAC,MAAM,GAA0B,EAAE,EAAE;AACzD,IAAI,KAAK,CAAC,mCAAmC,EAAE,WAAW,EAAE,MAAM,CAAC;AACnE;;AAEA;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,SAAS,IAAI,mCAAmC,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxG,IAAI,OAAO,MAAM;AACjB;;AAEA;AACA;AACA;AACA,GAAU,MAAM,CAAC,aAAa,EAAiC;AAC/D,IAAI,qBAAA,GAAwB,IAAI;;AAEhC,IAAI,SAAS,aAAa,CAAC,IAAI,EAAU;AACzC,MAAM,OAAO,CAAC,GAAG,IAAI,KAAiB;AACtC,QAAQ,MAAM,6BAA8B,GAAE,IAAI,CAAC,CAAC,CAAC,CAAC,sBAAA,IAA0B,EAAE;AAClF,QAAQ,MAAM,SAAA,GAAY,6BAA6B,CAAC,SAAS;;AAEjE;AACA;AACA,QAAQ,IAAI,SAAU,KAAI,SAAS,EAAE;AACrC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,yBAAyB;AAC3C,YAAY,SAAS,EAAE,IAAI;AAC3B,YAAY,YAAY,EAAE,KAAK;AAC/B,YAAY,aAAa,EAAE,KAAK;AAChC,YAAY,GAAG,6BAA6B;AAC5C,WAAW;AACX;;AAEA;AACA,QAAQ,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACpD,OAAO;AACP;;AAEA,IAAI,MAAM,oBAAA,GAAuB,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;AAC5E,MAAM,GAAG,CAAC,IAAI,CAAA,GAAI,aAAa,CAAC,IAAI,CAAC;AACrC,MAAM,OAAO,GAAG;AAChB,KAAK,EAAE,EAAC,EAA0B;;AAElC,IAAI,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,sBAAsB;AACxD;AACA;;;;"}
1
+ {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/vercelai/instrumentation.ts"],"sourcesContent":["import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { SDK_VERSION } from '@sentry/core';\nimport type { TelemetrySettings } from './types';\n\n// List of patched methods\n// From: https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\nconst INSTRUMENTED_METHODS = [\n 'generateText',\n 'streamText',\n 'generateObject',\n 'streamObject',\n 'embed',\n 'embedMany',\n] as const;\n\ninterface MethodFirstArg extends Record<string, unknown> {\n experimental_telemetry?: TelemetrySettings;\n}\n\ntype MethodArgs = [MethodFirstArg, ...unknown[]];\n\ntype PatchedModuleExports = Record<(typeof INSTRUMENTED_METHODS)[number], (...args: MethodArgs) => unknown> &\n Record<string, unknown>;\n\n/**\n * This detects is added by the Sentry Vercel AI Integration to detect if the integration should\n * be enabled.\n *\n * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.\n */\nexport class SentryVercelAiInstrumentation extends InstrumentationBase {\n private _isPatched = false;\n private _callbacks: (() => void)[] = [];\n\n public constructor(config: InstrumentationConfig = {}) {\n super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('ai', ['>=3.0.0 <5'], this._patch.bind(this));\n return module;\n }\n\n /**\n * Call the provided callback when the module is patched.\n * If it has already been patched, the callback will be called immediately.\n */\n public callWhenPatched(callback: () => void): void {\n if (this._isPatched) {\n callback();\n } else {\n this._callbacks.push(callback);\n }\n }\n\n /**\n * Patches module exports to enable Vercel AI telemetry.\n */\n private _patch(moduleExports: PatchedModuleExports): unknown {\n this._isPatched = true;\n\n this._callbacks.forEach(callback => callback());\n this._callbacks = [];\n\n function generatePatch(name: string) {\n return (...args: MethodArgs) => {\n const existingExperimentalTelemetry = args[0].experimental_telemetry || {};\n const isEnabled = existingExperimentalTelemetry.isEnabled;\n\n // if `isEnabled` is not explicitly set to `true` or `false`, enable telemetry\n // but disable capturing inputs and outputs by default\n if (isEnabled === undefined) {\n args[0].experimental_telemetry = {\n isEnabled: true,\n recordInputs: false,\n recordOutputs: false,\n ...existingExperimentalTelemetry,\n };\n }\n\n // @ts-expect-error we know that the method exists\n return moduleExports[name].apply(this, args);\n };\n }\n\n const patchedModuleExports = INSTRUMENTED_METHODS.reduce((acc, curr) => {\n acc[curr] = generatePatch(curr);\n return acc;\n }, {} as PatchedModuleExports);\n\n return { ...moduleExports, ...patchedModuleExports };\n }\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA,MAAM,uBAAuB;AAC7B,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,EAAE,gBAAgB;AAClB,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAE;;AAWF;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,6BAA8B,SAAQ,mBAAoB,CAAA;AACvE,GAAE,MAAA,GAAA,CAAA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,IAAI,SAAU,KAAI,SAAS,EAAE;AACrC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,yBAAyB;AAC3C,YAAY,SAAS,EAAE,IAAI;AAC3B,YAAY,YAAY,EAAE,KAAK;AAC/B,YAAY,aAAa,EAAE,KAAK;AAChC,YAAY,GAAG,6BAA6B;AAC5C,WAAW;AACX;;AAEA;AACA,QAAQ,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACpD,OAAO;AACP;;AAEA,IAAI,MAAM,oBAAA,GAAuB,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;AAC5E,MAAM,GAAG,CAAC,IAAI,CAAA,GAAI,aAAa,CAAC,IAAI,CAAC;AACrC,MAAM,OAAO,GAAG;AAChB,KAAK,EAAE,EAAC,EAA0B;;AAElC,IAAI,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,sBAAsB;AACxD;AACA;;;;"}
@@ -0,0 +1,193 @@
1
+ import { format } from 'node:util';
2
+ import { _INTERNAL_captureLog } from '@sentry/core';
3
+ export { fmt } from '@sentry/core';
4
+
5
+ /**
6
+ * Capture a log with the given level.
7
+ *
8
+ * @param level - The level of the log.
9
+ * @param message - The message to log.
10
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100.
11
+ */
12
+ function captureLog(level, ...args) {
13
+ const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributes] = args;
14
+ if (Array.isArray(paramsOrAttributes)) {
15
+ const attributes = { ...maybeAttributes };
16
+ attributes['sentry.message.template'] = messageOrMessageTemplate;
17
+ paramsOrAttributes.forEach((param, index) => {
18
+ attributes[`sentry.message.param.${index}`] = param;
19
+ });
20
+ const message = format(messageOrMessageTemplate, ...paramsOrAttributes);
21
+ _INTERNAL_captureLog({ level, message, attributes });
22
+ } else {
23
+ _INTERNAL_captureLog({ level, message: messageOrMessageTemplate, attributes: paramsOrAttributes });
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @summary Capture a log with the `trace` level. Requires `_experiments.enableLogs` to be enabled.
29
+ *
30
+ * You can either pass a message and attributes or a message template, params and attributes.
31
+ *
32
+ * @example
33
+ *
34
+ * ```
35
+ * Sentry.logger.trace('Starting database connection', {
36
+ * database: 'users',
37
+ * connectionId: 'conn_123'
38
+ * });
39
+ * ```
40
+ *
41
+ * @example With template strings
42
+ *
43
+ * ```
44
+ * Sentry.logger.trace('Database connection %s established for %s',
45
+ * ['successful', 'users'],
46
+ * { connectionId: 'conn_123' }
47
+ * );
48
+ * ```
49
+ */
50
+ function trace(...args) {
51
+ captureLog('trace', ...args);
52
+ }
53
+
54
+ /**
55
+ * @summary Capture a log with the `debug` level. Requires `_experiments.enableLogs` to be enabled.
56
+ *
57
+ * You can either pass a message and attributes or a message template, params and attributes.
58
+ *
59
+ * @example
60
+ *
61
+ * ```
62
+ * Sentry.logger.debug('Cache miss for user profile', {
63
+ * userId: 'user_123',
64
+ * cacheKey: 'profile:user_123'
65
+ * });
66
+ * ```
67
+ *
68
+ * @example With template strings
69
+ *
70
+ * ```
71
+ * Sentry.logger.debug('Cache %s for %s: %s',
72
+ * ['miss', 'user profile', 'key not found'],
73
+ * { userId: 'user_123' }
74
+ * );
75
+ * ```
76
+ */
77
+ function debug(...args) {
78
+ captureLog('debug', ...args);
79
+ }
80
+
81
+ /**
82
+ * @summary Capture a log with the `info` level. Requires `_experiments.enableLogs` to be enabled.
83
+ *
84
+ * You can either pass a message and attributes or a message template, params and attributes.
85
+ *
86
+ * @example
87
+ *
88
+ * ```
89
+ * Sentry.logger.info('User profile updated', {
90
+ * userId: 'user_123',
91
+ * updatedFields: ['email', 'preferences']
92
+ * });
93
+ * ```
94
+ *
95
+ * @example With template strings
96
+ *
97
+ * ```
98
+ * Sentry.logger.info('User %s updated their %s',
99
+ * ['John Doe', 'profile settings'],
100
+ * { userId: 'user_123' }
101
+ * );
102
+ * ```
103
+ */
104
+ function info(...args) {
105
+ captureLog('info', ...args);
106
+ }
107
+
108
+ /**
109
+ * @summary Capture a log with the `warn` level. Requires `_experiments.enableLogs` to be enabled.
110
+ *
111
+ * You can either pass a message and attributes or a message template, params and attributes.
112
+ *
113
+ * @example
114
+ *
115
+ * ```
116
+ * Sentry.logger.warn('Rate limit approaching', {
117
+ * endpoint: '/api/users',
118
+ * currentRate: '95/100',
119
+ * resetTime: '2024-03-20T10:00:00Z'
120
+ * });
121
+ * ```
122
+ *
123
+ * @example With template strings
124
+ *
125
+ * ```
126
+ * Sentry.logger.warn('Rate limit %s for %s: %s',
127
+ * ['approaching', '/api/users', '95/100 requests'],
128
+ * { resetTime: '2024-03-20T10:00:00Z' }
129
+ * );
130
+ * ```
131
+ */
132
+ function warn(...args) {
133
+ captureLog('warn', ...args);
134
+ }
135
+
136
+ /**
137
+ * @summary Capture a log with the `error` level. Requires `_experiments.enableLogs` to be enabled.
138
+ *
139
+ * You can either pass a message and attributes or a message template, params and attributes.
140
+ *
141
+ * @example
142
+ *
143
+ * ```
144
+ * Sentry.logger.error('Failed to process payment', {
145
+ * orderId: 'order_123',
146
+ * errorCode: 'PAYMENT_FAILED',
147
+ * amount: 99.99
148
+ * });
149
+ * ```
150
+ *
151
+ * @example With template strings
152
+ *
153
+ * ```
154
+ * Sentry.logger.error('Payment processing failed for order %s: %s',
155
+ * ['order_123', 'insufficient funds'],
156
+ * { amount: 99.99 }
157
+ * );
158
+ * ```
159
+ */
160
+ function error(...args) {
161
+ captureLog('error', ...args);
162
+ }
163
+
164
+ /**
165
+ * @summary Capture a log with the `fatal` level. Requires `_experiments.enableLogs` to be enabled.
166
+ *
167
+ * You can either pass a message and attributes or a message template, params and attributes.
168
+ *
169
+ * @example
170
+ *
171
+ * ```
172
+ * Sentry.logger.fatal('Database connection pool exhausted', {
173
+ * database: 'users',
174
+ * activeConnections: 100,
175
+ * maxConnections: 100
176
+ * });
177
+ * ```
178
+ *
179
+ * @example With template strings
180
+ *
181
+ * ```
182
+ * Sentry.logger.fatal('Database %s: %s connections active',
183
+ * ['connection pool exhausted', '100/100'],
184
+ * { database: 'users' }
185
+ * );
186
+ * ```
187
+ */
188
+ function fatal(...args) {
189
+ captureLog('fatal', ...args);
190
+ }
191
+
192
+ export { debug, error, fatal, info, trace, warn };
193
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sources":["../../src/log.ts"],"sourcesContent":["import { format } from 'node:util';\n\nimport type { LogSeverityLevel, Log, ParameterizedString } from '@sentry/core';\nimport { _INTERNAL_captureLog } from '@sentry/core';\n\ntype CaptureLogArgs =\n | [message: ParameterizedString, attributes?: Log['attributes']]\n | [messageTemplate: string, messageParams: Array<unknown>, attributes?: Log['attributes']];\n\n/**\n * Capture a log with the given level.\n *\n * @param level - The level of the log.\n * @param message - The message to log.\n * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100.\n */\nfunction captureLog(level: LogSeverityLevel, ...args: CaptureLogArgs): void {\n const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributes] = args;\n if (Array.isArray(paramsOrAttributes)) {\n const attributes = { ...maybeAttributes };\n attributes['sentry.message.template'] = messageOrMessageTemplate;\n paramsOrAttributes.forEach((param, index) => {\n attributes[`sentry.message.param.${index}`] = param;\n });\n const message = format(messageOrMessageTemplate, ...paramsOrAttributes);\n _INTERNAL_captureLog({ level, message, attributes });\n } else {\n _INTERNAL_captureLog({ level, message: messageOrMessageTemplate, attributes: paramsOrAttributes });\n }\n}\n\n/**\n * @summary Capture a log with the `trace` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.trace('Starting database connection', {\n * database: 'users',\n * connectionId: 'conn_123'\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.trace('Database connection %s established for %s',\n * ['successful', 'users'],\n * { connectionId: 'conn_123' }\n * );\n * ```\n */\nexport function trace(...args: CaptureLogArgs): void {\n captureLog('trace', ...args);\n}\n\n/**\n * @summary Capture a log with the `debug` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.debug('Cache miss for user profile', {\n * userId: 'user_123',\n * cacheKey: 'profile:user_123'\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.debug('Cache %s for %s: %s',\n * ['miss', 'user profile', 'key not found'],\n * { userId: 'user_123' }\n * );\n * ```\n */\nexport function debug(...args: CaptureLogArgs): void {\n captureLog('debug', ...args);\n}\n\n/**\n * @summary Capture a log with the `info` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.info('User profile updated', {\n * userId: 'user_123',\n * updatedFields: ['email', 'preferences']\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.info('User %s updated their %s',\n * ['John Doe', 'profile settings'],\n * { userId: 'user_123' }\n * );\n * ```\n */\nexport function info(...args: CaptureLogArgs): void {\n captureLog('info', ...args);\n}\n\n/**\n * @summary Capture a log with the `warn` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.warn('Rate limit approaching', {\n * endpoint: '/api/users',\n * currentRate: '95/100',\n * resetTime: '2024-03-20T10:00:00Z'\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.warn('Rate limit %s for %s: %s',\n * ['approaching', '/api/users', '95/100 requests'],\n * { resetTime: '2024-03-20T10:00:00Z' }\n * );\n * ```\n */\nexport function warn(...args: CaptureLogArgs): void {\n captureLog('warn', ...args);\n}\n\n/**\n * @summary Capture a log with the `error` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.error('Failed to process payment', {\n * orderId: 'order_123',\n * errorCode: 'PAYMENT_FAILED',\n * amount: 99.99\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.error('Payment processing failed for order %s: %s',\n * ['order_123', 'insufficient funds'],\n * { amount: 99.99 }\n * );\n * ```\n */\nexport function error(...args: CaptureLogArgs): void {\n captureLog('error', ...args);\n}\n\n/**\n * @summary Capture a log with the `fatal` level. Requires `_experiments.enableLogs` to be enabled.\n *\n * You can either pass a message and attributes or a message template, params and attributes.\n *\n * @example\n *\n * ```\n * Sentry.logger.fatal('Database connection pool exhausted', {\n * database: 'users',\n * activeConnections: 100,\n * maxConnections: 100\n * });\n * ```\n *\n * @example With template strings\n *\n * ```\n * Sentry.logger.fatal('Database %s: %s connections active',\n * ['connection pool exhausted', '100/100'],\n * { database: 'users' }\n * );\n * ```\n */\nexport function fatal(...args: CaptureLogArgs): void {\n captureLog('fatal', ...args);\n}\n\nexport { fmt } from '@sentry/core';\n"],"names":[],"mappings":";;;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,UAAU,CAAC,KAAK,EAAoB,GAAG,IAAI,EAAwB;AAC5E,EAAE,MAAM,CAAC,wBAAwB,EAAE,kBAAkB,EAAE,eAAe,CAAE,GAAE,IAAI;AAC9E,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;AACzC,IAAI,MAAM,UAAW,GAAE,EAAE,GAAG,iBAAiB;AAC7C,IAAI,UAAU,CAAC,yBAAyB,CAAA,GAAI,wBAAwB;AACpE,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK;AACjD,MAAM,UAAU,CAAC,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA,CAAA,GAAA,KAAA;AACA,KAAA,CAAA;AACA,IAAA,MAAA,OAAA,GAAA,MAAA,CAAA,wBAAA,EAAA,GAAA,kBAAA,CAAA;AACA,IAAA,oBAAA,CAAA,EAAA,KAAA,EAAA,OAAA,EAAA,UAAA,EAAA,CAAA;AACA,GAAA,MAAA;AACA,IAAA,oBAAA,CAAA,EAAA,KAAA,EAAA,OAAA,EAAA,wBAAA,EAAA,UAAA,EAAA,kBAAA,EAAA,CAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,KAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,OAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,KAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,OAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,IAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,MAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,IAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,MAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,KAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,OAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,KAAA,CAAA,GAAA,IAAA,EAAA;AACA,EAAA,UAAA,CAAA,OAAA,EAAA,GAAA,IAAA,CAAA;AACA;;;;"}