@sentry/core 10.30.0 → 10.32.0-alpha.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 (194) hide show
  1. package/build/cjs/attributes.js +98 -0
  2. package/build/cjs/attributes.js.map +1 -0
  3. package/build/cjs/client.js +11 -6
  4. package/build/cjs/client.js.map +1 -1
  5. package/build/cjs/envelope.js +41 -7
  6. package/build/cjs/envelope.js.map +1 -1
  7. package/build/cjs/index.js +30 -0
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/integrations/eventFilters.js +1 -1
  10. package/build/cjs/integrations/eventFilters.js.map +1 -1
  11. package/build/cjs/integrations/mcp-server/correlation.js +17 -3
  12. package/build/cjs/integrations/mcp-server/correlation.js.map +1 -1
  13. package/build/cjs/integrations/mcp-server/sessionExtraction.js +44 -0
  14. package/build/cjs/integrations/mcp-server/sessionExtraction.js.map +1 -1
  15. package/build/cjs/integrations/mcp-server/transport.js +17 -3
  16. package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
  17. package/build/cjs/integrations/requestdata.js +72 -6
  18. package/build/cjs/integrations/requestdata.js.map +1 -1
  19. package/build/cjs/integrations/serverSpanStreaming.js +51 -0
  20. package/build/cjs/integrations/serverSpanStreaming.js.map +1 -0
  21. package/build/cjs/semanticAttributes.js +36 -0
  22. package/build/cjs/semanticAttributes.js.map +1 -1
  23. package/build/cjs/spans/captureSpan.js +107 -0
  24. package/build/cjs/spans/captureSpan.js.map +1 -0
  25. package/build/cjs/spans/spanBuffer.js +117 -0
  26. package/build/cjs/spans/spanBuffer.js.map +1 -0
  27. package/build/cjs/spans/spanFirstUtils.js +187 -0
  28. package/build/cjs/spans/spanFirstUtils.js.map +1 -0
  29. package/build/cjs/tracing/ai/messageTruncation.js +120 -11
  30. package/build/cjs/tracing/ai/messageTruncation.js.map +1 -1
  31. package/build/cjs/tracing/google-genai/index.js +31 -14
  32. package/build/cjs/tracing/google-genai/index.js.map +1 -1
  33. package/build/cjs/tracing/google-genai/utils.js +24 -5
  34. package/build/cjs/tracing/google-genai/utils.js.map +1 -1
  35. package/build/cjs/tracing/sentrySpan.js +31 -0
  36. package/build/cjs/tracing/sentrySpan.js.map +1 -1
  37. package/build/cjs/tracing/trace.js +1 -0
  38. package/build/cjs/tracing/trace.js.map +1 -1
  39. package/build/cjs/tracing/vercel-ai/index.js +4 -5
  40. package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
  41. package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js +0 -10
  42. package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
  43. package/build/cjs/utils/applyScopeDataToEvent.js +5 -0
  44. package/build/cjs/utils/applyScopeDataToEvent.js.map +1 -1
  45. package/build/cjs/utils/beforeSendSpan.js +36 -0
  46. package/build/cjs/utils/beforeSendSpan.js.map +1 -0
  47. package/build/cjs/utils/featureFlags.js +1 -0
  48. package/build/cjs/utils/featureFlags.js.map +1 -1
  49. package/build/cjs/utils/request.js +75 -12
  50. package/build/cjs/utils/request.js.map +1 -1
  51. package/build/cjs/utils/should-ignore-span.js +31 -9
  52. package/build/cjs/utils/should-ignore-span.js.map +1 -1
  53. package/build/cjs/utils/spanUtils.js +101 -2
  54. package/build/cjs/utils/spanUtils.js.map +1 -1
  55. package/build/cjs/utils/traceData.js +1 -4
  56. package/build/cjs/utils/traceData.js.map +1 -1
  57. package/build/cjs/utils/version.js +1 -1
  58. package/build/cjs/utils/version.js.map +1 -1
  59. package/build/esm/attributes.js +95 -0
  60. package/build/esm/attributes.js.map +1 -0
  61. package/build/esm/client.js +6 -1
  62. package/build/esm/client.js.map +1 -1
  63. package/build/esm/envelope.js +41 -8
  64. package/build/esm/envelope.js.map +1 -1
  65. package/build/esm/index.js +10 -4
  66. package/build/esm/index.js.map +1 -1
  67. package/build/esm/integrations/eventFilters.js +1 -1
  68. package/build/esm/integrations/eventFilters.js.map +1 -1
  69. package/build/esm/integrations/mcp-server/correlation.js +17 -3
  70. package/build/esm/integrations/mcp-server/correlation.js.map +1 -1
  71. package/build/esm/integrations/mcp-server/sessionExtraction.js +43 -1
  72. package/build/esm/integrations/mcp-server/sessionExtraction.js.map +1 -1
  73. package/build/esm/integrations/mcp-server/transport.js +18 -4
  74. package/build/esm/integrations/mcp-server/transport.js.map +1 -1
  75. package/build/esm/integrations/requestdata.js +72 -6
  76. package/build/esm/integrations/requestdata.js.map +1 -1
  77. package/build/esm/integrations/serverSpanStreaming.js +49 -0
  78. package/build/esm/integrations/serverSpanStreaming.js.map +1 -0
  79. package/build/esm/package.json +1 -1
  80. package/build/esm/semanticAttributes.js +26 -1
  81. package/build/esm/semanticAttributes.js.map +1 -1
  82. package/build/esm/spans/captureSpan.js +105 -0
  83. package/build/esm/spans/captureSpan.js.map +1 -0
  84. package/build/esm/spans/spanBuffer.js +115 -0
  85. package/build/esm/spans/spanBuffer.js.map +1 -0
  86. package/build/esm/spans/spanFirstUtils.js +183 -0
  87. package/build/esm/spans/spanFirstUtils.js.map +1 -0
  88. package/build/esm/tracing/ai/messageTruncation.js +121 -11
  89. package/build/esm/tracing/ai/messageTruncation.js.map +1 -1
  90. package/build/esm/tracing/google-genai/index.js +34 -17
  91. package/build/esm/tracing/google-genai/index.js.map +1 -1
  92. package/build/esm/tracing/google-genai/utils.js +24 -6
  93. package/build/esm/tracing/google-genai/utils.js.map +1 -1
  94. package/build/esm/tracing/sentrySpan.js +32 -1
  95. package/build/esm/tracing/sentrySpan.js.map +1 -1
  96. package/build/esm/tracing/trace.js +1 -0
  97. package/build/esm/tracing/trace.js.map +1 -1
  98. package/build/esm/tracing/vercel-ai/index.js +5 -6
  99. package/build/esm/tracing/vercel-ai/index.js.map +1 -1
  100. package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js +1 -10
  101. package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
  102. package/build/esm/utils/applyScopeDataToEvent.js +5 -0
  103. package/build/esm/utils/applyScopeDataToEvent.js.map +1 -1
  104. package/build/esm/utils/beforeSendSpan.js +33 -0
  105. package/build/esm/utils/beforeSendSpan.js.map +1 -0
  106. package/build/esm/utils/featureFlags.js +1 -0
  107. package/build/esm/utils/featureFlags.js.map +1 -1
  108. package/build/esm/utils/request.js +76 -13
  109. package/build/esm/utils/request.js.map +1 -1
  110. package/build/esm/utils/should-ignore-span.js +31 -9
  111. package/build/esm/utils/should-ignore-span.js.map +1 -1
  112. package/build/esm/utils/spanUtils.js +97 -3
  113. package/build/esm/utils/spanUtils.js.map +1 -1
  114. package/build/esm/utils/traceData.js +1 -4
  115. package/build/esm/utils/traceData.js.map +1 -1
  116. package/build/esm/utils/version.js +1 -1
  117. package/build/esm/utils/version.js.map +1 -1
  118. package/build/types/attributes.d.ts +2 -2
  119. package/build/types/attributes.d.ts.map +1 -1
  120. package/build/types/client.d.ts +40 -2
  121. package/build/types/client.d.ts.map +1 -1
  122. package/build/types/envelope.d.ts +6 -1
  123. package/build/types/envelope.d.ts.map +1 -1
  124. package/build/types/index.d.ts +12 -5
  125. package/build/types/index.d.ts.map +1 -1
  126. package/build/types/integrations/mcp-server/correlation.d.ts +2 -2
  127. package/build/types/integrations/mcp-server/correlation.d.ts.map +1 -1
  128. package/build/types/integrations/mcp-server/sessionExtraction.d.ts +13 -1
  129. package/build/types/integrations/mcp-server/sessionExtraction.d.ts.map +1 -1
  130. package/build/types/integrations/mcp-server/transport.d.ts.map +1 -1
  131. package/build/types/integrations/requestdata.d.ts.map +1 -1
  132. package/build/types/integrations/serverSpanStreaming.d.ts +8 -0
  133. package/build/types/integrations/serverSpanStreaming.d.ts.map +1 -0
  134. package/build/types/semanticAttributes.d.ts +21 -0
  135. package/build/types/semanticAttributes.d.ts.map +1 -1
  136. package/build/types/spans/captureSpan.d.ts +10 -0
  137. package/build/types/spans/captureSpan.d.ts.map +1 -0
  138. package/build/types/spans/spanBuffer.d.ts +31 -0
  139. package/build/types/spans/spanBuffer.d.ts.map +1 -0
  140. package/build/types/spans/spanFirstUtils.d.ts +20 -0
  141. package/build/types/spans/spanFirstUtils.d.ts.map +1 -0
  142. package/build/types/tracing/ai/messageTruncation.d.ts +0 -20
  143. package/build/types/tracing/ai/messageTruncation.d.ts.map +1 -1
  144. package/build/types/tracing/google-genai/index.d.ts.map +1 -1
  145. package/build/types/tracing/google-genai/utils.d.ts +25 -0
  146. package/build/types/tracing/google-genai/utils.d.ts.map +1 -1
  147. package/build/types/tracing/sentrySpan.d.ts +10 -1
  148. package/build/types/tracing/sentrySpan.d.ts.map +1 -1
  149. package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
  150. package/build/types/types-hoist/attributes.d.ts +19 -0
  151. package/build/types/types-hoist/attributes.d.ts.map +1 -0
  152. package/build/types/types-hoist/envelope.d.ts +22 -2
  153. package/build/types/types-hoist/envelope.d.ts.map +1 -1
  154. package/build/types/types-hoist/link.d.ts +2 -2
  155. package/build/types/types-hoist/link.d.ts.map +1 -1
  156. package/build/types/types-hoist/options.d.ts +31 -2
  157. package/build/types/types-hoist/options.d.ts.map +1 -1
  158. package/build/types/types-hoist/span.d.ts +27 -0
  159. package/build/types/types-hoist/span.d.ts.map +1 -1
  160. package/build/types/utils/applyScopeDataToEvent.d.ts.map +1 -1
  161. package/build/types/utils/beforeSendSpan.d.ts +22 -0
  162. package/build/types/utils/beforeSendSpan.d.ts.map +1 -0
  163. package/build/types/utils/featureFlags.d.ts.map +1 -1
  164. package/build/types/utils/request.d.ts +1 -1
  165. package/build/types/utils/request.d.ts.map +1 -1
  166. package/build/types/utils/should-ignore-span.d.ts +3 -3
  167. package/build/types/utils/should-ignore-span.d.ts.map +1 -1
  168. package/build/types/utils/spanUtils.d.ts +26 -2
  169. package/build/types/utils/spanUtils.d.ts.map +1 -1
  170. package/build/types/utils/traceData.d.ts.map +1 -1
  171. package/build/types-ts3.8/attributes.d.ts +2 -2
  172. package/build/types-ts3.8/client.d.ts +40 -2
  173. package/build/types-ts3.8/envelope.d.ts +6 -1
  174. package/build/types-ts3.8/index.d.ts +12 -5
  175. package/build/types-ts3.8/integrations/mcp-server/correlation.d.ts +2 -2
  176. package/build/types-ts3.8/integrations/mcp-server/sessionExtraction.d.ts +13 -1
  177. package/build/types-ts3.8/integrations/serverSpanStreaming.d.ts +8 -0
  178. package/build/types-ts3.8/semanticAttributes.d.ts +21 -0
  179. package/build/types-ts3.8/spans/captureSpan.d.ts +10 -0
  180. package/build/types-ts3.8/spans/spanBuffer.d.ts +31 -0
  181. package/build/types-ts3.8/spans/spanFirstUtils.d.ts +20 -0
  182. package/build/types-ts3.8/tracing/ai/messageTruncation.d.ts +0 -20
  183. package/build/types-ts3.8/tracing/google-genai/utils.d.ts +25 -0
  184. package/build/types-ts3.8/tracing/sentrySpan.d.ts +10 -1
  185. package/build/types-ts3.8/types-hoist/attributes.d.ts +19 -0
  186. package/build/types-ts3.8/types-hoist/envelope.d.ts +22 -2
  187. package/build/types-ts3.8/types-hoist/link.d.ts +2 -2
  188. package/build/types-ts3.8/types-hoist/options.d.ts +31 -2
  189. package/build/types-ts3.8/types-hoist/span.d.ts +27 -0
  190. package/build/types-ts3.8/utils/beforeSendSpan.d.ts +22 -0
  191. package/build/types-ts3.8/utils/request.d.ts +1 -1
  192. package/build/types-ts3.8/utils/should-ignore-span.d.ts +3 -3
  193. package/build/types-ts3.8/utils/spanUtils.d.ts +26 -2
  194. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const dynamicSamplingContext = require('./tracing/dynamicSamplingContext.js');
4
+ const beforeSendSpan = require('./utils/beforeSendSpan.js');
4
5
  const dsn = require('./utils/dsn.js');
5
6
  const envelope = require('./utils/envelope.js');
6
7
  const shouldIgnoreSpan = require('./utils/should-ignore-span.js');
@@ -97,10 +98,6 @@ function createEventEnvelope(
97
98
  * Takes an optional client and runs spans through `beforeSendSpan` if available.
98
99
  */
99
100
  function createSpanEnvelope(spans, client) {
100
- function dscHasRequiredProps(dsc) {
101
- return !!dsc.trace_id && !!dsc.public_key;
102
- }
103
-
104
101
  // For the moment we'll obtain the DSC from the first span in the array
105
102
  // This might need to be changed if we permit sending multiple spans from
106
103
  // different segments in one envelope
@@ -115,7 +112,8 @@ function createSpanEnvelope(spans, client) {
115
112
  ...(!!tunnel && dsn$1 && { dsn: dsn.dsnToString(dsn$1) }),
116
113
  };
117
114
 
118
- const { beforeSendSpan, ignoreSpans } = client?.getOptions() || {};
115
+ const options = client?.getOptions();
116
+ const ignoreSpans = options?.ignoreSpans;
119
117
 
120
118
  const filteredSpans = ignoreSpans?.length
121
119
  ? spans.filter(span => !shouldIgnoreSpan.shouldIgnoreSpan(spanUtils.spanToJSON(span), ignoreSpans))
@@ -126,10 +124,14 @@ function createSpanEnvelope(spans, client) {
126
124
  client?.recordDroppedEvent('before_send', 'span', droppedSpans);
127
125
  }
128
126
 
129
- const convertToSpanJSON = beforeSendSpan
127
+ // checking against traceLifeCycle so that TS can infer the correct type for
128
+ // beforeSendSpan. This is a workaround for now as most likely, this entire function
129
+ // will be removed in the future (once we send standalone spans as spans v2)
130
+ const convertToSpanJSON = options?.beforeSendSpan
130
131
  ? (span) => {
131
132
  const spanJson = spanUtils.spanToJSON(span);
132
- const processedSpan = beforeSendSpan(spanJson);
133
+ const processedSpan =
134
+ !beforeSendSpan.isV2BeforeSendSpanCallback(options?.beforeSendSpan) && options?.beforeSendSpan?.(spanJson);
133
135
 
134
136
  if (!processedSpan) {
135
137
  spanUtils.showSpanDropWarning();
@@ -151,8 +153,40 @@ function createSpanEnvelope(spans, client) {
151
153
  return envelope.createEnvelope(headers, items);
152
154
  }
153
155
 
156
+ /**
157
+ * Creates a span v2 envelope
158
+ */
159
+ function createSpanV2Envelope(
160
+ serializedSpans,
161
+ dsc,
162
+ client,
163
+ ) {
164
+ const dsn$1 = client?.getDsn();
165
+ const tunnel = client?.getOptions().tunnel;
166
+ const sdk = client?.getOptions()._metadata?.sdk;
167
+
168
+ const headers = {
169
+ sent_at: new Date().toISOString(),
170
+ ...(dscHasRequiredProps(dsc) && { trace: dsc }),
171
+ ...(sdk && { sdk: sdk }),
172
+ ...(!!tunnel && dsn$1 && { dsn: dsn.dsnToString(dsn$1) }),
173
+ };
174
+
175
+ const spanContainer = [
176
+ { type: 'span', item_count: serializedSpans.length, content_type: 'application/vnd.sentry.items.span.v2+json' },
177
+ { items: serializedSpans },
178
+ ];
179
+
180
+ return envelope.createEnvelope(headers, [spanContainer]);
181
+ }
182
+
183
+ function dscHasRequiredProps(dsc) {
184
+ return !!dsc.trace_id && !!dsc.public_key;
185
+ }
186
+
154
187
  exports._enhanceEventWithSdkInfo = _enhanceEventWithSdkInfo;
155
188
  exports.createEventEnvelope = createEventEnvelope;
156
189
  exports.createSessionEnvelope = createSessionEnvelope;
157
190
  exports.createSpanEnvelope = createSpanEnvelope;
191
+ exports.createSpanV2Envelope = createSpanV2Envelope;
158
192
  //# sourceMappingURL=envelope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sources":["../../src/envelope.ts"],"sourcesContent":["import type { Client } from './client';\nimport { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';\nimport type { SentrySpan } from './tracing/sentrySpan';\nimport type { LegacyCSPReport } from './types-hoist/csp';\nimport type { DsnComponents } from './types-hoist/dsn';\nimport type {\n DynamicSamplingContext,\n EventEnvelope,\n EventItem,\n RawSecurityEnvelope,\n RawSecurityItem,\n SessionEnvelope,\n SessionItem,\n SpanEnvelope,\n SpanItem,\n} from './types-hoist/envelope';\nimport type { Event } from './types-hoist/event';\nimport type { SdkInfo } from './types-hoist/sdkinfo';\nimport type { SdkMetadata } from './types-hoist/sdkmetadata';\nimport type { Session, SessionAggregates } from './types-hoist/session';\nimport { dsnToString } from './utils/dsn';\nimport {\n createEnvelope,\n createEventEnvelopeHeaders,\n createSpanEnvelopeItem,\n getSdkMetadataForEnvelopeHeader,\n} from './utils/envelope';\nimport { uuid4 } from './utils/misc';\nimport { shouldIgnoreSpan } from './utils/should-ignore-span';\nimport { showSpanDropWarning, spanToJSON } from './utils/spanUtils';\n\n/**\n * Apply SdkInfo (name, version, packages, integrations) to the corresponding event key.\n * Merge with existing data if any.\n *\n * @internal, exported only for testing\n **/\nexport function _enhanceEventWithSdkInfo(event: Event, newSdkInfo?: SdkInfo): Event {\n if (!newSdkInfo) {\n return event;\n }\n\n const eventSdkInfo = event.sdk || {};\n\n event.sdk = {\n ...eventSdkInfo,\n name: eventSdkInfo.name || newSdkInfo.name,\n version: eventSdkInfo.version || newSdkInfo.version,\n integrations: [...(event.sdk?.integrations || []), ...(newSdkInfo.integrations || [])],\n packages: [...(event.sdk?.packages || []), ...(newSdkInfo.packages || [])],\n settings:\n event.sdk?.settings || newSdkInfo.settings\n ? {\n ...event.sdk?.settings,\n ...newSdkInfo.settings,\n }\n : undefined,\n };\n\n return event;\n}\n\n/** Creates an envelope from a Session */\nexport function createSessionEnvelope(\n session: Session | SessionAggregates,\n dsn?: DsnComponents,\n metadata?: SdkMetadata,\n tunnel?: string,\n): SessionEnvelope {\n const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);\n const envelopeHeaders = {\n sent_at: new Date().toISOString(),\n ...(sdkInfo && { sdk: sdkInfo }),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const envelopeItem: SessionItem =\n 'aggregates' in session ? [{ type: 'sessions' }, session] : [{ type: 'session' }, session.toJSON()];\n\n return createEnvelope<SessionEnvelope>(envelopeHeaders, [envelopeItem]);\n}\n\n/**\n * Create an Envelope from an event.\n */\nexport function createEventEnvelope(\n event: Event,\n dsn?: DsnComponents,\n metadata?: SdkMetadata,\n tunnel?: string,\n): EventEnvelope {\n const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);\n\n /*\n Note: Due to TS, event.type may be `replay_event`, theoretically.\n In practice, we never call `createEventEnvelope` with `replay_event` type,\n and we'd have to adjust a looot of types to make this work properly.\n We want to avoid casting this around, as that could lead to bugs (e.g. when we add another type)\n So the safe choice is to really guard against the replay_event type here.\n */\n const eventType = event.type && event.type !== 'replay_event' ? event.type : 'event';\n\n _enhanceEventWithSdkInfo(event, metadata?.sdk);\n\n const envelopeHeaders = createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn);\n\n // Prevent this data (which, if it exists, was used in earlier steps in the processing pipeline) from being sent to\n // sentry. (Note: Our use of this property comes and goes with whatever we might be debugging, whatever hacks we may\n // have temporarily added, etc. Even if we don't happen to be using it at some point in the future, let's not get rid\n // of this `delete`, lest we miss putting it back in the next time the property is in use.)\n delete event.sdkProcessingMetadata;\n\n const eventItem: EventItem = [{ type: eventType }, event];\n return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);\n}\n\n/**\n * Create envelope from Span item.\n *\n * Takes an optional client and runs spans through `beforeSendSpan` if available.\n */\nexport function createSpanEnvelope(spans: [SentrySpan, ...SentrySpan[]], client?: Client): SpanEnvelope {\n function dscHasRequiredProps(dsc: Partial<DynamicSamplingContext>): dsc is DynamicSamplingContext {\n return !!dsc.trace_id && !!dsc.public_key;\n }\n\n // For the moment we'll obtain the DSC from the first span in the array\n // This might need to be changed if we permit sending multiple spans from\n // different segments in one envelope\n const dsc = getDynamicSamplingContextFromSpan(spans[0]);\n\n const dsn = client?.getDsn();\n const tunnel = client?.getOptions().tunnel;\n\n const headers: SpanEnvelope[0] = {\n sent_at: new Date().toISOString(),\n ...(dscHasRequiredProps(dsc) && { trace: dsc }),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const { beforeSendSpan, ignoreSpans } = client?.getOptions() || {};\n\n const filteredSpans = ignoreSpans?.length\n ? spans.filter(span => !shouldIgnoreSpan(spanToJSON(span), ignoreSpans))\n : spans;\n const droppedSpans = spans.length - filteredSpans.length;\n\n if (droppedSpans) {\n client?.recordDroppedEvent('before_send', 'span', droppedSpans);\n }\n\n const convertToSpanJSON = beforeSendSpan\n ? (span: SentrySpan) => {\n const spanJson = spanToJSON(span);\n const processedSpan = beforeSendSpan(spanJson);\n\n if (!processedSpan) {\n showSpanDropWarning();\n return spanJson;\n }\n\n return processedSpan;\n }\n : spanToJSON;\n\n const items: SpanItem[] = [];\n for (const span of filteredSpans) {\n const spanJson = convertToSpanJSON(span);\n if (spanJson) {\n items.push(createSpanEnvelopeItem(spanJson));\n }\n }\n\n return createEnvelope<SpanEnvelope>(headers, items);\n}\n\n/**\n * Create an Envelope from a CSP report.\n */\nexport function createRawSecurityEnvelope(\n report: LegacyCSPReport,\n dsn: DsnComponents,\n tunnel?: string,\n release?: string,\n environment?: string,\n): RawSecurityEnvelope {\n const envelopeHeaders = {\n event_id: uuid4(),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const eventItem: RawSecurityItem = [\n { type: 'raw_security', sentry_release: release, sentry_environment: environment },\n report,\n ];\n\n return createEnvelope<RawSecurityEnvelope>(envelopeHeaders, [eventItem]);\n}\n"],"names":["dsn","getSdkMetadataForEnvelopeHeader","dsnToString","createEnvelope","createEventEnvelopeHeaders","getDynamicSamplingContextFromSpan","shouldIgnoreSpan","spanToJSON","showSpanDropWarning","createSpanEnvelopeItem"],"mappings":";;;;;;;;AA+BA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB,CAAC,KAAK,EAAS,UAAU,EAAmB;AACpF,EAAE,IAAI,CAAC,UAAU,EAAE;AACnB,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,MAAM,eAAe,KAAK,CAAC,GAAA,IAAO,EAAE;;AAEtC,EAAE,KAAK,CAAC,GAAA,GAAM;AACd,IAAI,GAAG,YAAY;AACnB,IAAI,IAAI,EAAE,YAAY,CAAC,QAAQ,UAAU,CAAC,IAAI;AAC9C,IAAI,OAAO,EAAE,YAAY,CAAC,WAAW,UAAU,CAAC,OAAO;AACvD,IAAI,YAAY,EAAE,CAAC,IAAI,KAAK,CAAC,GAAG,EAAE,YAAA,IAAgB,EAAE,CAAC,EAAE,IAAI,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC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sources":["../../src/envelope.ts"],"sourcesContent":["import type { Client } from './client';\nimport { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';\nimport type { SentrySpan } from './tracing/sentrySpan';\nimport type { LegacyCSPReport } from './types-hoist/csp';\nimport type { DsnComponents } from './types-hoist/dsn';\nimport type {\n DynamicSamplingContext,\n EventEnvelope,\n EventItem,\n RawSecurityEnvelope,\n RawSecurityItem,\n SessionEnvelope,\n SessionItem,\n SpanContainerItem,\n SpanEnvelope,\n SpanItem,\n SpanV2Envelope,\n} from './types-hoist/envelope';\nimport type { Event } from './types-hoist/event';\nimport type { SdkInfo } from './types-hoist/sdkinfo';\nimport type { SdkMetadata } from './types-hoist/sdkmetadata';\nimport type { Session, SessionAggregates } from './types-hoist/session';\nimport type { SpanV2JSON } from './types-hoist/span';\nimport { isV2BeforeSendSpanCallback } from './utils/beforeSendSpan';\nimport { dsnToString } from './utils/dsn';\nimport {\n createEnvelope,\n createEventEnvelopeHeaders,\n createSpanEnvelopeItem,\n getSdkMetadataForEnvelopeHeader,\n} from './utils/envelope';\nimport { uuid4 } from './utils/misc';\nimport { shouldIgnoreSpan } from './utils/should-ignore-span';\nimport { showSpanDropWarning, spanToJSON } from './utils/spanUtils';\n\n/**\n * Apply SdkInfo (name, version, packages, integrations) to the corresponding event key.\n * Merge with existing data if any.\n *\n * @internal, exported only for testing\n **/\nexport function _enhanceEventWithSdkInfo(event: Event, newSdkInfo?: SdkInfo): Event {\n if (!newSdkInfo) {\n return event;\n }\n\n const eventSdkInfo = event.sdk || {};\n\n event.sdk = {\n ...eventSdkInfo,\n name: eventSdkInfo.name || newSdkInfo.name,\n version: eventSdkInfo.version || newSdkInfo.version,\n integrations: [...(event.sdk?.integrations || []), ...(newSdkInfo.integrations || [])],\n packages: [...(event.sdk?.packages || []), ...(newSdkInfo.packages || [])],\n settings:\n event.sdk?.settings || newSdkInfo.settings\n ? {\n ...event.sdk?.settings,\n ...newSdkInfo.settings,\n }\n : undefined,\n };\n\n return event;\n}\n\n/** Creates an envelope from a Session */\nexport function createSessionEnvelope(\n session: Session | SessionAggregates,\n dsn?: DsnComponents,\n metadata?: SdkMetadata,\n tunnel?: string,\n): SessionEnvelope {\n const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);\n const envelopeHeaders = {\n sent_at: new Date().toISOString(),\n ...(sdkInfo && { sdk: sdkInfo }),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const envelopeItem: SessionItem =\n 'aggregates' in session ? [{ type: 'sessions' }, session] : [{ type: 'session' }, session.toJSON()];\n\n return createEnvelope<SessionEnvelope>(envelopeHeaders, [envelopeItem]);\n}\n\n/**\n * Create an Envelope from an event.\n */\nexport function createEventEnvelope(\n event: Event,\n dsn?: DsnComponents,\n metadata?: SdkMetadata,\n tunnel?: string,\n): EventEnvelope {\n const sdkInfo = getSdkMetadataForEnvelopeHeader(metadata);\n\n /*\n Note: Due to TS, event.type may be `replay_event`, theoretically.\n In practice, we never call `createEventEnvelope` with `replay_event` type,\n and we'd have to adjust a looot of types to make this work properly.\n We want to avoid casting this around, as that could lead to bugs (e.g. when we add another type)\n So the safe choice is to really guard against the replay_event type here.\n */\n const eventType = event.type && event.type !== 'replay_event' ? event.type : 'event';\n\n _enhanceEventWithSdkInfo(event, metadata?.sdk);\n\n const envelopeHeaders = createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn);\n\n // Prevent this data (which, if it exists, was used in earlier steps in the processing pipeline) from being sent to\n // sentry. (Note: Our use of this property comes and goes with whatever we might be debugging, whatever hacks we may\n // have temporarily added, etc. Even if we don't happen to be using it at some point in the future, let's not get rid\n // of this `delete`, lest we miss putting it back in the next time the property is in use.)\n delete event.sdkProcessingMetadata;\n\n const eventItem: EventItem = [{ type: eventType }, event];\n return createEnvelope<EventEnvelope>(envelopeHeaders, [eventItem]);\n}\n\n/**\n * Create envelope from Span item.\n *\n * Takes an optional client and runs spans through `beforeSendSpan` if available.\n */\nexport function createSpanEnvelope(spans: [SentrySpan, ...SentrySpan[]], client?: Client): SpanEnvelope {\n // For the moment we'll obtain the DSC from the first span in the array\n // This might need to be changed if we permit sending multiple spans from\n // different segments in one envelope\n const dsc = getDynamicSamplingContextFromSpan(spans[0]);\n\n const dsn = client?.getDsn();\n const tunnel = client?.getOptions().tunnel;\n\n const headers: SpanEnvelope[0] = {\n sent_at: new Date().toISOString(),\n ...(dscHasRequiredProps(dsc) && { trace: dsc }),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const options = client?.getOptions();\n const ignoreSpans = options?.ignoreSpans;\n\n const filteredSpans = ignoreSpans?.length\n ? spans.filter(span => !shouldIgnoreSpan(spanToJSON(span), ignoreSpans))\n : spans;\n const droppedSpans = spans.length - filteredSpans.length;\n\n if (droppedSpans) {\n client?.recordDroppedEvent('before_send', 'span', droppedSpans);\n }\n\n // checking against traceLifeCycle so that TS can infer the correct type for\n // beforeSendSpan. This is a workaround for now as most likely, this entire function\n // will be removed in the future (once we send standalone spans as spans v2)\n const convertToSpanJSON = options?.beforeSendSpan\n ? (span: SentrySpan) => {\n const spanJson = spanToJSON(span);\n const processedSpan =\n !isV2BeforeSendSpanCallback(options?.beforeSendSpan) && options?.beforeSendSpan?.(spanJson);\n\n if (!processedSpan) {\n showSpanDropWarning();\n return spanJson;\n }\n\n return processedSpan;\n }\n : spanToJSON;\n\n const items: SpanItem[] = [];\n for (const span of filteredSpans) {\n const spanJson = convertToSpanJSON(span);\n if (spanJson) {\n items.push(createSpanEnvelopeItem(spanJson));\n }\n }\n\n return createEnvelope<SpanEnvelope>(headers, items);\n}\n\n/**\n * Creates a span v2 envelope\n */\nexport function createSpanV2Envelope(\n serializedSpans: SpanV2JSON[],\n dsc: Partial<DynamicSamplingContext>,\n client: Client,\n): SpanV2Envelope {\n const dsn = client?.getDsn();\n const tunnel = client?.getOptions().tunnel;\n const sdk = client?.getOptions()._metadata?.sdk;\n\n const headers: SpanV2Envelope[0] = {\n sent_at: new Date().toISOString(),\n ...(dscHasRequiredProps(dsc) && { trace: dsc }),\n ...(sdk && { sdk: sdk }),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const spanContainer: SpanContainerItem = [\n { type: 'span', item_count: serializedSpans.length, content_type: 'application/vnd.sentry.items.span.v2+json' },\n { items: serializedSpans },\n ];\n\n return createEnvelope<SpanV2Envelope>(headers, [spanContainer]);\n}\n\n/**\n * Create an Envelope from a CSP report.\n */\nexport function createRawSecurityEnvelope(\n report: LegacyCSPReport,\n dsn: DsnComponents,\n tunnel?: string,\n release?: string,\n environment?: string,\n): RawSecurityEnvelope {\n const envelopeHeaders = {\n event_id: uuid4(),\n ...(!!tunnel && dsn && { dsn: dsnToString(dsn) }),\n };\n\n const eventItem: RawSecurityItem = [\n { type: 'raw_security', sentry_release: release, sentry_environment: environment },\n report,\n ];\n\n return createEnvelope<RawSecurityEnvelope>(envelopeHeaders, [eventItem]);\n}\n\nfunction dscHasRequiredProps(dsc: Partial<DynamicSamplingContext>): dsc is DynamicSamplingContext {\n return !!dsc.trace_id && !!dsc.public_key;\n}\n"],"names":["dsn","getSdkMetadataForEnvelopeHeader","dsnToString","createEnvelope","createEventEnvelopeHeaders","getDynamicSamplingContextFromSpan","shouldIgnoreSpan","spanToJSON","isV2BeforeSendSpanCallback","showSpanDropWarning","createSpanEnvelopeItem"],"mappings":";;;;;;;;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB,CAAC,KAAK,EAAS,UAAU,EAAmB;AACpF,EAAE,IAAI,CAAC,UAAU,EAAE;AACnB,IAAI,OAAO,KAAK;AAChB,EAAE;;AAEF,EAAE,MAAM,eAAe,KAAK,CAAC,GAAA,IAAO,EAAE;;AAEtC,EAAE,KAAK,CAAC,GAAA,GAAM;AACd,IAAI,GAAG,YAAY;AACnB,IAAI,IAAI,EAAE,YAAY,CAAC,QAAQ,UAAU,CAAC,IAAI;AAC9C,IAAI,OAAO,EAAE,YAAY,CAAC,WAAW,UAAU,C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./utils/parameterize.js');
40
40
  const ipAddress = require('./utils/ipAddress.js');
41
41
  const spanUtils = require('./utils/spanUtils.js');
42
+ const captureSpan = require('./spans/captureSpan.js');
43
+ const spanFirstUtils = require('./spans/spanFirstUtils.js');
44
+ const spanBuffer = require('./spans/spanBuffer.js');
42
45
  const spanOnScope = require('./utils/spanOnScope.js');
43
46
  const parseSampleRate = require('./utils/parseSampleRate.js');
44
47
  const sdkMetadata = require('./utils/sdkMetadata.js');
@@ -63,6 +66,7 @@ const thirdPartyErrorsFilter = require('./integrations/third-party-errors-filter
63
66
  const console = require('./integrations/console.js');
64
67
  const featureFlagsIntegration = require('./integrations/featureFlags/featureFlagsIntegration.js');
65
68
  const growthbook = require('./integrations/featureFlags/growthbook.js');
69
+ const serverSpanStreaming = require('./integrations/serverSpanStreaming.js');
66
70
  const profiling = require('./profiling.js');
67
71
  const fetch = require('./fetch.js');
68
72
  const trpc = require('./trpc.js');
@@ -131,6 +135,8 @@ const flushIfServerless = require('./utils/flushIfServerless.js');
131
135
  const version = require('./utils/version.js');
132
136
  const debugIds = require('./utils/debug-ids.js');
133
137
  const escapeStringForRegex = require('./vendor/escapeStringForRegex.js');
138
+ const beforeSendSpan = require('./utils/beforeSendSpan.js');
139
+ const shouldIgnoreSpan = require('./utils/should-ignore-span.js');
134
140
 
135
141
 
136
142
 
@@ -169,19 +175,31 @@ exports.SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME = semanticAttributes.SEMANTIC_ATTRIBUT
169
175
  exports.SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD = semanticAttributes.SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD;
170
176
  exports.SEMANTIC_ATTRIBUTE_PROFILE_ID = semanticAttributes.SEMANTIC_ATTRIBUTE_PROFILE_ID;
171
177
  exports.SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME;
178
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT;
172
179
  exports.SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON;
173
180
  exports.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT;
174
181
  exports.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE;
175
182
  exports.SEMANTIC_ATTRIBUTE_SENTRY_OP = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_OP;
176
183
  exports.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN;
177
184
  exports.SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_PREVIOUS_TRACE_SAMPLE_RATE;
185
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_RELEASE = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_RELEASE;
178
186
  exports.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE;
187
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME;
188
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION;
189
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID;
190
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME;
179
191
  exports.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE = semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE;
180
192
  exports.SEMANTIC_ATTRIBUTE_URL_FULL = semanticAttributes.SEMANTIC_ATTRIBUTE_URL_FULL;
193
+ exports.SEMANTIC_ATTRIBUTE_URL_QUERY = semanticAttributes.SEMANTIC_ATTRIBUTE_URL_QUERY;
194
+ exports.SEMANTIC_ATTRIBUTE_USER_EMAIL = semanticAttributes.SEMANTIC_ATTRIBUTE_USER_EMAIL;
195
+ exports.SEMANTIC_ATTRIBUTE_USER_ID = semanticAttributes.SEMANTIC_ATTRIBUTE_USER_ID;
196
+ exports.SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS = semanticAttributes.SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS;
197
+ exports.SEMANTIC_ATTRIBUTE_USER_USERNAME = semanticAttributes.SEMANTIC_ATTRIBUTE_USER_USERNAME;
181
198
  exports.SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE = semanticAttributes.SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE;
182
199
  exports.createEventEnvelope = envelope.createEventEnvelope;
183
200
  exports.createSessionEnvelope = envelope.createSessionEnvelope;
184
201
  exports.createSpanEnvelope = envelope.createSpanEnvelope;
202
+ exports.createSpanV2Envelope = envelope.createSpanV2Envelope;
185
203
  exports.addEventProcessor = exports$1.addEventProcessor;
186
204
  exports.captureCheckIn = exports$1.captureCheckIn;
187
205
  exports.captureEvent = exports$1.captureEvent;
@@ -247,18 +265,24 @@ exports.fmt = parameterize.fmt;
247
265
  exports.parameterize = parameterize.parameterize;
248
266
  exports.addAutoIpAddressToSession = ipAddress.addAutoIpAddressToSession;
249
267
  exports.addAutoIpAddressToUser = ipAddress.addAutoIpAddressToUser;
268
+ exports.INTERNAL_getSegmentSpan = spanUtils.INTERNAL_getSegmentSpan;
250
269
  exports.addChildSpanToSpan = spanUtils.addChildSpanToSpan;
251
270
  exports.convertSpanLinksForEnvelope = spanUtils.convertSpanLinksForEnvelope;
252
271
  exports.getActiveSpan = spanUtils.getActiveSpan;
253
272
  exports.getRootSpan = spanUtils.getRootSpan;
254
273
  exports.getSpanDescendants = spanUtils.getSpanDescendants;
255
274
  exports.getStatusMessage = spanUtils.getStatusMessage;
275
+ exports.showSpanDropWarning = spanUtils.showSpanDropWarning;
256
276
  exports.spanIsSampled = spanUtils.spanIsSampled;
257
277
  exports.spanTimeInputToSeconds = spanUtils.spanTimeInputToSeconds;
258
278
  exports.spanToJSON = spanUtils.spanToJSON;
259
279
  exports.spanToTraceContext = spanUtils.spanToTraceContext;
260
280
  exports.spanToTraceHeader = spanUtils.spanToTraceHeader;
281
+ exports.spanToV2JSON = spanUtils.spanToV2JSON;
261
282
  exports.updateSpanName = spanUtils.updateSpanName;
283
+ exports.captureSpan = captureSpan.captureSpan;
284
+ exports.safeSetSpanJSONAttributes = spanFirstUtils.safeSetSpanJSONAttributes;
285
+ exports.SpanBuffer = spanBuffer.SpanBuffer;
262
286
  exports._INTERNAL_setSpanForScope = spanOnScope._setSpanForScope;
263
287
  exports.parseSampleRate = parseSampleRate.parseSampleRate;
264
288
  exports.applySdkMetadata = sdkMetadata.applySdkMetadata;
@@ -290,6 +314,7 @@ exports.thirdPartyErrorFilterIntegration = thirdPartyErrorsFilter.thirdPartyErro
290
314
  exports.consoleIntegration = console.consoleIntegration;
291
315
  exports.featureFlagsIntegration = featureFlagsIntegration.featureFlagsIntegration;
292
316
  exports.growthbookIntegration = growthbook.growthbookIntegration;
317
+ exports.serverSpanStreamingIntegration = serverSpanStreaming.serverSpanStreamingIntegration;
293
318
  exports.profiler = profiling.profiler;
294
319
  exports.instrumentFetchRequest = fetch.instrumentFetchRequest;
295
320
  exports.trpcMiddleware = trpc.trpcMiddleware;
@@ -426,6 +451,7 @@ exports.timestampInSeconds = time.timestampInSeconds;
426
451
  exports.TRACEPARENT_REGEXP = tracing.TRACEPARENT_REGEXP;
427
452
  exports.extractTraceparentData = tracing.extractTraceparentData;
428
453
  exports.generateSentryTraceHeader = tracing.generateSentryTraceHeader;
454
+ exports.generateTraceparentHeader = tracing.generateTraceparentHeader;
429
455
  exports.propagationContextFromHeaders = tracing.propagationContextFromHeaders;
430
456
  exports.shouldContinueTrace = tracing.shouldContinueTrace;
431
457
  exports.getSDKSource = env.getSDKSource;
@@ -476,4 +502,8 @@ exports.SDK_VERSION = version.SDK_VERSION;
476
502
  exports.getDebugImagesForResources = debugIds.getDebugImagesForResources;
477
503
  exports.getFilenameToDebugIdMap = debugIds.getFilenameToDebugIdMap;
478
504
  exports.escapeStringForRegex = escapeStringForRegex.escapeStringForRegex;
505
+ exports.isV2BeforeSendSpanCallback = beforeSendSpan.isV2BeforeSendSpanCallback;
506
+ exports.withStreamSpan = beforeSendSpan.withStreamSpan;
507
+ exports.reparentChildSpans = shouldIgnoreSpan.reparentChildSpans;
508
+ exports.shouldIgnoreSpan = shouldIgnoreSpan.shouldIgnoreSpan;
479
509
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -136,7 +136,7 @@ function _shouldDropEvent(event, options) {
136
136
  }
137
137
  } else if (event.type === 'transaction') {
138
138
  // Filter transactions
139
-
139
+ // TODO (span-streaming): replace with ignoreSpans defaults (if we have any)
140
140
  if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
141
141
  debugBuild.DEBUG_BUILD &&
142
142
  debugLogger.debug.warn(
@@ -1 +1 @@
1
- {"version":3,"file":"eventFilters.js","sources":["../../../src/integrations/eventFilters.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { defineIntegration } from '../integration';\nimport type { Event } from '../types-hoist/event';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { StackFrame } from '../types-hoist/stackframe';\nimport { debug } from '../utils/debug-logger';\nimport { getPossibleEventMessages } from '../utils/eventUtils';\nimport { getEventDescription } from '../utils/misc';\nimport { stringMatchesSomePattern } from '../utils/string';\n\n// \"Script error.\" is hard coded into browsers for errors that it can't read.\n// this is the result of a script being pulled in from an external domain and CORS.\nconst DEFAULT_IGNORE_ERRORS = [\n /^Script error\\.?$/,\n /^Javascript error: Script error\\.? on line 0$/,\n /^ResizeObserver loop completed with undelivered notifications.$/, // The browser logs this when a ResizeObserver handler takes a bit longer. Usually this is not an actual issue though. It indicates slowness.\n /^Cannot redefine property: googletag$/, // This is thrown when google tag manager is used in combination with an ad blocker\n /^Can't find variable: gmo$/, // Error from Google Search App https://issuetracker.google.com/issues/396043331\n /^undefined is not an object \\(evaluating 'a\\.[A-Z]'\\)$/, // Random error that happens but not actionable or noticeable to end-users.\n 'can\\'t redefine non-configurable property \"solana\"', // Probably a browser extension or custom browser (Brave) throwing this error\n \"vv().getRestrictions is not a function. (In 'vv().getRestrictions(1,a)', 'vv().getRestrictions' is undefined)\", // Error thrown by GTM, seemingly not affecting end-users\n \"Can't find variable: _AutofillCallbackHandler\", // Unactionable error in instagram webview https://developers.facebook.com/community/threads/320013549791141/\n /^Non-Error promise rejection captured with value: Object Not Found Matching Id:\\d+, MethodName:simulateEvent, ParamCount:\\d+$/, // unactionable error from CEFSharp, a .NET library that embeds chromium in .NET apps\n /^Java exception was raised during method invocation$/, // error from Facebook Mobile browser (https://github.com/getsentry/sentry-javascript/issues/15065)\n];\n\n/** Options for the EventFilters integration */\nexport interface EventFiltersOptions {\n allowUrls: Array<string | RegExp>;\n denyUrls: Array<string | RegExp>;\n ignoreErrors: Array<string | RegExp>;\n ignoreTransactions: Array<string | RegExp>;\n ignoreInternal: boolean;\n disableErrorDefaults: boolean;\n}\n\nconst INTEGRATION_NAME = 'EventFilters';\n\n/**\n * An integration that filters out events (errors and transactions) based on:\n *\n * - (Errors) A curated list of known low-value or irrelevant errors (see {@link DEFAULT_IGNORE_ERRORS})\n * - (Errors) A list of error messages or urls/filenames passed in via\n * - Top level Sentry.init options (`ignoreErrors`, `denyUrls`, `allowUrls`)\n * - The same options passed to the integration directly via @param options\n * - (Transactions/Spans) A list of root span (transaction) names passed in via\n * - Top level Sentry.init option (`ignoreTransactions`)\n * - The same option passed to the integration directly via @param options\n *\n * Events filtered by this integration will not be sent to Sentry.\n */\nexport const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {\n let mergedOptions: Partial<EventFiltersOptions> | undefined;\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const clientOptions = client.getOptions();\n mergedOptions = _mergeOptions(options, clientOptions);\n },\n processEvent(event, _hint, client) {\n if (!mergedOptions) {\n const clientOptions = client.getOptions();\n mergedOptions = _mergeOptions(options, clientOptions);\n }\n return _shouldDropEvent(event, mergedOptions) ? null : event;\n },\n };\n});\n\n/**\n * An integration that filters out events (errors and transactions) based on:\n *\n * - (Errors) A curated list of known low-value or irrelevant errors (see {@link DEFAULT_IGNORE_ERRORS})\n * - (Errors) A list of error messages or urls/filenames passed in via\n * - Top level Sentry.init options (`ignoreErrors`, `denyUrls`, `allowUrls`)\n * - The same options passed to the integration directly via @param options\n * - (Transactions/Spans) A list of root span (transaction) names passed in via\n * - Top level Sentry.init option (`ignoreTransactions`)\n * - The same option passed to the integration directly via @param options\n *\n * Events filtered by this integration will not be sent to Sentry.\n *\n * @deprecated this integration was renamed and will be removed in a future major version.\n * Use `eventFiltersIntegration` instead.\n */\nexport const inboundFiltersIntegration = defineIntegration(((options: Partial<EventFiltersOptions> = {}) => {\n return {\n ...eventFiltersIntegration(options),\n name: 'InboundFilters',\n };\n}) satisfies IntegrationFn);\n\nfunction _mergeOptions(\n internalOptions: Partial<EventFiltersOptions> = {},\n clientOptions: Partial<EventFiltersOptions> = {},\n): Partial<EventFiltersOptions> {\n return {\n allowUrls: [...(internalOptions.allowUrls || []), ...(clientOptions.allowUrls || [])],\n denyUrls: [...(internalOptions.denyUrls || []), ...(clientOptions.denyUrls || [])],\n ignoreErrors: [\n ...(internalOptions.ignoreErrors || []),\n ...(clientOptions.ignoreErrors || []),\n ...(internalOptions.disableErrorDefaults ? [] : DEFAULT_IGNORE_ERRORS),\n ],\n ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])],\n };\n}\n\nfunction _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {\n if (!event.type) {\n // Filter errors\n if (_isIgnoredError(event, options.ignoreErrors)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`ignoreErrors\\` option.\\nEvent: ${getEventDescription(event)}`,\n );\n return true;\n }\n if (_isUselessError(event)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to not having an error message, error type or stacktrace.\\nEvent: ${getEventDescription(\n event,\n )}`,\n );\n return true;\n }\n if (_isDeniedUrl(event, options.denyUrls)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`denyUrls\\` option.\\nEvent: ${getEventDescription(\n event,\n )}.\\nUrl: ${_getEventFilterUrl(event)}`,\n );\n return true;\n }\n if (!_isAllowedUrl(event, options.allowUrls)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to not being matched by \\`allowUrls\\` option.\\nEvent: ${getEventDescription(\n event,\n )}.\\nUrl: ${_getEventFilterUrl(event)}`,\n );\n return true;\n }\n } else if (event.type === 'transaction') {\n // Filter transactions\n\n if (_isIgnoredTransaction(event, options.ignoreTransactions)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`ignoreTransactions\\` option.\\nEvent: ${getEventDescription(event)}`,\n );\n return true;\n }\n }\n return false;\n}\n\nfunction _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {\n if (!ignoreErrors?.length) {\n return false;\n }\n\n return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));\n}\n\nfunction _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {\n if (!ignoreTransactions?.length) {\n return false;\n }\n\n const name = event.transaction;\n return name ? stringMatchesSomePattern(name, ignoreTransactions) : false;\n}\n\nfunction _isDeniedUrl(event: Event, denyUrls?: Array<string | RegExp>): boolean {\n if (!denyUrls?.length) {\n return false;\n }\n const url = _getEventFilterUrl(event);\n return !url ? false : stringMatchesSomePattern(url, denyUrls);\n}\n\nfunction _isAllowedUrl(event: Event, allowUrls?: Array<string | RegExp>): boolean {\n if (!allowUrls?.length) {\n return true;\n }\n const url = _getEventFilterUrl(event);\n return !url ? true : stringMatchesSomePattern(url, allowUrls);\n}\n\nfunction _getLastValidUrl(frames: StackFrame[] = []): string | null {\n for (let i = frames.length - 1; i >= 0; i--) {\n const frame = frames[i];\n\n if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {\n return frame.filename || null;\n }\n }\n\n return null;\n}\n\nfunction _getEventFilterUrl(event: Event): string | null {\n try {\n // If there are linked exceptions or exception aggregates we only want to match against the top frame of the \"root\" (the main exception)\n // The root always comes last in linked exceptions\n const rootException = [...(event.exception?.values ?? [])]\n .reverse()\n .find(value => value.mechanism?.parent_id === undefined && value.stacktrace?.frames?.length);\n const frames = rootException?.stacktrace?.frames;\n return frames ? _getLastValidUrl(frames) : null;\n } catch {\n DEBUG_BUILD && debug.error(`Cannot extract url for event ${getEventDescription(event)}`);\n return null;\n }\n}\n\nfunction _isUselessError(event: Event): boolean {\n // We only want to consider events for dropping that actually have recorded exception values.\n if (!event.exception?.values?.length) {\n return false;\n }\n\n return (\n // No top-level message\n !event.message &&\n // There are no exception values that have a stacktrace, a non-generic-Error type or value\n !event.exception.values.some(value => value.stacktrace || (value.type && value.type !== 'Error') || value.value)\n );\n}\n"],"names":["defineIntegration","DEBUG_BUILD","debug","getEventDescription","getPossibleEventMessages","stringMatchesSomePattern"],"mappings":";;;;;;;;;AAUA;AACA;AACA,MAAM,wBAAwB;AA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,EAAA;;AAEA,EAAA,OAAA,IAAA;AACA;;AAEA,SAAA,kBAAA,CAAA,KAAA,EAAA;AACA,EAAA,IAAA;AACA;AACA;AACA,IAAA,MAAA,aAAA,GAAA,CAAA,IAAA,KAAA,CAAA,SAAA,EAAA,MAAA,IAAA,EAAA,CAAA;AACA,OAAA,OAAA;AACA,OAAA,IAAA,CAAA,KAAA,IAAA,KAAA,CAAA,SAAA,EAAA,SAAA,KAAA,SAAA,IAAA,KAAA,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AACA,IAAA,MAAA,MAAA,GAAA,aAAA,EAAA,UAAA,EAAA,MAAA;AACA,IAAA,OAAA,MAAA,GAAA,gBAAA,CAAA,MAAA,CAAA,GAAA,IAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA,IAAAJ,sBAAA,IAAAC,iBAAA,CAAA,KAAA,CAAA,CAAA,6BAAA,EAAAC,wBAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA;AACA,IAAA,OAAA,IAAA;AACA,EAAA;AACA;;AAEA,SAAA,eAAA,CAAA,KAAA,EAAA;AACA;AACA,EAAA,IAAA,CAAA,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,EAAA;AACA,IAAA,OAAA,KAAA;AACA,EAAA;;AAEA,EAAA;AACA;AACA,IAAA,CAAA,KAAA,CAAA,OAAA;AACA;AACA,IAAA,CAAA,KAAA,CAAA,SAAA,CAAA,MAAA,CAAA,IAAA,CAAA,KAAA,IAAA,KAAA,CAAA,UAAA,KAAA,KAAA,CAAA,IAAA,IAAA,KAAA,CAAA,IAAA,KAAA,OAAA,CAAA,IAAA,KAAA,CAAA,KAAA;AACA;AACA;;;;;"}
1
+ {"version":3,"file":"eventFilters.js","sources":["../../../src/integrations/eventFilters.ts"],"sourcesContent":["import { DEBUG_BUILD } from '../debug-build';\nimport { defineIntegration } from '../integration';\nimport type { Event } from '../types-hoist/event';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { StackFrame } from '../types-hoist/stackframe';\nimport { debug } from '../utils/debug-logger';\nimport { getPossibleEventMessages } from '../utils/eventUtils';\nimport { getEventDescription } from '../utils/misc';\nimport { stringMatchesSomePattern } from '../utils/string';\n\n// \"Script error.\" is hard coded into browsers for errors that it can't read.\n// this is the result of a script being pulled in from an external domain and CORS.\nconst DEFAULT_IGNORE_ERRORS = [\n /^Script error\\.?$/,\n /^Javascript error: Script error\\.? on line 0$/,\n /^ResizeObserver loop completed with undelivered notifications.$/, // The browser logs this when a ResizeObserver handler takes a bit longer. Usually this is not an actual issue though. It indicates slowness.\n /^Cannot redefine property: googletag$/, // This is thrown when google tag manager is used in combination with an ad blocker\n /^Can't find variable: gmo$/, // Error from Google Search App https://issuetracker.google.com/issues/396043331\n /^undefined is not an object \\(evaluating 'a\\.[A-Z]'\\)$/, // Random error that happens but not actionable or noticeable to end-users.\n 'can\\'t redefine non-configurable property \"solana\"', // Probably a browser extension or custom browser (Brave) throwing this error\n \"vv().getRestrictions is not a function. (In 'vv().getRestrictions(1,a)', 'vv().getRestrictions' is undefined)\", // Error thrown by GTM, seemingly not affecting end-users\n \"Can't find variable: _AutofillCallbackHandler\", // Unactionable error in instagram webview https://developers.facebook.com/community/threads/320013549791141/\n /^Non-Error promise rejection captured with value: Object Not Found Matching Id:\\d+, MethodName:simulateEvent, ParamCount:\\d+$/, // unactionable error from CEFSharp, a .NET library that embeds chromium in .NET apps\n /^Java exception was raised during method invocation$/, // error from Facebook Mobile browser (https://github.com/getsentry/sentry-javascript/issues/15065)\n];\n\n/** Options for the EventFilters integration */\nexport interface EventFiltersOptions {\n allowUrls: Array<string | RegExp>;\n denyUrls: Array<string | RegExp>;\n ignoreErrors: Array<string | RegExp>;\n ignoreTransactions: Array<string | RegExp>;\n ignoreInternal: boolean;\n disableErrorDefaults: boolean;\n}\n\nconst INTEGRATION_NAME = 'EventFilters';\n\n/**\n * An integration that filters out events (errors and transactions) based on:\n *\n * - (Errors) A curated list of known low-value or irrelevant errors (see {@link DEFAULT_IGNORE_ERRORS})\n * - (Errors) A list of error messages or urls/filenames passed in via\n * - Top level Sentry.init options (`ignoreErrors`, `denyUrls`, `allowUrls`)\n * - The same options passed to the integration directly via @param options\n * - (Transactions/Spans) A list of root span (transaction) names passed in via\n * - Top level Sentry.init option (`ignoreTransactions`)\n * - The same option passed to the integration directly via @param options\n *\n * Events filtered by this integration will not be sent to Sentry.\n */\nexport const eventFiltersIntegration = defineIntegration((options: Partial<EventFiltersOptions> = {}) => {\n let mergedOptions: Partial<EventFiltersOptions> | undefined;\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const clientOptions = client.getOptions();\n mergedOptions = _mergeOptions(options, clientOptions);\n },\n processEvent(event, _hint, client) {\n if (!mergedOptions) {\n const clientOptions = client.getOptions();\n mergedOptions = _mergeOptions(options, clientOptions);\n }\n return _shouldDropEvent(event, mergedOptions) ? null : event;\n },\n };\n});\n\n/**\n * An integration that filters out events (errors and transactions) based on:\n *\n * - (Errors) A curated list of known low-value or irrelevant errors (see {@link DEFAULT_IGNORE_ERRORS})\n * - (Errors) A list of error messages or urls/filenames passed in via\n * - Top level Sentry.init options (`ignoreErrors`, `denyUrls`, `allowUrls`)\n * - The same options passed to the integration directly via @param options\n * - (Transactions/Spans) A list of root span (transaction) names passed in via\n * - Top level Sentry.init option (`ignoreTransactions`)\n * - The same option passed to the integration directly via @param options\n *\n * Events filtered by this integration will not be sent to Sentry.\n *\n * @deprecated this integration was renamed and will be removed in a future major version.\n * Use `eventFiltersIntegration` instead.\n */\nexport const inboundFiltersIntegration = defineIntegration(((options: Partial<EventFiltersOptions> = {}) => {\n return {\n ...eventFiltersIntegration(options),\n name: 'InboundFilters',\n };\n}) satisfies IntegrationFn);\n\nfunction _mergeOptions(\n internalOptions: Partial<EventFiltersOptions> = {},\n clientOptions: Partial<EventFiltersOptions> = {},\n): Partial<EventFiltersOptions> {\n return {\n allowUrls: [...(internalOptions.allowUrls || []), ...(clientOptions.allowUrls || [])],\n denyUrls: [...(internalOptions.denyUrls || []), ...(clientOptions.denyUrls || [])],\n ignoreErrors: [\n ...(internalOptions.ignoreErrors || []),\n ...(clientOptions.ignoreErrors || []),\n ...(internalOptions.disableErrorDefaults ? [] : DEFAULT_IGNORE_ERRORS),\n ],\n ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])],\n };\n}\n\nfunction _shouldDropEvent(event: Event, options: Partial<EventFiltersOptions>): boolean {\n if (!event.type) {\n // Filter errors\n if (_isIgnoredError(event, options.ignoreErrors)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`ignoreErrors\\` option.\\nEvent: ${getEventDescription(event)}`,\n );\n return true;\n }\n if (_isUselessError(event)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to not having an error message, error type or stacktrace.\\nEvent: ${getEventDescription(\n event,\n )}`,\n );\n return true;\n }\n if (_isDeniedUrl(event, options.denyUrls)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`denyUrls\\` option.\\nEvent: ${getEventDescription(\n event,\n )}.\\nUrl: ${_getEventFilterUrl(event)}`,\n );\n return true;\n }\n if (!_isAllowedUrl(event, options.allowUrls)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to not being matched by \\`allowUrls\\` option.\\nEvent: ${getEventDescription(\n event,\n )}.\\nUrl: ${_getEventFilterUrl(event)}`,\n );\n return true;\n }\n } else if (event.type === 'transaction') {\n // Filter transactions\n // TODO (span-streaming): replace with ignoreSpans defaults (if we have any)\n if (_isIgnoredTransaction(event, options.ignoreTransactions)) {\n DEBUG_BUILD &&\n debug.warn(\n `Event dropped due to being matched by \\`ignoreTransactions\\` option.\\nEvent: ${getEventDescription(event)}`,\n );\n return true;\n }\n }\n return false;\n}\n\nfunction _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): boolean {\n if (!ignoreErrors?.length) {\n return false;\n }\n\n return getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));\n}\n\nfunction _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {\n if (!ignoreTransactions?.length) {\n return false;\n }\n\n const name = event.transaction;\n return name ? stringMatchesSomePattern(name, ignoreTransactions) : false;\n}\n\nfunction _isDeniedUrl(event: Event, denyUrls?: Array<string | RegExp>): boolean {\n if (!denyUrls?.length) {\n return false;\n }\n const url = _getEventFilterUrl(event);\n return !url ? false : stringMatchesSomePattern(url, denyUrls);\n}\n\nfunction _isAllowedUrl(event: Event, allowUrls?: Array<string | RegExp>): boolean {\n if (!allowUrls?.length) {\n return true;\n }\n const url = _getEventFilterUrl(event);\n return !url ? true : stringMatchesSomePattern(url, allowUrls);\n}\n\nfunction _getLastValidUrl(frames: StackFrame[] = []): string | null {\n for (let i = frames.length - 1; i >= 0; i--) {\n const frame = frames[i];\n\n if (frame && frame.filename !== '<anonymous>' && frame.filename !== '[native code]') {\n return frame.filename || null;\n }\n }\n\n return null;\n}\n\nfunction _getEventFilterUrl(event: Event): string | null {\n try {\n // If there are linked exceptions or exception aggregates we only want to match against the top frame of the \"root\" (the main exception)\n // The root always comes last in linked exceptions\n const rootException = [...(event.exception?.values ?? [])]\n .reverse()\n .find(value => value.mechanism?.parent_id === undefined && value.stacktrace?.frames?.length);\n const frames = rootException?.stacktrace?.frames;\n return frames ? _getLastValidUrl(frames) : null;\n } catch {\n DEBUG_BUILD && debug.error(`Cannot extract url for event ${getEventDescription(event)}`);\n return null;\n }\n}\n\nfunction _isUselessError(event: Event): boolean {\n // We only want to consider events for dropping that actually have recorded exception values.\n if (!event.exception?.values?.length) {\n return false;\n }\n\n return (\n // No top-level message\n !event.message &&\n // There are no exception values that have a stacktrace, a non-generic-Error type or value\n !event.exception.values.some(value => value.stacktrace || (value.type && value.type !== 'Error') || value.value)\n );\n}\n"],"names":["defineIntegration","DEBUG_BUILD","debug","getEventDescription","getPossibleEventMessages","stringMatchesSomePattern"],"mappings":";;;;;;;;;AAUA;AACA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AAA,IAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,IAAA;AACA;;AAEA,SAAA,kBAAA,CAAA,KAAA,EAAA;AACA,EAAA,IAAA;AACA;AACA;AACA,IAAA,MAAA,aAAA,GAAA,CAAA,IAAA,KAAA,CAAA,SAAA,EAAA,MAAA,IAAA,EAAA,CAAA;AACA,OAAA,OAAA;AACA,OAAA,IAAA,CAAA,KAAA,IAAA,KAAA,CAAA,SAAA,EAAA,SAAA,KAAA,SAAA,IAAA,KAAA,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AACA,IAAA,MAAA,MAAA,GAAA,aAAA,EAAA,UAAA,EAAA,MAAA;AACA,IAAA,OAAA,MAAA,GAAA,gBAAA,CAAA,MAAA,CAAA,GAAA,IAAA;AACA,EAAA,CAAA,CAAA,MAAA;AACA,IAAAJ,sBAAA,IAAAC,iBAAA,CAAA,KAAA,CAAA,CAAA,6BAAA,EAAAC,wBAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA;AACA,IAAA,OAAA,IAAA;AACA,EAAA;AACA;;AAEA,SAAA,eAAA,CAAA,KAAA,EAAA;AACA;AACA,EAAA,IAAA,CAAA,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,EAAA;AACA,IAAA,OAAA,KAAA;AACA,EAAA;;AAEA,EAAA;AACA;AACA,IAAA,CAAA,KAAA,CAAA,OAAA;AACA;AACA,IAAA,CAAA,KAAA,CAAA,SAAA,CAAA,MAAA,CAAA,IAAA,CAAA,KAAA,IAAA,KAAA,CAAA,UAAA,KAAA,KAAA,CAAA,IAAA,IAAA,KAAA,CAAA,IAAA,KAAA,OAAA,CAAA,IAAA,KAAA,CAAA,KAAA;AACA;AACA;;;;;"}
@@ -2,8 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const currentScopes = require('../../currentScopes.js');
4
4
  const spanstatus = require('../../tracing/spanstatus.js');
5
+ const attributes = require('./attributes.js');
5
6
  const piiFiltering = require('./piiFiltering.js');
6
7
  const resultExtraction = require('./resultExtraction.js');
8
+ const sessionExtraction = require('./sessionExtraction.js');
7
9
 
8
10
  /**
9
11
  * Request-span correlation system for MCP server instrumentation
@@ -52,10 +54,10 @@ function storeSpanForRequest(transport, requestId, span, method) {
52
54
  }
53
55
 
54
56
  /**
55
- * Completes span with tool results and cleans up correlation
57
+ * Completes span with results and cleans up correlation
56
58
  * @param transport - MCP transport instance
57
59
  * @param requestId - Request identifier
58
- * @param result - Tool execution result for attribute extraction
60
+ * @param result - Execution result for attribute extraction
59
61
  */
60
62
  function completeSpanWithResults(transport, requestId, result) {
61
63
  const spanMap = getOrCreateSpanMap(transport);
@@ -63,7 +65,19 @@ function completeSpanWithResults(transport, requestId, result) {
63
65
  if (spanData) {
64
66
  const { span, method } = spanData;
65
67
 
66
- if (method === 'tools/call') {
68
+ if (method === 'initialize') {
69
+ const sessionData = sessionExtraction.extractSessionDataFromInitializeResponse(result);
70
+ const serverAttributes = sessionExtraction.buildServerAttributesFromInfo(sessionData.serverInfo);
71
+
72
+ const initAttributes = {
73
+ ...serverAttributes,
74
+ };
75
+ if (sessionData.protocolVersion) {
76
+ initAttributes[attributes.MCP_PROTOCOL_VERSION_ATTRIBUTE] = sessionData.protocolVersion;
77
+ }
78
+
79
+ span.setAttributes(initAttributes);
80
+ } else if (method === 'tools/call') {
67
81
  const rawToolAttributes = resultExtraction.extractToolResultAttributes(result);
68
82
  const client = currentScopes.getClient();
69
83
  const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);
@@ -1 +1 @@
1
- {"version":3,"file":"correlation.js","sources":["../../../../src/integrations/mcp-server/correlation.ts"],"sourcesContent":["/**\n * Request-span correlation system for MCP server instrumentation\n *\n * Handles mapping requestId to span data for correlation with handler execution.\n * Uses WeakMap to scope correlation maps per transport instance, preventing\n * request ID collisions between different MCP sessions.\n */\n\nimport { getClient } from '../../currentScopes';\nimport { SPAN_STATUS_ERROR } from '../../tracing';\nimport type { Span } from '../../types-hoist/span';\nimport { filterMcpPiiFromSpanData } from './piiFiltering';\nimport { extractPromptResultAttributes, extractToolResultAttributes } from './resultExtraction';\nimport type { MCPTransport, RequestId, RequestSpanMapValue } from './types';\n\n/**\n * Transport-scoped correlation system that prevents collisions between different MCP sessions\n * @internal Each transport instance gets its own correlation map, eliminating request ID conflicts\n */\nconst transportToSpanMap = new WeakMap<MCPTransport, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Gets or creates the span map for a specific transport instance\n * @internal\n * @param transport - MCP transport instance\n * @returns Span map for the transport\n */\nfunction getOrCreateSpanMap(transport: MCPTransport): Map<RequestId, RequestSpanMapValue> {\n let spanMap = transportToSpanMap.get(transport);\n if (!spanMap) {\n spanMap = new Map();\n transportToSpanMap.set(transport, spanMap);\n }\n return spanMap;\n}\n\n/**\n * Stores span context for later correlation with handler execution\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param span - Active span to correlate\n * @param method - MCP method name\n */\nexport function storeSpanForRequest(transport: MCPTransport, requestId: RequestId, span: Span, method: string): void {\n const spanMap = getOrCreateSpanMap(transport);\n spanMap.set(requestId, {\n span,\n method,\n startTime: Date.now(),\n });\n}\n\n/**\n * Completes span with tool results and cleans up correlation\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param result - Tool execution result for attribute extraction\n */\nexport function completeSpanWithResults(transport: MCPTransport, requestId: RequestId, result: unknown): void {\n const spanMap = getOrCreateSpanMap(transport);\n const spanData = spanMap.get(requestId);\n if (spanData) {\n const { span, method } = spanData;\n\n if (method === 'tools/call') {\n const rawToolAttributes = extractToolResultAttributes(result);\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n const toolAttributes = filterMcpPiiFromSpanData(rawToolAttributes, sendDefaultPii);\n\n span.setAttributes(toolAttributes);\n } else if (method === 'prompts/get') {\n const rawPromptAttributes = extractPromptResultAttributes(result);\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n const promptAttributes = filterMcpPiiFromSpanData(rawPromptAttributes, sendDefaultPii);\n\n span.setAttributes(promptAttributes);\n }\n\n span.end();\n spanMap.delete(requestId);\n }\n}\n\n/**\n * Cleans up pending spans for a specific transport (when that transport closes)\n * @param transport - MCP transport instance\n */\nexport function cleanupPendingSpansForTransport(transport: MCPTransport): void {\n const spanMap = transportToSpanMap.get(transport);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n spanMap.clear();\n }\n}\n"],"names":["extractToolResultAttributes","getClient","filterMcpPiiFromSpanData","extractPromptResultAttributes","SPAN_STATUS_ERROR"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;AASA;AACA;AACA;AACA;AACA,MAAM,kBAAA,GAAqB,IAAI,OAAO,EAAqD;;AAE3F;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,SAAS,EAAqD;AAC1F,EAAE,IAAI,UAAU,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC;AACjD,EAAE,IAAI,CAAC,OAAO,EAAE;AAChB,IAAI,OAAA,GAAU,IAAI,GAAG,EAAE;AACvB,IAAI,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;AAC9C,EAAE;AACF,EAAE,OAAO,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mBAAmB,CAAC,SAAS,EAAgB,SAAS,EAAa,IAAI,EAAQ,MAAM,EAAgB;AACrH,EAAE,MAAM,OAAA,GAAU,kBAAkB,CAAC,SAAS,CAAC;AAC/C,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;AACzB,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;AACzB,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;A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;AACnD,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,KAAK,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AACxC,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAC9B,QAAQ,IAAI,EAAEE,4BAAiB;AAC/B,QAAQ,OAAO,EAAE,WAAW;AAC5B,OAAO,CAAC;AACR,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AACzB,IAAI;AACJ,IAAI,OAAO,CAAC,KAAK,EAAE;AACnB,EAAE;AACF;;;;;;"}
1
+ {"version":3,"file":"correlation.js","sources":["../../../../src/integrations/mcp-server/correlation.ts"],"sourcesContent":["/**\n * Request-span correlation system for MCP server instrumentation\n *\n * Handles mapping requestId to span data for correlation with handler execution.\n * Uses WeakMap to scope correlation maps per transport instance, preventing\n * request ID collisions between different MCP sessions.\n */\n\nimport { getClient } from '../../currentScopes';\nimport { SPAN_STATUS_ERROR } from '../../tracing';\nimport type { Span } from '../../types-hoist/span';\nimport { MCP_PROTOCOL_VERSION_ATTRIBUTE } from './attributes';\nimport { filterMcpPiiFromSpanData } from './piiFiltering';\nimport { extractPromptResultAttributes, extractToolResultAttributes } from './resultExtraction';\nimport { buildServerAttributesFromInfo, extractSessionDataFromInitializeResponse } from './sessionExtraction';\nimport type { MCPTransport, RequestId, RequestSpanMapValue } from './types';\n\n/**\n * Transport-scoped correlation system that prevents collisions between different MCP sessions\n * @internal Each transport instance gets its own correlation map, eliminating request ID conflicts\n */\nconst transportToSpanMap = new WeakMap<MCPTransport, Map<RequestId, RequestSpanMapValue>>();\n\n/**\n * Gets or creates the span map for a specific transport instance\n * @internal\n * @param transport - MCP transport instance\n * @returns Span map for the transport\n */\nfunction getOrCreateSpanMap(transport: MCPTransport): Map<RequestId, RequestSpanMapValue> {\n let spanMap = transportToSpanMap.get(transport);\n if (!spanMap) {\n spanMap = new Map();\n transportToSpanMap.set(transport, spanMap);\n }\n return spanMap;\n}\n\n/**\n * Stores span context for later correlation with handler execution\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param span - Active span to correlate\n * @param method - MCP method name\n */\nexport function storeSpanForRequest(transport: MCPTransport, requestId: RequestId, span: Span, method: string): void {\n const spanMap = getOrCreateSpanMap(transport);\n spanMap.set(requestId, {\n span,\n method,\n startTime: Date.now(),\n });\n}\n\n/**\n * Completes span with results and cleans up correlation\n * @param transport - MCP transport instance\n * @param requestId - Request identifier\n * @param result - Execution result for attribute extraction\n */\nexport function completeSpanWithResults(transport: MCPTransport, requestId: RequestId, result: unknown): void {\n const spanMap = getOrCreateSpanMap(transport);\n const spanData = spanMap.get(requestId);\n if (spanData) {\n const { span, method } = spanData;\n\n if (method === 'initialize') {\n const sessionData = extractSessionDataFromInitializeResponse(result);\n const serverAttributes = buildServerAttributesFromInfo(sessionData.serverInfo);\n\n const initAttributes: Record<string, string | number> = {\n ...serverAttributes,\n };\n if (sessionData.protocolVersion) {\n initAttributes[MCP_PROTOCOL_VERSION_ATTRIBUTE] = sessionData.protocolVersion;\n }\n\n span.setAttributes(initAttributes);\n } else if (method === 'tools/call') {\n const rawToolAttributes = extractToolResultAttributes(result);\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n const toolAttributes = filterMcpPiiFromSpanData(rawToolAttributes, sendDefaultPii);\n\n span.setAttributes(toolAttributes);\n } else if (method === 'prompts/get') {\n const rawPromptAttributes = extractPromptResultAttributes(result);\n const client = getClient();\n const sendDefaultPii = Boolean(client?.getOptions().sendDefaultPii);\n const promptAttributes = filterMcpPiiFromSpanData(rawPromptAttributes, sendDefaultPii);\n\n span.setAttributes(promptAttributes);\n }\n\n span.end();\n spanMap.delete(requestId);\n }\n}\n\n/**\n * Cleans up pending spans for a specific transport (when that transport closes)\n * @param transport - MCP transport instance\n */\nexport function cleanupPendingSpansForTransport(transport: MCPTransport): void {\n const spanMap = transportToSpanMap.get(transport);\n if (spanMap) {\n for (const [, spanData] of spanMap) {\n spanData.span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: 'cancelled',\n });\n spanData.span.end();\n }\n spanMap.clear();\n }\n}\n"],"names":["extractSessionDataFromInitializeResponse","buildServerAttributesFromInfo","MCP_PROTOCOL_VERSION_ATTRIBUTE","extractToolResultAttributes","getClient","filterMcpPiiFromSpanData","extractPromptResultAttributes","SPAN_STATUS_ERROR"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAWA;AACA;AACA;AACA;AACA,MAAM,kBAAA,GAAqB,IAAI,OAAO,EAAqD;;AAE3F;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,SAAS,EAAqD;AAC1F,EAAE,IAAI,UAAU,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC;AACjD,EAAE,IAAI,CAAC,OAAO,EAAE;AAChB,IAAI,OAAA,GAAU,IAAI,GAAG,EAAE;AACvB,IAAI,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;AAC9C,EAAE;AACF,EAAE,OAAO,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mBAAmB,CAAC,SAAS,EAAgB,SAAS,EAAa,IAAI,EAAQ,MAAM,EAAgB;AACrH,EAAE,MAAM,OAAA,GAAU,kBAAkB,CAAC,SAAS,CAAC;AAC/C,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;AACzB,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;AACzB,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,uBAAuB,CAAC,SAAS,EAAgB,SAAS,EAAa,MAAM,EAAiB;AAC9G,EAAE,MAAM,OAAA,GAAU,kBAAkB,CAAC,SAAS,CAAC;AAC/C,EAAE,MAAM,WAAW,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACzC,EAAE,IAAI,QAAQ,EAAE;A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d,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;AAC7B,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACO,SAAS,+BAA+B,CAAC,SAAS,EAAsB;AAC/E,EAAE,MAAM,UAAU,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC;AACnD,EAAE,IAAI,OAAO,EAAE;AACf,IAAI,KAAK,MAAM,GAAG,QAAQ,CAAA,IAAK,OAAO,EAAE;AACxC,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AAC9B,QAAQ,IAAI,EAAEE,4BAAiB;AAC/B,QAAQ,OAAO,EAAE,WAAW;AAC5B,OAAO,CAAC;AACR,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;AACzB,IAAI;AACJ,IAAI,OAAO,CAAC,KAAK,EAAE;AACnB,EAAE;AACF;;;;;;"}
@@ -92,6 +92,27 @@ function getClientAttributes(transport) {
92
92
  return attributes;
93
93
  }
94
94
 
95
+ /**
96
+ * Build client attributes from PartyInfo directly
97
+ * @param clientInfo - Client party info
98
+ * @returns Client attributes for span instrumentation
99
+ */
100
+ function buildClientAttributesFromInfo(clientInfo) {
101
+ const attributes = {};
102
+
103
+ if (clientInfo?.name) {
104
+ attributes['mcp.client.name'] = clientInfo.name;
105
+ }
106
+ if (clientInfo?.title) {
107
+ attributes['mcp.client.title'] = clientInfo.title;
108
+ }
109
+ if (clientInfo?.version) {
110
+ attributes['mcp.client.version'] = clientInfo.version;
111
+ }
112
+
113
+ return attributes;
114
+ }
115
+
95
116
  /**
96
117
  * Build server attributes from stored server info
97
118
  * @param transport - MCP transport instance
@@ -114,6 +135,27 @@ function getServerAttributes(transport) {
114
135
  return attributes$1;
115
136
  }
116
137
 
138
+ /**
139
+ * Build server attributes from PartyInfo directly
140
+ * @param serverInfo - Server party info
141
+ * @returns Server attributes for span instrumentation
142
+ */
143
+ function buildServerAttributesFromInfo(serverInfo) {
144
+ const attributes$1 = {};
145
+
146
+ if (serverInfo?.name) {
147
+ attributes$1[attributes.MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;
148
+ }
149
+ if (serverInfo?.title) {
150
+ attributes$1[attributes.MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;
151
+ }
152
+ if (serverInfo?.version) {
153
+ attributes$1[attributes.MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;
154
+ }
155
+
156
+ return attributes$1;
157
+ }
158
+
117
159
  /**
118
160
  * Extracts client connection info from extra handler data
119
161
  * @param extra - Extra handler data containing connection info
@@ -190,6 +232,8 @@ function buildTransportAttributes(
190
232
  return attributes$1;
191
233
  }
192
234
 
235
+ exports.buildClientAttributesFromInfo = buildClientAttributesFromInfo;
236
+ exports.buildServerAttributesFromInfo = buildServerAttributesFromInfo;
193
237
  exports.buildTransportAttributes = buildTransportAttributes;
194
238
  exports.extractClientInfo = extractClientInfo;
195
239
  exports.extractSessionDataFromInitializeRequest = extractSessionDataFromInitializeRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"sessionExtraction.js","sources":["../../../../src/integrations/mcp-server/sessionExtraction.ts"],"sourcesContent":["/**\n * Session and party info extraction functions for MCP server instrumentation\n *\n * Handles extraction of client/server info and session data from MCP messages.\n */\n\nimport {\n CLIENT_ADDRESS_ATTRIBUTE,\n CLIENT_PORT_ATTRIBUTE,\n MCP_PROTOCOL_VERSION_ATTRIBUTE,\n MCP_SERVER_NAME_ATTRIBUTE,\n MCP_SERVER_TITLE_ATTRIBUTE,\n MCP_SERVER_VERSION_ATTRIBUTE,\n MCP_SESSION_ID_ATTRIBUTE,\n MCP_TRANSPORT_ATTRIBUTE,\n NETWORK_PROTOCOL_VERSION_ATTRIBUTE,\n NETWORK_TRANSPORT_ATTRIBUTE,\n} from './attributes';\nimport {\n getClientInfoForTransport,\n getProtocolVersionForTransport,\n getSessionDataForTransport,\n} from './sessionManagement';\nimport type { ExtraHandlerData, JsonRpcRequest, MCPTransport, PartyInfo, SessionData } from './types';\nimport { isValidContentItem } from './validation';\n\n/**\n * Extracts and validates PartyInfo from an unknown object\n * @param obj - Unknown object that might contain party info\n * @returns Validated PartyInfo object with only string properties\n */\nfunction extractPartyInfo(obj: unknown): PartyInfo {\n const partyInfo: PartyInfo = {};\n\n if (isValidContentItem(obj)) {\n if (typeof obj.name === 'string') {\n partyInfo.name = obj.name;\n }\n if (typeof obj.title === 'string') {\n partyInfo.title = obj.title;\n }\n if (typeof obj.version === 'string') {\n partyInfo.version = obj.version;\n }\n }\n\n return partyInfo;\n}\n\n/**\n * Extracts session data from \"initialize\" requests\n * @param request - JSON-RPC \"initialize\" request containing client info and protocol version\n * @returns Session data extracted from request parameters including protocol version and client info\n */\nexport function extractSessionDataFromInitializeRequest(request: JsonRpcRequest): SessionData {\n const sessionData: SessionData = {};\n if (isValidContentItem(request.params)) {\n if (typeof request.params.protocolVersion === 'string') {\n sessionData.protocolVersion = request.params.protocolVersion;\n }\n if (request.params.clientInfo) {\n sessionData.clientInfo = extractPartyInfo(request.params.clientInfo);\n }\n }\n return sessionData;\n}\n\n/**\n * Extracts session data from \"initialize\" response\n * @param result - \"initialize\" response result containing server info and protocol version\n * @returns Partial session data extracted from response including protocol version and server info\n */\nexport function extractSessionDataFromInitializeResponse(result: unknown): Partial<SessionData> {\n const sessionData: Partial<SessionData> = {};\n if (isValidContentItem(result)) {\n if (typeof result.protocolVersion === 'string') {\n sessionData.protocolVersion = result.protocolVersion;\n }\n if (result.serverInfo) {\n sessionData.serverInfo = extractPartyInfo(result.serverInfo);\n }\n }\n return sessionData;\n}\n\n/**\n * Build client attributes from stored client info\n * @param transport - MCP transport instance\n * @returns Client attributes for span instrumentation\n */\nexport function getClientAttributes(transport: MCPTransport): Record<string, string> {\n const clientInfo = getClientInfoForTransport(transport);\n const attributes: Record<string, string> = {};\n\n if (clientInfo?.name) {\n attributes['mcp.client.name'] = clientInfo.name;\n }\n if (clientInfo?.title) {\n attributes['mcp.client.title'] = clientInfo.title;\n }\n if (clientInfo?.version) {\n attributes['mcp.client.version'] = clientInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Build server attributes from stored server info\n * @param transport - MCP transport instance\n * @returns Server attributes for span instrumentation\n */\nexport function getServerAttributes(transport: MCPTransport): Record<string, string> {\n const serverInfo = getSessionDataForTransport(transport)?.serverInfo;\n const attributes: Record<string, string> = {};\n\n if (serverInfo?.name) {\n attributes[MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;\n }\n if (serverInfo?.title) {\n attributes[MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;\n }\n if (serverInfo?.version) {\n attributes[MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Extracts client connection info from extra handler data\n * @param extra - Extra handler data containing connection info\n * @returns Client address and port information\n */\nexport function extractClientInfo(extra: ExtraHandlerData): {\n address?: string;\n port?: number;\n} {\n return {\n address:\n extra?.requestInfo?.remoteAddress ||\n extra?.clientAddress ||\n extra?.request?.ip ||\n extra?.request?.connection?.remoteAddress,\n port: extra?.requestInfo?.remotePort || extra?.clientPort || extra?.request?.connection?.remotePort,\n };\n}\n\n/**\n * Extracts transport types based on transport constructor name\n * @param transport - MCP transport instance\n * @returns Transport type mapping for span attributes\n */\nexport function getTransportTypes(transport: MCPTransport): { mcpTransport: string; networkTransport: string } {\n if (!transport?.constructor) {\n return { mcpTransport: 'unknown', networkTransport: 'unknown' };\n }\n const transportName = typeof transport.constructor?.name === 'string' ? transport.constructor.name : 'unknown';\n let networkTransport = 'unknown';\n\n const lowerTransportName = transportName.toLowerCase();\n if (lowerTransportName.includes('stdio')) {\n networkTransport = 'pipe';\n } else if (lowerTransportName.includes('http') || lowerTransportName.includes('sse')) {\n networkTransport = 'tcp';\n }\n\n return {\n mcpTransport: transportName,\n networkTransport,\n };\n}\n\n/**\n * Build transport and network attributes\n * @param transport - MCP transport instance\n * @param extra - Optional extra handler data\n * @returns Transport attributes for span instrumentation\n * @note sessionId may be undefined during initial setup - session should be established by client during initialize flow\n */\nexport function buildTransportAttributes(\n transport: MCPTransport,\n extra?: ExtraHandlerData,\n): Record<string, string | number> {\n const sessionId = transport && 'sessionId' in transport ? transport.sessionId : undefined;\n const clientInfo = extra ? extractClientInfo(extra) : {};\n const { mcpTransport, networkTransport } = getTransportTypes(transport);\n const clientAttributes = getClientAttributes(transport);\n const serverAttributes = getServerAttributes(transport);\n const protocolVersion = getProtocolVersionForTransport(transport);\n\n const attributes = {\n ...(sessionId && { [MCP_SESSION_ID_ATTRIBUTE]: sessionId }),\n ...(clientInfo.address && { [CLIENT_ADDRESS_ATTRIBUTE]: clientInfo.address }),\n ...(clientInfo.port && { [CLIENT_PORT_ATTRIBUTE]: clientInfo.port }),\n [MCP_TRANSPORT_ATTRIBUTE]: mcpTransport,\n [NETWORK_TRANSPORT_ATTRIBUTE]: networkTransport,\n [NETWORK_PROTOCOL_VERSION_ATTRIBUTE]: '2.0',\n ...(protocolVersion && { [MCP_PROTOCOL_VERSION_ATTRIBUTE]: protocolVersion }),\n ...clientAttributes,\n ...serverAttributes,\n };\n\n return attributes;\n}\n"],"names":["isValidContentItem","getClientInfoForTransport","getSessionDataForTransport","attributes","MCP_SERVER_NAME_ATTRIBUTE","MCP_SERVER_TITLE_ATTRIBUTE","MCP_SERVER_VERSION_ATTRIBUTE","getProtocolVersionForTransport","MCP_SESSION_ID_ATTRIBUTE","CLIENT_ADDRESS_ATTRIBUTE","CLIENT_PORT_ATTRIBUTE","MCP_TRANSPORT_ATTRIBUTE","NETWORK_TRANSPORT_ATTRIBUTE","NETWORK_PROTOCOL_VERSION_ATTRIBUTE","MCP_PROTOCOL_VERSION_ATTRIBUTE"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,GAAG,EAAsB;AACnD,EAAE,MAAM,SAAS,GAAc,EAAE;;AAEjC,EAAE,IAAIA,6BAAkB,CAAC,GAAG,CAAC,EAAE;AAC/B,IAAI,I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,EAAE,SAAS;AACX,EAAE,KAAK;AACP,EAAmC;AACnC,EAAE,MAAM,SAAA,GAAY,SAAA,IAAa,WAAA,IAAe,SAAA,GAAY,SAAS,CAAC,SAAA,GAAY,SAAS;AAC3F,EAAE,MAAM,UAAA,GAAa,KAAA,GAAQ,iBAAiB,CAAC,KAAK,CAAA,GAAI,EAAE;AAC1D,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAA,KAAqB,iBAAiB,CAAC,SAAS,CAAC;AACzE,EAAE,MAAM,gBAAA,GAAmB,mBAAmB,CAAC,SAAS,CAAC;AACzD,EAAE,MAAM,gBAAA,GAAmB,mBAAmB,CAAC,SAAS,CAAC;AACzD,EAAE,MAAM,eAAA,GAAkBI,gDAA8B,CAAC,SAAS,CAAC;;AAEnE,EAAE,MAAMJ,eAAa;AACrB,IAAI,IAAI,SAAA,IAAa,EAAE,CAACK,mCAAwB,GAAG,SAAA,EAAW,CAAC;AAC/D,IAAI,IAAI,UAAU,CAAC,WAAW,EAAE,CAACC,mCAAwB,GAAG,UAAU,CAAC,OAAA,EAAS,CAAC;AACjF,IAAI,IAAI,UAAU,CAAC,QAAQ,EAAE,CAACC,gCAAqB,GAAG,UAAU,CAAC,IAAA,EAAM,CAAC;AACxE,IAAI,CAACC,kCAAuB,GAAG,YAAY;AAC3C,IAAI,CAACC,sCAA2B,GAAG,gBAAgB;AACnD,IAAI,CAACC,6CAAkC,GAAG,KAAK;AAC/C,IAAI,IAAI,eAAA,IAAmB,EAAE,CAACC,yCAA8B,GAAG,eAAA,EAAiB,CAAC;AACjF,IAAI,GAAG,gBAAgB;AACvB,IAAI,GAAG,gBAAgB;AACvB,GAAG;;AAEH,EAAE,OAAOX,YAAU;AACnB;;;;;;;;;;"}
1
+ {"version":3,"file":"sessionExtraction.js","sources":["../../../../src/integrations/mcp-server/sessionExtraction.ts"],"sourcesContent":["/**\n * Session and party info extraction functions for MCP server instrumentation\n *\n * Handles extraction of client/server info and session data from MCP messages.\n */\n\nimport {\n CLIENT_ADDRESS_ATTRIBUTE,\n CLIENT_PORT_ATTRIBUTE,\n MCP_PROTOCOL_VERSION_ATTRIBUTE,\n MCP_SERVER_NAME_ATTRIBUTE,\n MCP_SERVER_TITLE_ATTRIBUTE,\n MCP_SERVER_VERSION_ATTRIBUTE,\n MCP_SESSION_ID_ATTRIBUTE,\n MCP_TRANSPORT_ATTRIBUTE,\n NETWORK_PROTOCOL_VERSION_ATTRIBUTE,\n NETWORK_TRANSPORT_ATTRIBUTE,\n} from './attributes';\nimport {\n getClientInfoForTransport,\n getProtocolVersionForTransport,\n getSessionDataForTransport,\n} from './sessionManagement';\nimport type { ExtraHandlerData, JsonRpcRequest, MCPTransport, PartyInfo, SessionData } from './types';\nimport { isValidContentItem } from './validation';\n\n/**\n * Extracts and validates PartyInfo from an unknown object\n * @param obj - Unknown object that might contain party info\n * @returns Validated PartyInfo object with only string properties\n */\nfunction extractPartyInfo(obj: unknown): PartyInfo {\n const partyInfo: PartyInfo = {};\n\n if (isValidContentItem(obj)) {\n if (typeof obj.name === 'string') {\n partyInfo.name = obj.name;\n }\n if (typeof obj.title === 'string') {\n partyInfo.title = obj.title;\n }\n if (typeof obj.version === 'string') {\n partyInfo.version = obj.version;\n }\n }\n\n return partyInfo;\n}\n\n/**\n * Extracts session data from \"initialize\" requests\n * @param request - JSON-RPC \"initialize\" request containing client info and protocol version\n * @returns Session data extracted from request parameters including protocol version and client info\n */\nexport function extractSessionDataFromInitializeRequest(request: JsonRpcRequest): SessionData {\n const sessionData: SessionData = {};\n if (isValidContentItem(request.params)) {\n if (typeof request.params.protocolVersion === 'string') {\n sessionData.protocolVersion = request.params.protocolVersion;\n }\n if (request.params.clientInfo) {\n sessionData.clientInfo = extractPartyInfo(request.params.clientInfo);\n }\n }\n return sessionData;\n}\n\n/**\n * Extracts session data from \"initialize\" response\n * @param result - \"initialize\" response result containing server info and protocol version\n * @returns Partial session data extracted from response including protocol version and server info\n */\nexport function extractSessionDataFromInitializeResponse(result: unknown): Partial<SessionData> {\n const sessionData: Partial<SessionData> = {};\n if (isValidContentItem(result)) {\n if (typeof result.protocolVersion === 'string') {\n sessionData.protocolVersion = result.protocolVersion;\n }\n if (result.serverInfo) {\n sessionData.serverInfo = extractPartyInfo(result.serverInfo);\n }\n }\n return sessionData;\n}\n\n/**\n * Build client attributes from stored client info\n * @param transport - MCP transport instance\n * @returns Client attributes for span instrumentation\n */\nexport function getClientAttributes(transport: MCPTransport): Record<string, string> {\n const clientInfo = getClientInfoForTransport(transport);\n const attributes: Record<string, string> = {};\n\n if (clientInfo?.name) {\n attributes['mcp.client.name'] = clientInfo.name;\n }\n if (clientInfo?.title) {\n attributes['mcp.client.title'] = clientInfo.title;\n }\n if (clientInfo?.version) {\n attributes['mcp.client.version'] = clientInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Build client attributes from PartyInfo directly\n * @param clientInfo - Client party info\n * @returns Client attributes for span instrumentation\n */\nexport function buildClientAttributesFromInfo(clientInfo?: PartyInfo): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n if (clientInfo?.name) {\n attributes['mcp.client.name'] = clientInfo.name;\n }\n if (clientInfo?.title) {\n attributes['mcp.client.title'] = clientInfo.title;\n }\n if (clientInfo?.version) {\n attributes['mcp.client.version'] = clientInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Build server attributes from stored server info\n * @param transport - MCP transport instance\n * @returns Server attributes for span instrumentation\n */\nexport function getServerAttributes(transport: MCPTransport): Record<string, string> {\n const serverInfo = getSessionDataForTransport(transport)?.serverInfo;\n const attributes: Record<string, string> = {};\n\n if (serverInfo?.name) {\n attributes[MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;\n }\n if (serverInfo?.title) {\n attributes[MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;\n }\n if (serverInfo?.version) {\n attributes[MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Build server attributes from PartyInfo directly\n * @param serverInfo - Server party info\n * @returns Server attributes for span instrumentation\n */\nexport function buildServerAttributesFromInfo(serverInfo?: PartyInfo): Record<string, string> {\n const attributes: Record<string, string> = {};\n\n if (serverInfo?.name) {\n attributes[MCP_SERVER_NAME_ATTRIBUTE] = serverInfo.name;\n }\n if (serverInfo?.title) {\n attributes[MCP_SERVER_TITLE_ATTRIBUTE] = serverInfo.title;\n }\n if (serverInfo?.version) {\n attributes[MCP_SERVER_VERSION_ATTRIBUTE] = serverInfo.version;\n }\n\n return attributes;\n}\n\n/**\n * Extracts client connection info from extra handler data\n * @param extra - Extra handler data containing connection info\n * @returns Client address and port information\n */\nexport function extractClientInfo(extra: ExtraHandlerData): {\n address?: string;\n port?: number;\n} {\n return {\n address:\n extra?.requestInfo?.remoteAddress ||\n extra?.clientAddress ||\n extra?.request?.ip ||\n extra?.request?.connection?.remoteAddress,\n port: extra?.requestInfo?.remotePort || extra?.clientPort || extra?.request?.connection?.remotePort,\n };\n}\n\n/**\n * Extracts transport types based on transport constructor name\n * @param transport - MCP transport instance\n * @returns Transport type mapping for span attributes\n */\nexport function getTransportTypes(transport: MCPTransport): { mcpTransport: string; networkTransport: string } {\n if (!transport?.constructor) {\n return { mcpTransport: 'unknown', networkTransport: 'unknown' };\n }\n const transportName = typeof transport.constructor?.name === 'string' ? transport.constructor.name : 'unknown';\n let networkTransport = 'unknown';\n\n const lowerTransportName = transportName.toLowerCase();\n if (lowerTransportName.includes('stdio')) {\n networkTransport = 'pipe';\n } else if (lowerTransportName.includes('http') || lowerTransportName.includes('sse')) {\n networkTransport = 'tcp';\n }\n\n return {\n mcpTransport: transportName,\n networkTransport,\n };\n}\n\n/**\n * Build transport and network attributes\n * @param transport - MCP transport instance\n * @param extra - Optional extra handler data\n * @returns Transport attributes for span instrumentation\n * @note sessionId may be undefined during initial setup - session should be established by client during initialize flow\n */\nexport function buildTransportAttributes(\n transport: MCPTransport,\n extra?: ExtraHandlerData,\n): Record<string, string | number> {\n const sessionId = transport && 'sessionId' in transport ? transport.sessionId : undefined;\n const clientInfo = extra ? extractClientInfo(extra) : {};\n const { mcpTransport, networkTransport } = getTransportTypes(transport);\n const clientAttributes = getClientAttributes(transport);\n const serverAttributes = getServerAttributes(transport);\n const protocolVersion = getProtocolVersionForTransport(transport);\n\n const attributes = {\n ...(sessionId && { [MCP_SESSION_ID_ATTRIBUTE]: sessionId }),\n ...(clientInfo.address && { [CLIENT_ADDRESS_ATTRIBUTE]: clientInfo.address }),\n ...(clientInfo.port && { [CLIENT_PORT_ATTRIBUTE]: clientInfo.port }),\n [MCP_TRANSPORT_ATTRIBUTE]: mcpTransport,\n [NETWORK_TRANSPORT_ATTRIBUTE]: networkTransport,\n [NETWORK_PROTOCOL_VERSION_ATTRIBUTE]: '2.0',\n ...(protocolVersion && { [MCP_PROTOCOL_VERSION_ATTRIBUTE]: protocolVersion }),\n ...clientAttributes,\n ...serverAttributes,\n };\n\n return attributes;\n}\n"],"names":["isValidContentItem","getClientInfoForTransport","getSessionDataForTransport","attributes","MCP_SERVER_NAME_ATTRIBUTE","MCP_SERVER_TITLE_ATTRIBUTE","MCP_SERVER_VERSION_ATTRIBUTE","getProtocolVersionForTransport","MCP_SESSION_ID_ATTRIBUTE","CLIENT_ADDRESS_ATTRIBUTE","CLIENT_PORT_ATTRIBUTE","MCP_TRANSPORT_ATTRIBUTE","NETWORK_TRANSPORT_ATTRIBUTE","NETWORK_PROTOCOL_VERSION_ATTRIBUTE","MCP_PROTOCOL_VERSION_ATTRIBUTE"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;;AAsBA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,GAAG,EAAsB;AACnD,EAAE,MAAM,SAAS,GAAc,EAAE;;AAEjC,EAAE,IAAIA,6BAAkB,CAAC,GAAG,CAAC,EAAE;AAC/B,IAAI,IAAI,OAAO,GAAG,CAAC,IAAA,KAAS,QAAQ,EAAE;AACtC,MAAM,SAAS,CAAC,IAAA,GAAO,GAAG,CAAC,IAAI;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mBAAmB,CAAC,SAAS,CAAC;AACzD,EAAE,MAAM,eAAA,GAAkBI,gDAA8B,CAAC,SAAS,CAAC;;AAEnE,EAAE,MAAMJ,eAAa;AACrB,IAAI,IAAI,SAAA,IAAa,EAAE,CAACK,mCAAwB,GAAG,SAAA,EAAW,CAAC;AAC/D,IAAI,IAAI,UAAU,CAAC,WAAW,EAAE,CAACC,mCAAwB,GAAG,UAAU,CAAC,OAAA,EAAS,CAAC;AACjF,IAAI,IAAI,UAAU,CAAC,QAAQ,EAAE,CAACC,gCAAqB,GAAG,UAAU,CAAC,IAAA,EAAM,CAAC;AACxE,IAAI,CAACC,kCAAuB,GAAG,YAAY;AAC3C,IAAI,CAACC,sCAA2B,GAAG,gBAAgB;AACnD,IAAI,CAACC,6CAAkC,GAAG,KAAK;AAC/C,IAAI,IAAI,eAAA,IAAmB,EAAE,CAACC,yCAA8B,GAAG,eAAA,EAAiB,CAAC;AACjF,IAAI,GAAG,gBAAgB;AACvB,IAAI,GAAG,gBAAgB;AACvB,GAAG;;AAEH,EAAE,OAAOX,YAAU;AACnB;;;;;;;;;;;;"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const currentScopes = require('../../currentScopes.js');
4
4
  const object = require('../../utils/object.js');
5
5
  const trace = require('../../tracing/trace.js');
6
+ const attributes = require('./attributes.js');
6
7
  const correlation = require('./correlation.js');
7
8
  const errorCapture = require('./errorCapture.js');
8
9
  const sessionExtraction = require('./sessionExtraction.js');
@@ -29,10 +30,13 @@ function wrapTransportOnMessage(transport) {
29
30
  object.fill(transport, 'onmessage', originalOnMessage => {
30
31
  return function ( message, extra) {
31
32
  if (validation.isJsonRpcRequest(message)) {
32
- if (message.method === 'initialize') {
33
+ const isInitialize = message.method === 'initialize';
34
+ let initSessionData;
35
+
36
+ if (isInitialize) {
33
37
  try {
34
- const sessionData = sessionExtraction.extractSessionDataFromInitializeRequest(message);
35
- sessionManagement.storeSessionDataForTransport(this, sessionData);
38
+ initSessionData = sessionExtraction.extractSessionDataFromInitializeRequest(message);
39
+ sessionManagement.storeSessionDataForTransport(this, initSessionData);
36
40
  } catch {
37
41
  // noop
38
42
  }
@@ -44,6 +48,16 @@ function wrapTransportOnMessage(transport) {
44
48
  const spanConfig = spans.buildMcpServerSpanConfig(message, this, extra );
45
49
  const span = trace.startInactiveSpan(spanConfig);
46
50
 
51
+ // For initialize requests, add client info directly to span (works even for stateless transports)
52
+ if (isInitialize && initSessionData) {
53
+ span.setAttributes({
54
+ ...sessionExtraction.buildClientAttributesFromInfo(initSessionData.clientInfo),
55
+ ...(initSessionData.protocolVersion && {
56
+ [attributes.MCP_PROTOCOL_VERSION_ATTRIBUTE]: initSessionData.protocolVersion,
57
+ }),
58
+ });
59
+ }
60
+
47
61
  correlation.storeSpanForRequest(this, message.id, span, message.method);
48
62
 
49
63
  return trace.withActiveSpan(span, () => {