@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
@@ -12,21 +12,26 @@ const instrumentKnex = instrument.generateInstrumentOnce(
12
12
  );
13
13
 
14
14
  const _knexIntegration = (() => {
15
+ let instrumentationWrappedCallback;
16
+
15
17
  return {
16
18
  name: INTEGRATION_NAME,
17
19
  setupOnce() {
18
- instrumentKnex();
20
+ const instrumentation = instrumentKnex();
21
+ instrumentationWrappedCallback = instrument.instrumentWhenWrapped(instrumentation);
19
22
  },
20
23
 
21
24
  setup(client) {
22
- client.on('spanStart', span => {
23
- const { data } = core.spanToJSON(span);
24
- // knex.version is always set in the span data
25
- // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/0309caeafc44ac9cb13a3345b790b01b76d0497d/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts#L138
26
- if ('knex.version' in data) {
27
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.knex');
28
- }
29
- });
25
+ instrumentationWrappedCallback?.(() =>
26
+ client.on('spanStart', span => {
27
+ const { data } = core.spanToJSON(span);
28
+ // knex.version is always set in the span data
29
+ // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/0309caeafc44ac9cb13a3345b790b01b76d0497d/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts#L138
30
+ if ('knex.version' in data) {
31
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.knex');
32
+ }
33
+ }),
34
+ );
30
35
  },
31
36
  };
32
37
  }) ;
@@ -1 +1 @@
1
- {"version":3,"file":"knex.js","sources":["../../../../src/integrations/tracing/knex.ts"],"sourcesContent":["import { KnexInstrumentation } from '@opentelemetry/instrumentation-knex';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../otel/instrument';\n\nconst INTEGRATION_NAME = 'Knex';\n\nexport const instrumentKnex = generateInstrumentOnce(\n INTEGRATION_NAME,\n () => new KnexInstrumentation({ requireParentSpan: true }),\n);\n\nconst _knexIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentKnex();\n },\n\n setup(client) {\n client.on('spanStart', span => {\n const { data } = spanToJSON(span);\n // knex.version is always set in the span data\n // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/0309caeafc44ac9cb13a3345b790b01b76d0497d/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts#L138\n if ('knex.version' in data) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.knex');\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Knex integration\n *\n * Capture tracing data for [Knex](https://knexjs.org/).\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n *\n * Sentry.init({\n * integrations: [Sentry.knexIntegration()],\n * });\n * ```\n */\nexport const knexIntegration = defineIntegration(_knexIntegration);\n"],"names":["generateInstrumentOnce","KnexInstrumentation","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,MAAM;;AAExB,MAAM,cAAe,GAAEA,iCAAsB;AACpD,EAAE,gBAAgB;AAClB,EAAE,MAAM,IAAIC,uCAAmB,CAAC,EAAE,iBAAiB,EAAE,IAAK,EAAC,CAAC;AAC5D;;AAEA,MAAM,gBAAiB,IAAG,MAAM;AAChC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,cAAc,EAAE;AACtB,KAAK;;AAEL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACrC,QAAQ,MAAM,EAAE,IAAK,EAAA,GAAIC,eAAU,CAAC,IAAI,CAAC;AACzC;AACA;AACA,QAAQ,IAAI,cAAe,IAAG,IAAI,EAAE;AACpC,UAAU,IAAI,CAAC,YAAY,CAACC,qCAAgC,EAAE,mBAAmB,CAAC;AAClF;AACA,OAAO,CAAC;AACR,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,eAAgB,GAAEC,sBAAiB,CAAC,gBAAgB;;;;;"}
1
+ {"version":3,"file":"knex.js","sources":["../../../../src/integrations/tracing/knex.ts"],"sourcesContent":["import { KnexInstrumentation } from '@opentelemetry/instrumentation-knex';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce, instrumentWhenWrapped } from '../../otel/instrument';\n\nconst INTEGRATION_NAME = 'Knex';\n\nexport const instrumentKnex = generateInstrumentOnce(\n INTEGRATION_NAME,\n () => new KnexInstrumentation({ requireParentSpan: true }),\n);\n\nconst _knexIntegration = (() => {\n let instrumentationWrappedCallback: undefined | ((callback: () => void) => void);\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n const instrumentation = instrumentKnex();\n instrumentationWrappedCallback = instrumentWhenWrapped(instrumentation);\n },\n\n setup(client) {\n instrumentationWrappedCallback?.(() =>\n client.on('spanStart', span => {\n const { data } = spanToJSON(span);\n // knex.version is always set in the span data\n // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/0309caeafc44ac9cb13a3345b790b01b76d0497d/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts#L138\n if ('knex.version' in data) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.knex');\n }\n }),\n );\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Knex integration\n *\n * Capture tracing data for [Knex](https://knexjs.org/).\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n *\n * Sentry.init({\n * integrations: [Sentry.knexIntegration()],\n * });\n * ```\n */\nexport const knexIntegration = defineIntegration(_knexIntegration);\n"],"names":["generateInstrumentOnce","KnexInstrumentation","instrumentWhenWrapped","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,MAAM;;AAExB,MAAM,cAAe,GAAEA,iCAAsB;AACpD,EAAE,gBAAgB;AAClB,EAAE,MAAM,IAAIC,uCAAmB,CAAC,EAAE,iBAAiB,EAAE,IAAK,EAAC,CAAC;AAC5D;;AAEA,MAAM,gBAAiB,IAAG,MAAM;AAChC,EAAE,IAAI,8BAA8B;;AAEpC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,MAAM,eAAA,GAAkB,cAAc,EAAE;AAC9C,MAAM,8BAA+B,GAAEC,gCAAqB,CAAC,eAAe,CAAC;AAC7E,KAAK;;AAEL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,8BAA8B,GAAG;AACvC,QAAQ,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACvC,UAAU,MAAM,EAAE,IAAK,EAAA,GAAIC,eAAU,CAAC,IAAI,CAAC;AAC3C;AACA;AACA,UAAU,IAAI,cAAe,IAAG,IAAI,EAAE;AACtC,YAAY,IAAI,CAAC,YAAY,CAACC,qCAAgC,EAAE,mBAAmB,CAAC;AACpF;AACA,SAAS,CAAC;AACV,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,eAAgB,GAAEC,sBAAiB,CAAC,gBAAgB;;;;;"}
@@ -15,6 +15,18 @@ function isPrismaV6TracingHelper(helper) {
15
15
  return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;
16
16
  }
17
17
 
18
+ function getPrismaTracingHelper() {
19
+ const prismaInstrumentationObject = (globalThis ).PRISMA_INSTRUMENTATION;
20
+ const prismaTracingHelper =
21
+ prismaInstrumentationObject &&
22
+ typeof prismaInstrumentationObject === 'object' &&
23
+ 'helper' in prismaInstrumentationObject
24
+ ? prismaInstrumentationObject.helper
25
+ : undefined;
26
+
27
+ return prismaTracingHelper;
28
+ }
29
+
18
30
  class SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation {
19
31
  constructor() {
20
32
  super();
@@ -26,13 +38,7 @@ class SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation
26
38
  // The PrismaIntegration (super class) defines a global variable `global["PRISMA_INSTRUMENTATION"]` when `enable()` is called. This global variable holds a "TracingHelper" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.
27
39
  // Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.
28
40
  // We still won't fully emit all the spans, but this could potentially be implemented in the future.
29
- const prismaInstrumentationObject = (globalThis ).PRISMA_INSTRUMENTATION;
30
- const prismaTracingHelper =
31
- prismaInstrumentationObject &&
32
- typeof prismaInstrumentationObject === 'object' &&
33
- 'helper' in prismaInstrumentationObject
34
- ? prismaInstrumentationObject.helper
35
- : undefined;
41
+ const prismaTracingHelper = getPrismaTracingHelper();
36
42
 
37
43
  let emittedWarning = false;
38
44
 
@@ -108,6 +114,12 @@ const prismaIntegration = core.defineIntegration(
108
114
  instrumentPrisma({ prismaInstrumentation });
109
115
  },
110
116
  setup(client) {
117
+ // If no tracing helper exists, we skip any work here
118
+ // this means that prisma is not being used
119
+ if (!getPrismaTracingHelper()) {
120
+ return;
121
+ }
122
+
111
123
  client.on('spanStart', span => {
112
124
  const spanJSON = core.spanToJSON(span);
113
125
  if (spanJSON.description?.startsWith('prisma:')) {
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.js","sources":["../../../../src/integrations/tracing/prisma.ts"],"sourcesContent":["import type { Instrumentation } from '@opentelemetry/instrumentation';\n// When importing CJS modules into an ESM module, we cannot import the named exports directly.\nimport * as prismaInstrumentation from '@prisma/instrumentation';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, consoleSandbox, defineIntegration, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../otel/instrument';\nimport type { PrismaV5TracingHelper } from './prisma/vendor/v5-tracing-helper';\nimport type { PrismaV6TracingHelper } from './prisma/vendor/v6-tracing-helper';\n\nconst INTEGRATION_NAME = 'Prisma';\n\nconst EsmInteropPrismaInstrumentation: typeof prismaInstrumentation.PrismaInstrumentation =\n // @ts-expect-error We need to do the following for interop reasons\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prismaInstrumentation.default?.PrismaInstrumentation || prismaInstrumentation.PrismaInstrumentation;\n\ntype CompatibilityLayerTraceHelper = PrismaV5TracingHelper & PrismaV6TracingHelper;\n\nfunction isPrismaV6TracingHelper(helper: unknown): helper is PrismaV6TracingHelper {\n return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;\n}\n\nclass SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation {\n public constructor() {\n super();\n }\n\n public enable(): void {\n super.enable();\n\n // The PrismaIntegration (super class) defines a global variable `global[\"PRISMA_INSTRUMENTATION\"]` when `enable()` is called. This global variable holds a \"TracingHelper\" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.\n // Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.\n // We still won't fully emit all the spans, but this could potentially be implemented in the future.\n const prismaInstrumentationObject = (globalThis as Record<string, unknown>).PRISMA_INSTRUMENTATION;\n const prismaTracingHelper =\n prismaInstrumentationObject &&\n typeof prismaInstrumentationObject === 'object' &&\n 'helper' in prismaInstrumentationObject\n ? prismaInstrumentationObject.helper\n : undefined;\n\n let emittedWarning = false;\n\n if (isPrismaV6TracingHelper(prismaTracingHelper)) {\n (prismaTracingHelper as CompatibilityLayerTraceHelper).createEngineSpan = () => {\n consoleSandbox(() => {\n if (!emittedWarning) {\n emittedWarning = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] The Sentry SDK supports tracing with Prisma version 5 only with limited capabilities. For full tracing capabilities pass `prismaInstrumentation` for version 5 to the Sentry `prismaIntegration`. Read more: https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/',\n );\n }\n });\n };\n }\n }\n}\n\nexport const instrumentPrisma = generateInstrumentOnce<{ prismaInstrumentation?: Instrumentation }>(\n INTEGRATION_NAME,\n options => {\n // Use a passed instrumentation instance to support older Prisma versions\n if (options?.prismaInstrumentation) {\n return options.prismaInstrumentation;\n }\n\n return new SentryPrismaInteropInstrumentation();\n },\n);\n\n/**\n * Adds Sentry tracing instrumentation for the [prisma](https://www.npmjs.com/package/prisma) library.\n * For more information, see the [`prismaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/).\n *\n * NOTE: By default, this integration works with Prisma version 6.\n * To get performance instrumentation for other Prisma versions,\n * 1. Install the `@prisma/instrumentation` package with the desired version.\n * 1. Pass a `new PrismaInstrumentation()` instance as exported from `@prisma/instrumentation` to the `prismaInstrumentation` option of this integration:\n *\n * ```js\n * import { PrismaInstrumentation } from '@prisma/instrumentation'\n *\n * Sentry.init({\n * integrations: [\n * prismaIntegration({\n * // Override the default instrumentation that Sentry uses\n * prismaInstrumentation: new PrismaInstrumentation()\n * })\n * ]\n * })\n * ```\n *\n * The passed instrumentation instance will override the default instrumentation instance the integration would use, while the `prismaIntegration` will still ensure data compatibility for the various Prisma versions.\n * 1. Depending on your Prisma version (prior to version 6), add `previewFeatures = [\"tracing\"]` to the client generator block of your Prisma schema:\n *\n * ```\n * generator client {\n * provider = \"prisma-client-js\"\n * previewFeatures = [\"tracing\"]\n * }\n * ```\n */\nexport const prismaIntegration = defineIntegration(\n ({\n prismaInstrumentation,\n }: {\n /**\n * Overrides the instrumentation used by the Sentry SDK with the passed in instrumentation instance.\n *\n * NOTE: By default, the Sentry SDK uses the Prisma v6 instrumentation. Use this option if you need performance instrumentation different Prisma versions.\n *\n * For more information refer to the documentation of `prismaIntegration()` or see https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/\n */\n prismaInstrumentation?: Instrumentation;\n } = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPrisma({ prismaInstrumentation });\n },\n setup(client) {\n client.on('spanStart', span => {\n const spanJSON = spanToJSON(span);\n if (spanJSON.description?.startsWith('prisma:')) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');\n }\n\n // Make sure we use the query text as the span name, for ex. SELECT * FROM \"User\" WHERE \"id\" = $1\n if (spanJSON.description === 'prisma:engine:db_query' && spanJSON.data['db.query.text']) {\n span.updateName(spanJSON.data['db.query.text'] as string);\n }\n\n // In Prisma v5.22+, the `db.system` attribute is automatically set\n // On older versions, this is missing, so we add it here\n if (spanJSON.description === 'prisma:engine:db_query' && !spanJSON.data['db.system']) {\n span.setAttribute('db.system', 'prisma');\n }\n });\n },\n };\n },\n);\n"],"names":["consoleSandbox","generateInstrumentOnce","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;;;AAQA,MAAM,gBAAA,GAAmB,QAAQ;;AAEjC,MAAM,+BAA+B;AACrC;AACA;AACA,EAAE,qBAAqB,CAAC,OAAO,EAAE,yBAAyB,qBAAqB,CAAC,qBAAqB;;AAIrG,SAAS,uBAAuB,CAAC,MAAM,EAA4C;AACnF,EAAE,OAAO,CAAC,CAAC,MAAA,IAAU,OAAO,MAAO,KAAI,QAAS,IAAG,qBAAsB,IAAG,MAAM;AAClF;;AAEA,MAAM,kCAAA,SAA2C,+BAAgC,CAAA;AACjF,GAAS,WAAW,GAAG;AACvB,IAAI,KAAK,EAAE;AACX;;AAEA,GAAS,MAAM,GAAS;AACxB,IAAI,KAAK,CAAC,MAAM,EAAE;;AAElB;AACA;AACA;AACA,IAAI,MAAM,2BAA4B,GAAE,CAAC,UAAW,GAA4B,sBAAsB;AACtG,IAAI,MAAM,mBAAoB;AAC9B,MAAM,2BAA4B;AAClC,MAAM,OAAO,2BAA4B,KAAI,QAAS;AACtD,MAAM,YAAY;AAClB,UAAU,2BAA2B,CAAC;AACtC,UAAU,SAAS;;AAEnB,IAAI,IAAI,cAAe,GAAE,KAAK;;AAE9B,IAAI,IAAI,uBAAuB,CAAC,mBAAmB,CAAC,EAAE;AACtD,MAAM,CAAC,sBAAsD,mBAAmB,MAAM;AACtF,QAAQA,mBAAc,CAAC,MAAM;AAC7B,UAAU,IAAI,CAAC,cAAc,EAAE;AAC/B,YAAY,cAAA,GAAiB,IAAI;AACjC;AACA,YAAY,OAAO,CAAC,IAAI;AACxB,cAAc,kTAAkT;AAChU,aAAa;AACb;AACA,SAAS,CAAC;AACV,OAAO;AACP;AACA;AACA;;AAEO,MAAM,gBAAiB,GAAEC,iCAAsB;AACtD,EAAE,gBAAgB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AACA,SAAS,CAAC;AACV,OAAO;AACP,KAAK;AACL,GAAG;AACH;;;;;"}
1
+ {"version":3,"file":"prisma.js","sources":["../../../../src/integrations/tracing/prisma.ts"],"sourcesContent":["import type { Instrumentation } from '@opentelemetry/instrumentation';\n// When importing CJS modules into an ESM module, we cannot import the named exports directly.\nimport * as prismaInstrumentation from '@prisma/instrumentation';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, consoleSandbox, defineIntegration, spanToJSON } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../otel/instrument';\nimport type { PrismaV5TracingHelper } from './prisma/vendor/v5-tracing-helper';\nimport type { PrismaV6TracingHelper } from './prisma/vendor/v6-tracing-helper';\n\nconst INTEGRATION_NAME = 'Prisma';\n\nconst EsmInteropPrismaInstrumentation: typeof prismaInstrumentation.PrismaInstrumentation =\n // @ts-expect-error We need to do the following for interop reasons\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prismaInstrumentation.default?.PrismaInstrumentation || prismaInstrumentation.PrismaInstrumentation;\n\ntype CompatibilityLayerTraceHelper = PrismaV5TracingHelper & PrismaV6TracingHelper;\n\nfunction isPrismaV6TracingHelper(helper: unknown): helper is PrismaV6TracingHelper {\n return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;\n}\n\nfunction getPrismaTracingHelper(): unknown | undefined {\n const prismaInstrumentationObject = (globalThis as Record<string, unknown>).PRISMA_INSTRUMENTATION;\n const prismaTracingHelper =\n prismaInstrumentationObject &&\n typeof prismaInstrumentationObject === 'object' &&\n 'helper' in prismaInstrumentationObject\n ? prismaInstrumentationObject.helper\n : undefined;\n\n return prismaTracingHelper;\n}\n\nclass SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation {\n public constructor() {\n super();\n }\n\n public enable(): void {\n super.enable();\n\n // The PrismaIntegration (super class) defines a global variable `global[\"PRISMA_INSTRUMENTATION\"]` when `enable()` is called. This global variable holds a \"TracingHelper\" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.\n // Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.\n // We still won't fully emit all the spans, but this could potentially be implemented in the future.\n const prismaTracingHelper = getPrismaTracingHelper();\n\n let emittedWarning = false;\n\n if (isPrismaV6TracingHelper(prismaTracingHelper)) {\n (prismaTracingHelper as CompatibilityLayerTraceHelper).createEngineSpan = () => {\n consoleSandbox(() => {\n if (!emittedWarning) {\n emittedWarning = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] The Sentry SDK supports tracing with Prisma version 5 only with limited capabilities. For full tracing capabilities pass `prismaInstrumentation` for version 5 to the Sentry `prismaIntegration`. Read more: https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/',\n );\n }\n });\n };\n }\n }\n}\n\nexport const instrumentPrisma = generateInstrumentOnce<{ prismaInstrumentation?: Instrumentation }>(\n INTEGRATION_NAME,\n options => {\n // Use a passed instrumentation instance to support older Prisma versions\n if (options?.prismaInstrumentation) {\n return options.prismaInstrumentation;\n }\n\n return new SentryPrismaInteropInstrumentation();\n },\n);\n\n/**\n * Adds Sentry tracing instrumentation for the [prisma](https://www.npmjs.com/package/prisma) library.\n * For more information, see the [`prismaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/).\n *\n * NOTE: By default, this integration works with Prisma version 6.\n * To get performance instrumentation for other Prisma versions,\n * 1. Install the `@prisma/instrumentation` package with the desired version.\n * 1. Pass a `new PrismaInstrumentation()` instance as exported from `@prisma/instrumentation` to the `prismaInstrumentation` option of this integration:\n *\n * ```js\n * import { PrismaInstrumentation } from '@prisma/instrumentation'\n *\n * Sentry.init({\n * integrations: [\n * prismaIntegration({\n * // Override the default instrumentation that Sentry uses\n * prismaInstrumentation: new PrismaInstrumentation()\n * })\n * ]\n * })\n * ```\n *\n * The passed instrumentation instance will override the default instrumentation instance the integration would use, while the `prismaIntegration` will still ensure data compatibility for the various Prisma versions.\n * 1. Depending on your Prisma version (prior to version 6), add `previewFeatures = [\"tracing\"]` to the client generator block of your Prisma schema:\n *\n * ```\n * generator client {\n * provider = \"prisma-client-js\"\n * previewFeatures = [\"tracing\"]\n * }\n * ```\n */\nexport const prismaIntegration = defineIntegration(\n ({\n prismaInstrumentation,\n }: {\n /**\n * Overrides the instrumentation used by the Sentry SDK with the passed in instrumentation instance.\n *\n * NOTE: By default, the Sentry SDK uses the Prisma v6 instrumentation. Use this option if you need performance instrumentation different Prisma versions.\n *\n * For more information refer to the documentation of `prismaIntegration()` or see https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/\n */\n prismaInstrumentation?: Instrumentation;\n } = {}) => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentPrisma({ prismaInstrumentation });\n },\n setup(client) {\n // If no tracing helper exists, we skip any work here\n // this means that prisma is not being used\n if (!getPrismaTracingHelper()) {\n return;\n }\n\n client.on('spanStart', span => {\n const spanJSON = spanToJSON(span);\n if (spanJSON.description?.startsWith('prisma:')) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');\n }\n\n // Make sure we use the query text as the span name, for ex. SELECT * FROM \"User\" WHERE \"id\" = $1\n if (spanJSON.description === 'prisma:engine:db_query' && spanJSON.data['db.query.text']) {\n span.updateName(spanJSON.data['db.query.text'] as string);\n }\n\n // In Prisma v5.22+, the `db.system` attribute is automatically set\n // On older versions, this is missing, so we add it here\n if (spanJSON.description === 'prisma:engine:db_query' && !spanJSON.data['db.system']) {\n span.setAttribute('db.system', 'prisma');\n }\n });\n },\n };\n },\n);\n"],"names":["consoleSandbox","generateInstrumentOnce","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORI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Y,CAAC,WAAW,EAAE,QAAQ,CAAC;AACpD;AACA,SAAS,CAAC;AACV,OAAO;AACP,KAAK;AACL,GAAG;AACH;;;;;"}
@@ -18,25 +18,30 @@ const INTEGRATION_NAME = 'Tedious';
18
18
  const instrumentTedious = instrument.generateInstrumentOnce(INTEGRATION_NAME, () => new instrumentationTedious.TediousInstrumentation({}));
19
19
 
20
20
  const _tediousIntegration = (() => {
21
+ let instrumentationWrappedCallback;
22
+
21
23
  return {
22
24
  name: INTEGRATION_NAME,
23
25
  setupOnce() {
24
- instrumentTedious();
26
+ const instrumentation = instrumentTedious();
27
+ instrumentationWrappedCallback = instrument.instrumentWhenWrapped(instrumentation);
25
28
  },
26
29
 
27
30
  setup(client) {
28
- client.on('spanStart', span => {
29
- const { description, data } = core.spanToJSON(span);
30
- // Tedius integration always set a span name and `db.system` attribute to `mssql`.
31
- if (!description || data['db.system'] !== 'mssql') {
32
- return;
33
- }
34
-
35
- const operation = description.split(' ')[0] || '';
36
- if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) {
37
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');
38
- }
39
- });
31
+ instrumentationWrappedCallback?.(() =>
32
+ client.on('spanStart', span => {
33
+ const { description, data } = core.spanToJSON(span);
34
+ // Tedius integration always set a span name and `db.system` attribute to `mssql`.
35
+ if (!description || data['db.system'] !== 'mssql') {
36
+ return;
37
+ }
38
+
39
+ const operation = description.split(' ')[0] || '';
40
+ if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) {
41
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');
42
+ }
43
+ }),
44
+ );
40
45
  },
41
46
  };
42
47
  }) ;
@@ -1 +1 @@
1
- {"version":3,"file":"tedious.js","sources":["../../../../src/integrations/tracing/tedious.ts"],"sourcesContent":["import { TediousInstrumentation } from '@opentelemetry/instrumentation-tedious';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce } from '../../otel/instrument';\n\nconst TEDIUS_INSTRUMENTED_METHODS = new Set([\n 'callProcedure',\n 'execSql',\n 'execSqlBatch',\n 'execBulkLoad',\n 'prepare',\n 'execute',\n]);\n\nconst INTEGRATION_NAME = 'Tedious';\n\nexport const instrumentTedious = generateInstrumentOnce(INTEGRATION_NAME, () => new TediousInstrumentation({}));\n\nconst _tediousIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentTedious();\n },\n\n setup(client) {\n client.on('spanStart', span => {\n const { description, data } = spanToJSON(span);\n // Tedius integration always set a span name and `db.system` attribute to `mssql`.\n if (!description || data['db.system'] !== 'mssql') {\n return;\n }\n\n const operation = description.split(' ')[0] || '';\n if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [tedious](https://www.npmjs.com/package/tedious) library.\n *\n * For more information, see the [`tediousIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/tedious/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.tediousIntegration()],\n * });\n * ```\n */\nexport const tediousIntegration = defineIntegration(_tediousIntegration);\n"],"names":["generateInstrumentOnce","TediousInstrumentation","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,2BAA4B,GAAE,IAAI,GAAG,CAAC;AAC5C,EAAE,eAAe;AACjB,EAAE,SAAS;AACX,EAAE,cAAc;AAChB,EAAE,cAAc;AAChB,EAAE,SAAS;AACX,EAAE,SAAS;AACX,CAAC,CAAC;;AAEF,MAAM,gBAAA,GAAmB,SAAS;;MAErB,iBAAkB,GAAEA,iCAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,6CAAsB,CAAC,EAAE,CAAC;;AAE9G,MAAM,mBAAoB,IAAG,MAAM;AACnC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,iBAAiB,EAAE;AACzB,KAAK;;AAEL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACrC,QAAQ,MAAM,EAAE,WAAW,EAAE,IAAA,KAASC,eAAU,CAAC,IAAI,CAAC;AACtD;AACA,QAAQ,IAAI,CAAC,WAAY,IAAG,IAAI,CAAC,WAAW,CAAA,KAAM,OAAO,EAAE;AAC3D,UAAU;AACV;;AAEA,QAAQ,MAAM,SAAA,GAAY,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA,IAAK,EAAE;AACzD,QAAQ,IAAI,2BAA2B,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;AACxD,UAAU,IAAI,CAAC,YAAY,CAACC,qCAAgC,EAAE,sBAAsB,CAAC;AACrF;AACA,OAAO,CAAC;AACR,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,kBAAmB,GAAEC,sBAAiB,CAAC,mBAAmB;;;;;"}
1
+ {"version":3,"file":"tedious.js","sources":["../../../../src/integrations/tracing/tedious.ts"],"sourcesContent":["import { TediousInstrumentation } from '@opentelemetry/instrumentation-tedious';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core';\nimport type { IntegrationFn } from '@sentry/core';\nimport { generateInstrumentOnce, instrumentWhenWrapped } from '../../otel/instrument';\n\nconst TEDIUS_INSTRUMENTED_METHODS = new Set([\n 'callProcedure',\n 'execSql',\n 'execSqlBatch',\n 'execBulkLoad',\n 'prepare',\n 'execute',\n]);\n\nconst INTEGRATION_NAME = 'Tedious';\n\nexport const instrumentTedious = generateInstrumentOnce(INTEGRATION_NAME, () => new TediousInstrumentation({}));\n\nconst _tediousIntegration = (() => {\n let instrumentationWrappedCallback: undefined | ((callback: () => void) => void);\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n const instrumentation = instrumentTedious();\n instrumentationWrappedCallback = instrumentWhenWrapped(instrumentation);\n },\n\n setup(client) {\n instrumentationWrappedCallback?.(() =>\n client.on('spanStart', span => {\n const { description, data } = spanToJSON(span);\n // Tedius integration always set a span name and `db.system` attribute to `mssql`.\n if (!description || data['db.system'] !== 'mssql') {\n return;\n }\n\n const operation = description.split(' ')[0] || '';\n if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');\n }\n }),\n );\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [tedious](https://www.npmjs.com/package/tedious) library.\n *\n * For more information, see the [`tediousIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/tedious/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.tediousIntegration()],\n * });\n * ```\n */\nexport const tediousIntegration = defineIntegration(_tediousIntegration);\n"],"names":["generateInstrumentOnce","TediousInstrumentation","instrumentWhenWrapped","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,2BAA4B,GAAE,IAAI,GAAG,CAAC;AAC5C,EAAE,eAAe;AACjB,EAAE,SAAS;AACX,EAAE,cAAc;AAChB,EAAE,cAAc;AAChB,EAAE,SAAS;AACX,EAAE,SAAS;AACX,CAAC,CAAC;;AAEF,MAAM,gBAAA,GAAmB,SAAS;;MAErB,iBAAkB,GAAEA,iCAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,6CAAsB,CAAC,EAAE,CAAC;;AAE9G,MAAM,mBAAoB,IAAG,MAAM;AACnC,EAAE,IAAI,8BAA8B;;AAEpC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,MAAM,eAAA,GAAkB,iBAAiB,EAAE;AACjD,MAAM,8BAA+B,GAAEC,gCAAqB,CAAC,eAAe,CAAC;AAC7E,KAAK;;AAEL,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,8BAA8B,GAAG;AACvC,QAAQ,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ;AACvC,UAAU,MAAM,EAAE,WAAW,EAAE,IAAA,KAASC,eAAU,CAAC,IAAI,CAAC;AACxD;AACA,UAAU,IAAI,CAAC,WAAY,IAAG,IAAI,CAAC,WAAW,CAAA,KAAM,OAAO,EAAE;AAC7D,YAAY;AACZ;;AAEA,UAAU,MAAM,SAAA,GAAY,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA,IAAK,EAAE;AAC3D,UAAU,IAAI,2BAA2B,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;AAC1D,YAAY,IAAI,CAAC,YAAY,CAACC,qCAAgC,EAAE,sBAAsB,CAAC;AACvF;AACA,SAAS,CAAC;AACV,OAAO;AACP,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,kBAAmB,GAAEC,sBAAiB,CAAC,mBAAmB;;;;;"}
@@ -12,145 +12,146 @@ const INTEGRATION_NAME = 'VercelAI';
12
12
  const instrumentVercelAi = instrument.generateInstrumentOnce(INTEGRATION_NAME, () => new instrumentation.SentryVercelAiInstrumentation({}));
13
13
 
14
14
  const _vercelAIIntegration = (() => {
15
+ let instrumentation;
16
+
15
17
  return {
16
18
  name: INTEGRATION_NAME,
17
19
  setupOnce() {
18
- instrumentVercelAi();
19
- },
20
- processEvent(event) {
21
- if (event.type === 'transaction' && event.spans?.length) {
22
- for (const span of event.spans) {
23
- const { data: attributes, description: name } = span;
24
-
25
- if (!name || span.origin !== 'auto.vercelai.otel') {
26
- continue;
27
- }
28
-
29
- if (attributes['ai.usage.completionTokens'] != undefined) {
30
- attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];
31
- }
32
- if (attributes['ai.usage.promptTokens'] != undefined) {
33
- attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];
34
- }
35
- if (
36
- typeof attributes['ai.usage.completionTokens'] == 'number' &&
37
- typeof attributes['ai.usage.promptTokens'] == 'number'
38
- ) {
39
- attributes['ai.total_tokens.used'] =
40
- attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];
41
- }
42
- }
43
- }
44
-
45
- return event;
20
+ instrumentation = instrumentVercelAi();
46
21
  },
47
22
  setup(client) {
48
- client.on('spanStart', span => {
49
- if (!instrumentation.sentryVercelAiPatched) {
50
- return;
51
- }
52
-
53
- const { data: attributes, description: name } = core.spanToJSON(span);
54
-
55
- if (!name) {
56
- return;
57
- }
58
-
59
- // The id of the model
60
- const aiModelId = attributes['ai.model.id'];
61
-
62
- // the provider of the model
63
- const aiModelProvider = attributes['ai.model.provider'];
64
-
65
- // both of these must be defined for the integration to work
66
- if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {
67
- return;
68
- }
69
-
70
- let isPipelineSpan = false;
71
-
72
- switch (name) {
73
- case 'ai.generateText': {
74
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');
75
- isPipelineSpan = true;
76
- break;
77
- }
78
- case 'ai.generateText.doGenerate': {
79
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
80
- break;
81
- }
82
- case 'ai.streamText': {
83
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');
84
- isPipelineSpan = true;
85
- break;
86
- }
87
- case 'ai.streamText.doStream': {
88
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
89
- break;
90
- }
91
- case 'ai.generateObject': {
92
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');
93
- isPipelineSpan = true;
94
- break;
95
- }
96
- case 'ai.generateObject.doGenerate': {
97
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
98
- break;
99
- }
100
- case 'ai.streamObject': {
101
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');
102
- isPipelineSpan = true;
103
- break;
104
- }
105
- case 'ai.streamObject.doStream': {
106
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
107
- break;
108
- }
109
- case 'ai.embed': {
110
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');
111
- isPipelineSpan = true;
112
- break;
113
- }
114
- case 'ai.embed.doEmbed': {
115
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
116
- break;
117
- }
118
- case 'ai.embedMany': {
119
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');
120
- isPipelineSpan = true;
121
- break;
122
- }
123
- case 'ai.embedMany.doEmbed': {
124
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
125
- break;
126
- }
127
- case 'ai.toolCall':
128
- case 'ai.stream.firstChunk':
129
- case 'ai.stream.finish':
130
- span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');
131
- break;
132
- }
133
-
134
- addOriginToSpan.addOriginToSpan(span, 'auto.vercelai.otel');
135
-
136
- const nameWthoutAi = name.replace('ai.', '');
137
- span.setAttribute('ai.pipeline.name', nameWthoutAi);
138
- span.updateName(nameWthoutAi);
139
-
140
- // If a Telemetry name is set and it is a pipeline span, use that as the operation name
141
- const functionId = attributes['ai.telemetry.functionId'];
142
- if (functionId && typeof functionId === 'string' && isPipelineSpan) {
143
- span.updateName(functionId);
144
- span.setAttribute('ai.pipeline.name', functionId);
145
- }
146
-
147
- if (attributes['ai.prompt']) {
148
- span.setAttribute('ai.input_messages', attributes['ai.prompt']);
149
- }
150
- if (attributes['ai.model.id']) {
151
- span.setAttribute('ai.model_id', attributes['ai.model.id']);
152
- }
153
- span.setAttribute('ai.streaming', name.includes('stream'));
23
+ instrumentation?.callWhenPatched(() => {
24
+ client.on('spanStart', span => {
25
+ const { data: attributes, description: name } = core.spanToJSON(span);
26
+
27
+ if (!name) {
28
+ return;
29
+ }
30
+
31
+ // The id of the model
32
+ const aiModelId = attributes['ai.model.id'];
33
+
34
+ // the provider of the model
35
+ const aiModelProvider = attributes['ai.model.provider'];
36
+
37
+ // both of these must be defined for the integration to work
38
+ if (typeof aiModelId !== 'string' || typeof aiModelProvider !== 'string' || !aiModelId || !aiModelProvider) {
39
+ return;
40
+ }
41
+
42
+ let isPipelineSpan = false;
43
+
44
+ switch (name) {
45
+ case 'ai.generateText': {
46
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateText');
47
+ isPipelineSpan = true;
48
+ break;
49
+ }
50
+ case 'ai.generateText.doGenerate': {
51
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
52
+ break;
53
+ }
54
+ case 'ai.streamText': {
55
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamText');
56
+ isPipelineSpan = true;
57
+ break;
58
+ }
59
+ case 'ai.streamText.doStream': {
60
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
61
+ break;
62
+ }
63
+ case 'ai.generateObject': {
64
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.generateObject');
65
+ isPipelineSpan = true;
66
+ break;
67
+ }
68
+ case 'ai.generateObject.doGenerate': {
69
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doGenerate');
70
+ break;
71
+ }
72
+ case 'ai.streamObject': {
73
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.streamObject');
74
+ isPipelineSpan = true;
75
+ break;
76
+ }
77
+ case 'ai.streamObject.doStream': {
78
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run.doStream');
79
+ break;
80
+ }
81
+ case 'ai.embed': {
82
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embed');
83
+ isPipelineSpan = true;
84
+ break;
85
+ }
86
+ case 'ai.embed.doEmbed': {
87
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
88
+ break;
89
+ }
90
+ case 'ai.embedMany': {
91
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.pipeline.embedMany');
92
+ isPipelineSpan = true;
93
+ break;
94
+ }
95
+ case 'ai.embedMany.doEmbed': {
96
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.embeddings');
97
+ break;
98
+ }
99
+ case 'ai.toolCall':
100
+ case 'ai.stream.firstChunk':
101
+ case 'ai.stream.finish':
102
+ span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'ai.run');
103
+ break;
104
+ }
105
+
106
+ addOriginToSpan.addOriginToSpan(span, 'auto.vercelai.otel');
107
+
108
+ const nameWthoutAi = name.replace('ai.', '');
109
+ span.setAttribute('ai.pipeline.name', nameWthoutAi);
110
+ span.updateName(nameWthoutAi);
111
+
112
+ // If a Telemetry name is set and it is a pipeline span, use that as the operation name
113
+ const functionId = attributes['ai.telemetry.functionId'];
114
+ if (functionId && typeof functionId === 'string' && isPipelineSpan) {
115
+ span.updateName(functionId);
116
+ span.setAttribute('ai.pipeline.name', functionId);
117
+ }
118
+
119
+ if (attributes['ai.prompt']) {
120
+ span.setAttribute('ai.input_messages', attributes['ai.prompt']);
121
+ }
122
+ if (attributes['ai.model.id']) {
123
+ span.setAttribute('ai.model_id', attributes['ai.model.id']);
124
+ }
125
+ span.setAttribute('ai.streaming', name.includes('stream'));
126
+ });
127
+
128
+ client.addEventProcessor(event => {
129
+ if (event.type === 'transaction' && event.spans?.length) {
130
+ for (const span of event.spans) {
131
+ const { data: attributes, description: name } = span;
132
+
133
+ if (!name || span.origin !== 'auto.vercelai.otel') {
134
+ continue;
135
+ }
136
+
137
+ if (attributes['ai.usage.completionTokens'] != undefined) {
138
+ attributes['ai.completion_tokens.used'] = attributes['ai.usage.completionTokens'];
139
+ }
140
+ if (attributes['ai.usage.promptTokens'] != undefined) {
141
+ attributes['ai.prompt_tokens.used'] = attributes['ai.usage.promptTokens'];
142
+ }
143
+ if (
144
+ typeof attributes['ai.usage.completionTokens'] == 'number' &&
145
+ typeof attributes['ai.usage.promptTokens'] == 'number'
146
+ ) {
147
+ attributes['ai.total_tokens.used'] =
148
+ attributes['ai.usage.completionTokens'] + attributes['ai.usage.promptTokens'];
149
+ }
150
+ }
151
+ }
152
+
153
+ return event;
154
+ });
154
155
  });
155
156
  },
156
157
  };
@@ -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":["generateInstrumentOnce","SentryVercelAiInstrumentation","sentryVercelAiPatched","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","addOriginToSpan","defineIntegration"],"mappings":";;;;;;;AAAA;;AAOA,MAAM,gBAAA,GAAmB,UAAU;;MAEtB,kBAAmB,GAAEA,iCAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,6CAA6B,CAAC,EAAE,CAAC;;AAEtH,MAAM,oBAAqB,IAAG,MAAM;AACpC,EAAE,OAAO;AACT,IAAI,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AI,UAAA,IAAc,OAAO,eAAe,QAAA,IAAY,cAAc,EAAE;AAC5E,UAAU,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;AACrC,UAAU,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,UAAU,CAAC;AAC3D;;AAEA,QAAQ,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE;AACrC,UAAU,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;AACzE;AACA,QAAQ,IAAI,UAAU,CAAC,aAAa,CAAC,EAAE;AACvC,UAAU,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;AACrE;AACA,QAAQ,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAClE,OAAO,CAAC;AACR,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;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;AACA;AACA;AACA;AACA;AACA;AACA;MACa,mBAAoB,GAAEC,sBAAiB,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":["generateInstrumentOnce","SentryVercelAiInstrumentation","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","addOriginToSpan","defineIntegration"],"mappings":";;;;;;;AAAA;;AAOA,MAAM,gBAAA,GAAmB,UAAU;;MAEtB,kBAAmB,GAAEA,iCAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,6CAA6B,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;AA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BAAuB,CAAE,IAAG,SAAS,EAAE;AACpE,gBAAgB,UAAU,CAAC,uBAAuB,CAAA,GAAI,UAAU,CAAC,uBAAuB,CAAC;AACzF;AACA,cAAc;AACd,gBAAgB,OAAO,UAAU,CAAC,2BAA2B,CAAA,IAAK,QAAS;AAC3E,gBAAgB,OAAO,UAAU,CAAC,uBAAuB,KAAK;AAC9D,gBAAgB;AAChB,gBAAgB,UAAU,CAAC,sBAAsB,CAAE;AACnD,kBAAkB,UAAU,CAAC,2BAA2B,CAAA,GAAI,UAAU,CAAC,uBAAuB,CAAC;AAC/F;AACA;AACA;;AAEA,UAAU,OAAO,KAAK;AACtB,SAAS,CAAC;AACV,OAAO,CAAC;AACR,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH;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;AACA;AACA;AACA;AACA;AACA;AACA;MACa,mBAAoB,GAAEC,sBAAiB,CAAC,oBAAoB;;;;;"}
@@ -14,8 +14,6 @@ const INSTRUMENTED_METHODS = [
14
14
  'embedMany',
15
15
  ] ;
16
16
 
17
- exports.sentryVercelAiPatched = false;
18
-
19
17
  /**
20
18
  * This detects is added by the Sentry Vercel AI Integration to detect if the integration should
21
19
  * be enabled.
@@ -23,9 +21,11 @@ exports.sentryVercelAiPatched = false;
23
21
  * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.
24
22
  */
25
23
  class SentryVercelAiInstrumentation extends instrumentation.InstrumentationBase {
24
+ __init() {this._isPatched = false;}
25
+ __init2() {this._callbacks = [];}
26
+
26
27
  constructor(config = {}) {
27
- super('@sentry/instrumentation-vercel-ai', core.SDK_VERSION, config);
28
- }
28
+ super('@sentry/instrumentation-vercel-ai', core.SDK_VERSION, config);SentryVercelAiInstrumentation.prototype.__init.call(this);SentryVercelAiInstrumentation.prototype.__init2.call(this); }
29
29
 
30
30
  /**
31
31
  * Initializes the instrumentation by defining the modules to be patched.
@@ -35,11 +35,26 @@ class SentryVercelAiInstrumentation extends instrumentation.InstrumentationBase
35
35
  return module;
36
36
  }
37
37
 
38
+ /**
39
+ * Call the provided callback when the module is patched.
40
+ * If it has already been patched, the callback will be called immediately.
41
+ */
42
+ callWhenPatched(callback) {
43
+ if (this._isPatched) {
44
+ callback();
45
+ } else {
46
+ this._callbacks.push(callback);
47
+ }
48
+ }
49
+
38
50
  /**
39
51
  * Patches module exports to enable Vercel AI telemetry.
40
52
  */
41
53
  _patch(moduleExports) {
42
- exports.sentryVercelAiPatched = true;
54
+ this._isPatched = true;
55
+
56
+ this._callbacks.forEach(callback => callback());
57
+ this._callbacks = [];
43
58
 
44
59
  function generatePatch(name) {
45
60
  return (...args) => {