@sentry/opentelemetry 7.74.2-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 (209) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +98 -0
  3. package/cjs/asyncContextStrategy.js +46 -0
  4. package/cjs/asyncContextStrategy.js.map +1 -0
  5. package/cjs/constants.js +18 -0
  6. package/cjs/constants.js.map +1 -0
  7. package/cjs/contextManager.js +59 -0
  8. package/cjs/contextManager.js.map +1 -0
  9. package/cjs/custom/client.js +81 -0
  10. package/cjs/custom/client.js.map +1 -0
  11. package/cjs/custom/hub.js +165 -0
  12. package/cjs/custom/hub.js.map +1 -0
  13. package/cjs/custom/hubextensions.js +34 -0
  14. package/cjs/custom/hubextensions.js.map +1 -0
  15. package/cjs/custom/scope.js +181 -0
  16. package/cjs/custom/scope.js.map +1 -0
  17. package/cjs/custom/transaction.js +52 -0
  18. package/cjs/custom/transaction.js.map +1 -0
  19. package/cjs/index.js +63 -0
  20. package/cjs/index.js.map +1 -0
  21. package/cjs/propagator.js +132 -0
  22. package/cjs/propagator.js.map +1 -0
  23. package/cjs/sampler.js +185 -0
  24. package/cjs/sampler.js.map +1 -0
  25. package/cjs/semanticAttributes.js +21 -0
  26. package/cjs/semanticAttributes.js.map +1 -0
  27. package/cjs/setupEventContextTrace.js +35 -0
  28. package/cjs/setupEventContextTrace.js.map +1 -0
  29. package/cjs/spanExporter.js +302 -0
  30. package/cjs/spanExporter.js.map +1 -0
  31. package/cjs/spanProcessor.js +88 -0
  32. package/cjs/spanProcessor.js.map +1 -0
  33. package/cjs/trace.js +107 -0
  34. package/cjs/trace.js.map +1 -0
  35. package/cjs/utils/addOriginToSpan.js +11 -0
  36. package/cjs/utils/addOriginToSpan.js.map +1 -0
  37. package/cjs/utils/captureExceptionForTimedEvent.js +58 -0
  38. package/cjs/utils/captureExceptionForTimedEvent.js.map +1 -0
  39. package/cjs/utils/contextData.js +41 -0
  40. package/cjs/utils/contextData.js.map +1 -0
  41. package/cjs/utils/convertOtelTimeToSeconds.js +9 -0
  42. package/cjs/utils/convertOtelTimeToSeconds.js.map +1 -0
  43. package/cjs/utils/getActiveSpan.js +29 -0
  44. package/cjs/utils/getActiveSpan.js.map +1 -0
  45. package/cjs/utils/getRequestSpanData.js +48 -0
  46. package/cjs/utils/getRequestSpanData.js.map +1 -0
  47. package/cjs/utils/getSpanKind.js +21 -0
  48. package/cjs/utils/getSpanKind.js.map +1 -0
  49. package/cjs/utils/groupSpansWithParents.js +74 -0
  50. package/cjs/utils/groupSpansWithParents.js.map +1 -0
  51. package/cjs/utils/isSentryRequest.js +29 -0
  52. package/cjs/utils/isSentryRequest.js.map +1 -0
  53. package/cjs/utils/mapStatus.js +76 -0
  54. package/cjs/utils/mapStatus.js.map +1 -0
  55. package/cjs/utils/parseSpanDescription.js +158 -0
  56. package/cjs/utils/parseSpanDescription.js.map +1 -0
  57. package/cjs/utils/spanData.js +59 -0
  58. package/cjs/utils/spanData.js.map +1 -0
  59. package/cjs/utils/spanTypes.js +77 -0
  60. package/cjs/utils/spanTypes.js.map +1 -0
  61. package/esm/asyncContextStrategy.js +41 -0
  62. package/esm/asyncContextStrategy.js.map +1 -0
  63. package/esm/constants.js +13 -0
  64. package/esm/constants.js.map +1 -0
  65. package/esm/contextManager.js +57 -0
  66. package/esm/contextManager.js.map +1 -0
  67. package/esm/custom/client.js +76 -0
  68. package/esm/custom/client.js.map +1 -0
  69. package/esm/custom/hub.js +159 -0
  70. package/esm/custom/hub.js.map +1 -0
  71. package/esm/custom/hubextensions.js +32 -0
  72. package/esm/custom/hubextensions.js.map +1 -0
  73. package/esm/custom/scope.js +179 -0
  74. package/esm/custom/scope.js.map +1 -0
  75. package/esm/custom/transaction.js +49 -0
  76. package/esm/custom/transaction.js.map +1 -0
  77. package/esm/index.js +32 -0
  78. package/esm/index.js.map +1 -0
  79. package/esm/propagator.js +127 -0
  80. package/esm/propagator.js.map +1 -0
  81. package/esm/sampler.js +183 -0
  82. package/esm/sampler.js.map +1 -0
  83. package/esm/semanticAttributes.js +19 -0
  84. package/esm/semanticAttributes.js.map +1 -0
  85. package/esm/setupEventContextTrace.js +33 -0
  86. package/esm/setupEventContextTrace.js.map +1 -0
  87. package/esm/spanExporter.js +300 -0
  88. package/esm/spanExporter.js.map +1 -0
  89. package/esm/spanProcessor.js +86 -0
  90. package/esm/spanProcessor.js.map +1 -0
  91. package/esm/trace.js +104 -0
  92. package/esm/trace.js.map +1 -0
  93. package/esm/utils/addOriginToSpan.js +9 -0
  94. package/esm/utils/addOriginToSpan.js.map +1 -0
  95. package/esm/utils/captureExceptionForTimedEvent.js +56 -0
  96. package/esm/utils/captureExceptionForTimedEvent.js.map +1 -0
  97. package/esm/utils/contextData.js +36 -0
  98. package/esm/utils/contextData.js.map +1 -0
  99. package/esm/utils/convertOtelTimeToSeconds.js +7 -0
  100. package/esm/utils/convertOtelTimeToSeconds.js.map +1 -0
  101. package/esm/utils/getActiveSpan.js +26 -0
  102. package/esm/utils/getActiveSpan.js.map +1 -0
  103. package/esm/utils/getRequestSpanData.js +46 -0
  104. package/esm/utils/getRequestSpanData.js.map +1 -0
  105. package/esm/utils/getSpanKind.js +19 -0
  106. package/esm/utils/getSpanKind.js.map +1 -0
  107. package/esm/utils/groupSpansWithParents.js +72 -0
  108. package/esm/utils/groupSpansWithParents.js.map +1 -0
  109. package/esm/utils/isSentryRequest.js +27 -0
  110. package/esm/utils/isSentryRequest.js.map +1 -0
  111. package/esm/utils/mapStatus.js +74 -0
  112. package/esm/utils/mapStatus.js.map +1 -0
  113. package/esm/utils/parseSpanDescription.js +154 -0
  114. package/esm/utils/parseSpanDescription.js.map +1 -0
  115. package/esm/utils/spanData.js +50 -0
  116. package/esm/utils/spanData.js.map +1 -0
  117. package/esm/utils/spanTypes.js +70 -0
  118. package/esm/utils/spanTypes.js.map +1 -0
  119. package/package.json +45 -0
  120. package/types/asyncContextStrategy.d.ts +6 -0
  121. package/types/asyncContextStrategy.d.ts.map +1 -0
  122. package/types/constants.d.ts +7 -0
  123. package/types/constants.d.ts.map +1 -0
  124. package/types/contextManager.d.ts +11 -0
  125. package/types/contextManager.d.ts.map +1 -0
  126. package/types/custom/client.d.ts +12 -0
  127. package/types/custom/client.d.ts.map +1 -0
  128. package/types/custom/hub.d.ts +40 -0
  129. package/types/custom/hub.d.ts.map +1 -0
  130. package/types/custom/hubextensions.d.ts +5 -0
  131. package/types/custom/hubextensions.d.ts.map +1 -0
  132. package/types/custom/scope.d.ts +34 -0
  133. package/types/custom/scope.d.ts.map +1 -0
  134. package/types/custom/transaction.d.ts +17 -0
  135. package/types/custom/transaction.d.ts.map +1 -0
  136. package/types/index.d.ts +31 -0
  137. package/types/index.d.ts.map +1 -0
  138. package/types/propagator.d.ts +20 -0
  139. package/types/propagator.d.ts.map +1 -0
  140. package/types/sampler.d.ts +15 -0
  141. package/types/sampler.d.ts.map +1 -0
  142. package/types/semanticAttributes.d.ts +17 -0
  143. package/types/semanticAttributes.d.ts.map +1 -0
  144. package/types/setupEventContextTrace.d.ts +4 -0
  145. package/types/setupEventContextTrace.d.ts.map +1 -0
  146. package/types/spanExporter.d.ts +17 -0
  147. package/types/spanExporter.d.ts.map +1 -0
  148. package/types/spanProcessor.d.ts +22 -0
  149. package/types/spanProcessor.d.ts.map +1 -0
  150. package/types/trace.d.ts +28 -0
  151. package/types/trace.d.ts.map +1 -0
  152. package/types/types.d.ts +26 -0
  153. package/types/types.d.ts.map +1 -0
  154. package/types/utils/addOriginToSpan.d.ts +5 -0
  155. package/types/utils/addOriginToSpan.d.ts.map +1 -0
  156. package/types/utils/captureExceptionForTimedEvent.d.ts +8 -0
  157. package/types/utils/captureExceptionForTimedEvent.d.ts.map +1 -0
  158. package/types/utils/contextData.d.ts +23 -0
  159. package/types/utils/contextData.d.ts.map +1 -0
  160. package/types/utils/convertOtelTimeToSeconds.d.ts +3 -0
  161. package/types/utils/convertOtelTimeToSeconds.d.ts.map +1 -0
  162. package/types/utils/getActiveSpan.d.ts +11 -0
  163. package/types/utils/getActiveSpan.d.ts.map +1 -0
  164. package/types/utils/getRequestSpanData.d.ts +8 -0
  165. package/types/utils/getRequestSpanData.d.ts.map +1 -0
  166. package/types/utils/getSpanKind.d.ts +10 -0
  167. package/types/utils/getSpanKind.d.ts.map +1 -0
  168. package/types/utils/groupSpansWithParents.d.ts +13 -0
  169. package/types/utils/groupSpansWithParents.d.ts.map +1 -0
  170. package/types/utils/isSentryRequest.d.ts +8 -0
  171. package/types/utils/isSentryRequest.d.ts.map +1 -0
  172. package/types/utils/mapStatus.d.ts +7 -0
  173. package/types/utils/mapStatus.d.ts.map +1 -0
  174. package/types/utils/parseSpanDescription.d.ts +32 -0
  175. package/types/utils/parseSpanDescription.d.ts.map +1 -0
  176. package/types/utils/spanData.d.ts +20 -0
  177. package/types/utils/spanData.d.ts.map +1 -0
  178. package/types/utils/spanTypes.d.ts +52 -0
  179. package/types/utils/spanTypes.d.ts.map +1 -0
  180. package/types-ts3.8/asyncContextStrategy.d.ts +6 -0
  181. package/types-ts3.8/constants.d.ts +7 -0
  182. package/types-ts3.8/contextManager.d.ts +11 -0
  183. package/types-ts3.8/custom/client.d.ts +12 -0
  184. package/types-ts3.8/custom/hub.d.ts +40 -0
  185. package/types-ts3.8/custom/hubextensions.d.ts +5 -0
  186. package/types-ts3.8/custom/scope.d.ts +34 -0
  187. package/types-ts3.8/custom/transaction.d.ts +17 -0
  188. package/types-ts3.8/index.d.ts +31 -0
  189. package/types-ts3.8/propagator.d.ts +20 -0
  190. package/types-ts3.8/sampler.d.ts +15 -0
  191. package/types-ts3.8/semanticAttributes.d.ts +17 -0
  192. package/types-ts3.8/setupEventContextTrace.d.ts +4 -0
  193. package/types-ts3.8/spanExporter.d.ts +17 -0
  194. package/types-ts3.8/spanProcessor.d.ts +22 -0
  195. package/types-ts3.8/trace.d.ts +28 -0
  196. package/types-ts3.8/types.d.ts +26 -0
  197. package/types-ts3.8/utils/addOriginToSpan.d.ts +5 -0
  198. package/types-ts3.8/utils/captureExceptionForTimedEvent.d.ts +8 -0
  199. package/types-ts3.8/utils/contextData.d.ts +23 -0
  200. package/types-ts3.8/utils/convertOtelTimeToSeconds.d.ts +6 -0
  201. package/types-ts3.8/utils/getActiveSpan.d.ts +11 -0
  202. package/types-ts3.8/utils/getRequestSpanData.d.ts +8 -0
  203. package/types-ts3.8/utils/getSpanKind.d.ts +10 -0
  204. package/types-ts3.8/utils/groupSpansWithParents.d.ts +13 -0
  205. package/types-ts3.8/utils/isSentryRequest.d.ts +8 -0
  206. package/types-ts3.8/utils/mapStatus.d.ts +7 -0
  207. package/types-ts3.8/utils/parseSpanDescription.d.ts +32 -0
  208. package/types-ts3.8/utils/spanData.d.ts +20 -0
  209. package/types-ts3.8/utils/spanTypes.d.ts +52 -0
@@ -0,0 +1,76 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ const api = require('@opentelemetry/api');
4
+ const semanticConventions = require('@opentelemetry/semantic-conventions');
5
+ const spanTypes = require('./spanTypes.js');
6
+
7
+ // canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/
8
+ const canonicalCodesHTTPMap = {
9
+ '400': 'failed_precondition',
10
+ '401': 'unauthenticated',
11
+ '403': 'permission_denied',
12
+ '404': 'not_found',
13
+ '409': 'aborted',
14
+ '429': 'resource_exhausted',
15
+ '499': 'cancelled',
16
+ '500': 'internal_error',
17
+ '501': 'unimplemented',
18
+ '503': 'unavailable',
19
+ '504': 'deadline_exceeded',
20
+ } ;
21
+
22
+ // canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.
23
+ const canonicalCodesGrpcMap = {
24
+ '1': 'cancelled',
25
+ '2': 'unknown_error',
26
+ '3': 'invalid_argument',
27
+ '4': 'deadline_exceeded',
28
+ '5': 'not_found',
29
+ '6': 'already_exists',
30
+ '7': 'permission_denied',
31
+ '8': 'resource_exhausted',
32
+ '9': 'failed_precondition',
33
+ '10': 'aborted',
34
+ '11': 'out_of_range',
35
+ '12': 'unimplemented',
36
+ '13': 'internal_error',
37
+ '14': 'unavailable',
38
+ '15': 'data_loss',
39
+ '16': 'unauthenticated',
40
+ } ;
41
+
42
+ /**
43
+ * Get a Sentry span status from an otel span.
44
+ */
45
+ function mapStatus(span) {
46
+ const attributes = spanTypes.spanHasAttributes(span) ? span.attributes : {};
47
+ const status = spanTypes.spanHasStatus(span) ? span.status : undefined;
48
+
49
+ const httpCode = attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE];
50
+ const grpcCode = attributes[semanticConventions.SemanticAttributes.RPC_GRPC_STATUS_CODE];
51
+
52
+ const code = typeof httpCode === 'string' ? httpCode : typeof httpCode === 'number' ? httpCode.toString() : undefined;
53
+ if (code) {
54
+ const sentryStatus = canonicalCodesHTTPMap[code];
55
+ if (sentryStatus) {
56
+ return sentryStatus;
57
+ }
58
+ }
59
+
60
+ if (typeof grpcCode === 'string') {
61
+ const sentryStatus = canonicalCodesGrpcMap[grpcCode];
62
+ if (sentryStatus) {
63
+ return sentryStatus;
64
+ }
65
+ }
66
+
67
+ const statusCode = status && status.code;
68
+ if (statusCode === api.SpanStatusCode.OK || statusCode === api.SpanStatusCode.UNSET) {
69
+ return 'ok';
70
+ }
71
+
72
+ return 'unknown_error';
73
+ }
74
+
75
+ exports.mapStatus = mapStatus;
76
+ //# sourceMappingURL=mapStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapStatus.js","sources":["../../../src/utils/mapStatus.ts"],"sourcesContent":["import { SpanStatusCode } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SpanStatusType as SentryStatus } from '@sentry/core';\n\nimport type { AbstractSpan } from '../types';\nimport { spanHasAttributes, spanHasStatus } from './spanTypes';\n\n// canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/\nconst canonicalCodesHTTPMap: Record<string, SentryStatus> = {\n '400': 'failed_precondition',\n '401': 'unauthenticated',\n '403': 'permission_denied',\n '404': 'not_found',\n '409': 'aborted',\n '429': 'resource_exhausted',\n '499': 'cancelled',\n '500': 'internal_error',\n '501': 'unimplemented',\n '503': 'unavailable',\n '504': 'deadline_exceeded',\n} as const;\n\n// canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.\nconst canonicalCodesGrpcMap: Record<string, SentryStatus> = {\n '1': 'cancelled',\n '2': 'unknown_error',\n '3': 'invalid_argument',\n '4': 'deadline_exceeded',\n '5': 'not_found',\n '6': 'already_exists',\n '7': 'permission_denied',\n '8': 'resource_exhausted',\n '9': 'failed_precondition',\n '10': 'aborted',\n '11': 'out_of_range',\n '12': 'unimplemented',\n '13': 'internal_error',\n '14': 'unavailable',\n '15': 'data_loss',\n '16': 'unauthenticated',\n} as const;\n\n/**\n * Get a Sentry span status from an otel span.\n */\nexport function mapStatus(span: AbstractSpan): SentryStatus {\n const attributes = spanHasAttributes(span) ? span.attributes : {};\n const status = spanHasStatus(span) ? span.status : undefined;\n\n const httpCode = attributes[SemanticAttributes.HTTP_STATUS_CODE];\n const grpcCode = attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n\n const code = typeof httpCode === 'string' ? httpCode : typeof httpCode === 'number' ? httpCode.toString() : undefined;\n if (code) {\n const sentryStatus = canonicalCodesHTTPMap[code];\n if (sentryStatus) {\n return sentryStatus;\n }\n }\n\n if (typeof grpcCode === 'string') {\n const sentryStatus = canonicalCodesGrpcMap[grpcCode];\n if (sentryStatus) {\n return sentryStatus;\n }\n }\n\n const statusCode = status && status.code;\n if (statusCode === SpanStatusCode.OK || statusCode === SpanStatusCode.UNSET) {\n return 'ok';\n }\n\n return 'unknown_error';\n}\n"],"names":["spanHasAttributes","spanHasStatus","SemanticAttributes","SpanStatusCode"],"mappings":";;;;;;AAOA;AACA,MAAA,qBAAA,GAAA;AACA,EAAA,KAAA,EAAA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,CAAA,CAAA;AACA;AACA,EAAA,MAAA,IAAA,GAAA,OAAA,QAAA,KAAA,QAAA,GAAA,QAAA,GAAA,OAAA,QAAA,KAAA,QAAA,GAAA,QAAA,CAAA,QAAA,EAAA,GAAA,SAAA,CAAA;AACA,EAAA,IAAA,IAAA,EAAA;AACA,IAAA,MAAA,YAAA,GAAA,qBAAA,CAAA,IAAA,CAAA,CAAA;AACA,IAAA,IAAA,YAAA,EAAA;AACA,MAAA,OAAA,YAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA,EAAA,IAAA,OAAA,QAAA,KAAA,QAAA,EAAA;AACA,IAAA,MAAA,YAAA,GAAA,qBAAA,CAAA,QAAA,CAAA,CAAA;AACA,IAAA,IAAA,YAAA,EAAA;AACA,MAAA,OAAA,YAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA,EAAA,MAAA,UAAA,GAAA,MAAA,IAAA,MAAA,CAAA,IAAA,CAAA;AACA,EAAA,IAAA,UAAA,KAAAC,kBAAA,CAAA,EAAA,IAAA,UAAA,KAAAA,kBAAA,CAAA,KAAA,EAAA;AACA,IAAA,OAAA,IAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,eAAA,CAAA;AACA;;;;"}
@@ -0,0 +1,158 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ const api = require('@opentelemetry/api');
4
+ const semanticConventions = require('@opentelemetry/semantic-conventions');
5
+ const utils = require('@sentry/utils');
6
+ const getSpanKind = require('./getSpanKind.js');
7
+ const spanTypes = require('./spanTypes.js');
8
+
9
+ /**
10
+ * Extract better op/description from an otel span.
11
+ *
12
+ * Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
13
+ */
14
+ function parseSpanDescription(span) {
15
+ const attributes = spanTypes.spanHasAttributes(span) ? span.attributes : {};
16
+ const name = spanTypes.spanHasName(span) ? span.name : '<unknown>';
17
+
18
+ // if http.method exists, this is an http request span
19
+ const httpMethod = attributes[semanticConventions.SemanticAttributes.HTTP_METHOD];
20
+ if (httpMethod) {
21
+ return descriptionForHttpMethod({ attributes, name, kind: getSpanKind.getSpanKind(span) }, httpMethod);
22
+ }
23
+
24
+ // If db.type exists then this is a database call span.
25
+ const dbSystem = attributes[semanticConventions.SemanticAttributes.DB_SYSTEM];
26
+ if (dbSystem) {
27
+ return descriptionForDbSystem({ attributes, name });
28
+ }
29
+
30
+ // If rpc.service exists then this is a rpc call span.
31
+ const rpcService = attributes[semanticConventions.SemanticAttributes.RPC_SERVICE];
32
+ if (rpcService) {
33
+ return {
34
+ op: 'rpc',
35
+ description: name,
36
+ source: 'route',
37
+ };
38
+ }
39
+
40
+ // If messaging.system exists then this is a messaging system span.
41
+ const messagingSystem = attributes[semanticConventions.SemanticAttributes.MESSAGING_SYSTEM];
42
+ if (messagingSystem) {
43
+ return {
44
+ op: 'message',
45
+ description: name,
46
+ source: 'route',
47
+ };
48
+ }
49
+
50
+ // If faas.trigger exists then this is a function as a service span.
51
+ const faasTrigger = attributes[semanticConventions.SemanticAttributes.FAAS_TRIGGER];
52
+ if (faasTrigger) {
53
+ return { op: faasTrigger.toString(), description: name, source: 'route' };
54
+ }
55
+
56
+ return { op: undefined, description: name, source: 'custom' };
57
+ }
58
+
59
+ function descriptionForDbSystem({ attributes, name }) {
60
+ // Use DB statement (Ex "SELECT * FROM table") if possible as description.
61
+ const statement = attributes[semanticConventions.SemanticAttributes.DB_STATEMENT];
62
+
63
+ const description = statement ? statement.toString() : name;
64
+
65
+ return { op: 'db', description, source: 'task' };
66
+ }
67
+
68
+ /** Only exported for tests. */
69
+ function descriptionForHttpMethod(
70
+ { name, kind, attributes },
71
+ httpMethod,
72
+ ) {
73
+ const opParts = ['http'];
74
+
75
+ switch (kind) {
76
+ case api.SpanKind.CLIENT:
77
+ opParts.push('client');
78
+ break;
79
+ case api.SpanKind.SERVER:
80
+ opParts.push('server');
81
+ break;
82
+ }
83
+
84
+ const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl(attributes, kind);
85
+
86
+ if (!urlPath) {
87
+ return { op: opParts.join('.'), description: name, source: 'custom' };
88
+ }
89
+
90
+ // Ex. description="GET /api/users".
91
+ const description = `${httpMethod} ${urlPath}`;
92
+
93
+ // If `httpPath` is a root path, then we can categorize the transaction source as route.
94
+ const source = hasRoute || urlPath === '/' ? 'route' : 'url';
95
+
96
+ const data = {};
97
+
98
+ if (url) {
99
+ data.url = url;
100
+ }
101
+ if (query) {
102
+ data['http.query'] = query;
103
+ }
104
+ if (fragment) {
105
+ data['http.fragment'] = fragment;
106
+ }
107
+
108
+ return {
109
+ op: opParts.join('.'),
110
+ description,
111
+ source,
112
+ data,
113
+ };
114
+ }
115
+
116
+ /** Exported for tests only */
117
+ function getSanitizedUrl(
118
+ attributes,
119
+ kind,
120
+ )
121
+
122
+ {
123
+ // This is the relative path of the URL, e.g. /sub
124
+ const httpTarget = attributes[semanticConventions.SemanticAttributes.HTTP_TARGET];
125
+ // This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
126
+ const httpUrl = attributes[semanticConventions.SemanticAttributes.HTTP_URL];
127
+ // This is the normalized route name - may not always be available!
128
+ const httpRoute = attributes[semanticConventions.SemanticAttributes.HTTP_ROUTE];
129
+
130
+ const parsedUrl = typeof httpUrl === 'string' ? utils.parseUrl(httpUrl) : undefined;
131
+ const url = parsedUrl ? utils.getSanitizedUrlString(parsedUrl) : undefined;
132
+ const query = parsedUrl && parsedUrl.search ? parsedUrl.search : undefined;
133
+ const fragment = parsedUrl && parsedUrl.hash ? parsedUrl.hash : undefined;
134
+
135
+ if (typeof httpRoute === 'string') {
136
+ return { urlPath: httpRoute, url, query, fragment, hasRoute: true };
137
+ }
138
+
139
+ if (kind === api.SpanKind.SERVER && typeof httpTarget === 'string') {
140
+ return { urlPath: utils.stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
141
+ }
142
+
143
+ if (parsedUrl) {
144
+ return { urlPath: url, url, query, fragment, hasRoute: false };
145
+ }
146
+
147
+ // fall back to target even for client spans, if no URL is present
148
+ if (typeof httpTarget === 'string') {
149
+ return { urlPath: utils.stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
150
+ }
151
+
152
+ return { urlPath: undefined, url, query, fragment, hasRoute: false };
153
+ }
154
+
155
+ exports.descriptionForHttpMethod = descriptionForHttpMethod;
156
+ exports.getSanitizedUrl = getSanitizedUrl;
157
+ exports.parseSpanDescription = parseSpanDescription;
158
+ //# sourceMappingURL=parseSpanDescription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSpanDescription.js","sources":["../../../src/utils/parseSpanDescription.ts"],"sourcesContent":["import type { Attributes, AttributeValue } from '@opentelemetry/api';\nimport { SpanKind } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { TransactionSource } from '@sentry/types';\nimport { getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from '@sentry/utils';\n\nimport type { AbstractSpan } from '../types';\nimport { getSpanKind } from './getSpanKind';\nimport { spanHasAttributes, spanHasName } from './spanTypes';\n\ninterface SpanDescription {\n op: string | undefined;\n description: string;\n source: TransactionSource;\n data?: Record<string, string>;\n}\n\n/**\n * Extract better op/description from an otel span.\n *\n * Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306\n */\nexport function parseSpanDescription(span: AbstractSpan): SpanDescription {\n const attributes = spanHasAttributes(span) ? span.attributes : {};\n const name = spanHasName(span) ? span.name : '<unknown>';\n\n // if http.method exists, this is an http request span\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);\n }\n\n // If db.type exists then this is a database call span.\n const dbSystem = attributes[SemanticAttributes.DB_SYSTEM];\n if (dbSystem) {\n return descriptionForDbSystem({ attributes, name });\n }\n\n // If rpc.service exists then this is a rpc call span.\n const rpcService = attributes[SemanticAttributes.RPC_SERVICE];\n if (rpcService) {\n return {\n op: 'rpc',\n description: name,\n source: 'route',\n };\n }\n\n // If messaging.system exists then this is a messaging system span.\n const messagingSystem = attributes[SemanticAttributes.MESSAGING_SYSTEM];\n if (messagingSystem) {\n return {\n op: 'message',\n description: name,\n source: 'route',\n };\n }\n\n // If faas.trigger exists then this is a function as a service span.\n const faasTrigger = attributes[SemanticAttributes.FAAS_TRIGGER];\n if (faasTrigger) {\n return { op: faasTrigger.toString(), description: name, source: 'route' };\n }\n\n return { op: undefined, description: name, source: 'custom' };\n}\n\nfunction descriptionForDbSystem({ attributes, name }: { attributes: Attributes; name: string }): SpanDescription {\n // Use DB statement (Ex \"SELECT * FROM table\") if possible as description.\n const statement = attributes[SemanticAttributes.DB_STATEMENT];\n\n const description = statement ? statement.toString() : name;\n\n return { op: 'db', description, source: 'task' };\n}\n\n/** Only exported for tests. */\nexport function descriptionForHttpMethod(\n { name, kind, attributes }: { name: string; attributes: Attributes; kind: SpanKind },\n httpMethod: AttributeValue,\n): SpanDescription {\n const opParts = ['http'];\n\n switch (kind) {\n case SpanKind.CLIENT:\n opParts.push('client');\n break;\n case SpanKind.SERVER:\n opParts.push('server');\n break;\n }\n\n const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl(attributes, kind);\n\n if (!urlPath) {\n return { op: opParts.join('.'), description: name, source: 'custom' };\n }\n\n // Ex. description=\"GET /api/users\".\n const description = `${httpMethod} ${urlPath}`;\n\n // If `httpPath` is a root path, then we can categorize the transaction source as route.\n const source: TransactionSource = hasRoute || urlPath === '/' ? 'route' : 'url';\n\n const data: Record<string, string> = {};\n\n if (url) {\n data.url = url;\n }\n if (query) {\n data['http.query'] = query;\n }\n if (fragment) {\n data['http.fragment'] = fragment;\n }\n\n return {\n op: opParts.join('.'),\n description,\n source,\n data,\n };\n}\n\n/** Exported for tests only */\nexport function getSanitizedUrl(\n attributes: Attributes,\n kind: SpanKind,\n): {\n url: string | undefined;\n urlPath: string | undefined;\n query: string | undefined;\n fragment: string | undefined;\n hasRoute: boolean;\n} {\n // This is the relative path of the URL, e.g. /sub\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n // This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n // This is the normalized route name - may not always be available!\n const httpRoute = attributes[SemanticAttributes.HTTP_ROUTE];\n\n const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined;\n const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined;\n const query = parsedUrl && parsedUrl.search ? parsedUrl.search : undefined;\n const fragment = parsedUrl && parsedUrl.hash ? parsedUrl.hash : undefined;\n\n if (typeof httpRoute === 'string') {\n return { urlPath: httpRoute, url, query, fragment, hasRoute: true };\n }\n\n if (kind === SpanKind.SERVER && typeof httpTarget === 'string') {\n return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };\n }\n\n if (parsedUrl) {\n return { urlPath: url, url, query, fragment, hasRoute: false };\n }\n\n // fall back to target even for client spans, if no URL is present\n if (typeof httpTarget === 'string') {\n return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };\n }\n\n return { urlPath: undefined, url, query, fragment, hasRoute: false };\n}\n"],"names":["spanHasAttributes","spanHasName","SemanticAttributes","getSpanKind","SpanKind","parseUrl","getSanitizedUrlString","stripUrlQueryAndFragment"],"mappings":";;;;;;;;AAiBA;AACA;AACA;AACA;AACA;AACA,SAAA,oBAAA,CAAA,IAAA,EAAA;AACA,EAAA,MAAA,UAAA,GAAAA,2BAAA,CAAA,IAAA,CAAA,GAAA,IAAA,CAAA,UAAA,GAAA,EAAA,CAAA;AACA,EAAA,MAAA,IAAA,GAAAC,qBAAA,CAAA,IAAA,CAAA,GAAA,IAAA,CAAA,IAAA,GAAA,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AAA,CAAA,IAAA,GAAA,SAAA,CAAA,IAAA,GAAA,SAAA,CAAA;AACA;AACA,EAAA,IAAA,OAAA,SAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,EAAA,OAAA,EAAA,SAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,IAAA,IAAA,KAAAF,YAAA,CAAA,MAAA,IAAA,OAAA,UAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,EAAA,OAAA,EAAAG,8BAAA,CAAA,UAAA,CAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA,EAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,IAAA,SAAA,EAAA;AACA,IAAA,OAAA,EAAA,OAAA,EAAA,GAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA,EAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,IAAA,OAAA,UAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,EAAA,OAAA,EAAAA,8BAAA,CAAA,UAAA,CAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA,EAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,EAAA,OAAA,EAAA,SAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA,EAAA,CAAA;AACA;;;;;;"}
@@ -0,0 +1,59 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ // We store the parent span, scope & metadata in separate weakmaps, so we can access them for a given span
4
+ // This way we can enhance the data that an OTEL Span natively gives us
5
+ // and since we are using weakmaps, we do not need to clean up after ourselves
6
+ const SpanScope = new WeakMap();
7
+ const SpanHub = new WeakMap();
8
+ const SpanParent = new WeakMap();
9
+ const SpanMetadata = new WeakMap();
10
+
11
+ /** Set the Sentry scope on an OTEL span. */
12
+ function setSpanScope(span, scope) {
13
+ SpanScope.set(span, scope);
14
+ }
15
+
16
+ /** Get the Sentry scope of an OTEL span. */
17
+ function getSpanScope(span) {
18
+ return SpanScope.get(span);
19
+ }
20
+
21
+ /** Set the Sentry hub on an OTEL span. */
22
+ function setSpanHub(span, hub) {
23
+ SpanHub.set(span, hub);
24
+ }
25
+
26
+ /** Get the Sentry hub of an OTEL span. */
27
+ function getSpanHub(span) {
28
+ return SpanHub.get(span);
29
+ }
30
+
31
+ /** Set the parent OTEL span on an OTEL span. */
32
+ function setSpanParent(span, parentSpan) {
33
+ SpanParent.set(span, parentSpan);
34
+ }
35
+
36
+ /** Get the parent OTEL span of an OTEL span. */
37
+ function getSpanParent(span) {
38
+ return SpanParent.get(span);
39
+ }
40
+
41
+ /** Set metadata for an OTEL span. */
42
+ function setSpanMetadata(span, metadata) {
43
+ SpanMetadata.set(span, metadata);
44
+ }
45
+
46
+ /** Get metadata for an OTEL span. */
47
+ function getSpanMetadata(span) {
48
+ return SpanMetadata.get(span);
49
+ }
50
+
51
+ exports.getSpanHub = getSpanHub;
52
+ exports.getSpanMetadata = getSpanMetadata;
53
+ exports.getSpanParent = getSpanParent;
54
+ exports.getSpanScope = getSpanScope;
55
+ exports.setSpanHub = setSpanHub;
56
+ exports.setSpanMetadata = setSpanMetadata;
57
+ exports.setSpanParent = setSpanParent;
58
+ exports.setSpanScope = setSpanScope;
59
+ //# sourceMappingURL=spanData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanData.js","sources":["../../../src/utils/spanData.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { Hub, Scope, TransactionMetadata } from '@sentry/types';\n\nimport type { AbstractSpan } from '../types';\n\n// We store the parent span, scope & metadata in separate weakmaps, so we can access them for a given span\n// This way we can enhance the data that an OTEL Span natively gives us\n// and since we are using weakmaps, we do not need to clean up after ourselves\nconst SpanScope = new WeakMap<AbstractSpan, Scope>();\nconst SpanHub = new WeakMap<AbstractSpan, Hub>();\nconst SpanParent = new WeakMap<AbstractSpan, Span>();\nconst SpanMetadata = new WeakMap<AbstractSpan, Partial<TransactionMetadata>>();\n\n/** Set the Sentry scope on an OTEL span. */\nexport function setSpanScope(span: AbstractSpan, scope: Scope): void {\n SpanScope.set(span, scope);\n}\n\n/** Get the Sentry scope of an OTEL span. */\nexport function getSpanScope(span: AbstractSpan): Scope | undefined {\n return SpanScope.get(span);\n}\n\n/** Set the Sentry hub on an OTEL span. */\nexport function setSpanHub(span: AbstractSpan, hub: Hub): void {\n SpanHub.set(span, hub);\n}\n\n/** Get the Sentry hub of an OTEL span. */\nexport function getSpanHub(span: AbstractSpan): Hub | undefined {\n return SpanHub.get(span);\n}\n\n/** Set the parent OTEL span on an OTEL span. */\nexport function setSpanParent(span: AbstractSpan, parentSpan: Span): void {\n SpanParent.set(span, parentSpan);\n}\n\n/** Get the parent OTEL span of an OTEL span. */\nexport function getSpanParent(span: AbstractSpan): Span | undefined {\n return SpanParent.get(span);\n}\n\n/** Set metadata for an OTEL span. */\nexport function setSpanMetadata(span: AbstractSpan, metadata: Partial<TransactionMetadata>): void {\n SpanMetadata.set(span, metadata);\n}\n\n/** Get metadata for an OTEL span. */\nexport function getSpanMetadata(span: AbstractSpan): Partial<TransactionMetadata> | undefined {\n return SpanMetadata.get(span);\n}\n"],"names":[],"mappings":";;AAKA;AACA;AACA;AACA,MAAA,SAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,OAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,UAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,YAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA;AACA;AACA,SAAA,YAAA,CAAA,IAAA,EAAA,KAAA,EAAA;AACA,EAAA,SAAA,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,YAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,SAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,UAAA,CAAA,IAAA,EAAA,GAAA,EAAA;AACA,EAAA,OAAA,CAAA,GAAA,CAAA,IAAA,EAAA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,UAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,aAAA,CAAA,IAAA,EAAA,UAAA,EAAA;AACA,EAAA,UAAA,CAAA,GAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,aAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,UAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,eAAA,CAAA,IAAA,EAAA,QAAA,EAAA;AACA,EAAA,YAAA,CAAA,GAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,eAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,YAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA;;;;;;;;;;;"}
@@ -0,0 +1,77 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ /**
4
+ * Check if a given span has attributes.
5
+ * This is necessary because the base `Span` type does not have attributes,
6
+ * so in places where we are passed a generic span, we need to check if we want to access them.
7
+ */
8
+ function spanHasAttributes(
9
+ span,
10
+ ) {
11
+ const castSpan = span ;
12
+ return !!castSpan.attributes && typeof castSpan.attributes === 'object';
13
+ }
14
+
15
+ /**
16
+ * Check if a given span has a kind.
17
+ * This is necessary because the base `Span` type does not have a kind,
18
+ * so in places where we are passed a generic span, we need to check if we want to access it.
19
+ */
20
+ function spanHasKind(span) {
21
+ const castSpan = span ;
22
+ return !!castSpan.kind;
23
+ }
24
+
25
+ /**
26
+ * Check if a given span has a status.
27
+ * This is necessary because the base `Span` type does not have a status,
28
+ * so in places where we are passed a generic span, we need to check if we want to access it.
29
+ */
30
+ function spanHasStatus(
31
+ span,
32
+ ) {
33
+ const castSpan = span ;
34
+ return !!castSpan.status;
35
+ }
36
+
37
+ /**
38
+ * Check if a given span has a name.
39
+ * This is necessary because the base `Span` type does not have a name,
40
+ * so in places where we are passed a generic span, we need to check if we want to access it.
41
+ */
42
+ function spanHasName(span) {
43
+ const castSpan = span ;
44
+ return !!castSpan.name;
45
+ }
46
+
47
+ /**
48
+ * Check if a given span has a kind.
49
+ * This is necessary because the base `Span` type does not have a kind,
50
+ * so in places where we are passed a generic span, we need to check if we want to access it.
51
+ */
52
+ function spanHasParentId(
53
+ span,
54
+ ) {
55
+ const castSpan = span ;
56
+ return !!castSpan.parentSpanId;
57
+ }
58
+
59
+ /**
60
+ * Check if a given span has events.
61
+ * This is necessary because the base `Span` type does not have events,
62
+ * so in places where we are passed a generic span, we need to check if we want to access it.
63
+ */
64
+ function spanHasEvents(
65
+ span,
66
+ ) {
67
+ const castSpan = span ;
68
+ return Array.isArray(castSpan.events);
69
+ }
70
+
71
+ exports.spanHasAttributes = spanHasAttributes;
72
+ exports.spanHasEvents = spanHasEvents;
73
+ exports.spanHasKind = spanHasKind;
74
+ exports.spanHasName = spanHasName;
75
+ exports.spanHasParentId = spanHasParentId;
76
+ exports.spanHasStatus = spanHasStatus;
77
+ //# sourceMappingURL=spanTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spanTypes.js","sources":["../../../src/utils/spanTypes.ts"],"sourcesContent":["import type { SpanKind, SpanStatus } from '@opentelemetry/api';\nimport type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';\n\nimport type { AbstractSpan } from '../types';\n\n/**\n * Check if a given span has attributes.\n * This is necessary because the base `Span` type does not have attributes,\n * so in places where we are passed a generic span, we need to check if we want to access them.\n */\nexport function spanHasAttributes<SpanType extends AbstractSpan>(\n span: SpanType,\n): span is SpanType & { attributes: ReadableSpan['attributes'] } {\n const castSpan = span as ReadableSpan;\n return !!castSpan.attributes && typeof castSpan.attributes === 'object';\n}\n\n/**\n * Check if a given span has a kind.\n * This is necessary because the base `Span` type does not have a kind,\n * so in places where we are passed a generic span, we need to check if we want to access it.\n */\nexport function spanHasKind<SpanType extends AbstractSpan>(span: SpanType): span is SpanType & { kind: SpanKind } {\n const castSpan = span as ReadableSpan;\n return !!castSpan.kind;\n}\n\n/**\n * Check if a given span has a status.\n * This is necessary because the base `Span` type does not have a status,\n * so in places where we are passed a generic span, we need to check if we want to access it.\n */\nexport function spanHasStatus<SpanType extends AbstractSpan>(\n span: SpanType,\n): span is SpanType & { status: SpanStatus } {\n const castSpan = span as ReadableSpan;\n return !!castSpan.status;\n}\n\n/**\n * Check if a given span has a name.\n * This is necessary because the base `Span` type does not have a name,\n * so in places where we are passed a generic span, we need to check if we want to access it.\n */\nexport function spanHasName<SpanType extends AbstractSpan>(span: SpanType): span is SpanType & { name: string } {\n const castSpan = span as ReadableSpan;\n return !!castSpan.name;\n}\n\n/**\n * Check if a given span has a kind.\n * This is necessary because the base `Span` type does not have a kind,\n * so in places where we are passed a generic span, we need to check if we want to access it.\n */\nexport function spanHasParentId<SpanType extends AbstractSpan>(\n span: SpanType,\n): span is SpanType & { parentSpanId: string } {\n const castSpan = span as ReadableSpan;\n return !!castSpan.parentSpanId;\n}\n\n/**\n * Check if a given span has events.\n * This is necessary because the base `Span` type does not have events,\n * so in places where we are passed a generic span, we need to check if we want to access it.\n */\nexport function spanHasEvents<SpanType extends AbstractSpan>(\n span: SpanType,\n): span is SpanType & { events: TimedEvent[] } {\n const castSpan = span as ReadableSpan;\n return Array.isArray(castSpan.events);\n}\n"],"names":[],"mappings":";;AAKA;AACA;AACA;AACA;AACA;AACA,SAAA,iBAAA;AACA,EAAA,IAAA;AACA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,CAAA,CAAA,QAAA,CAAA,UAAA,IAAA,OAAA,QAAA,CAAA,UAAA,KAAA,QAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,WAAA,CAAA,IAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,CAAA,CAAA,QAAA,CAAA,IAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,aAAA;AACA,EAAA,IAAA;AACA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,CAAA,CAAA,QAAA,CAAA,MAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,WAAA,CAAA,IAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,CAAA,CAAA,QAAA,CAAA,IAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,eAAA;AACA,EAAA,IAAA;AACA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,CAAA,CAAA,QAAA,CAAA,YAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,aAAA;AACA,EAAA,IAAA;AACA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,EAAA;AACA,EAAA,OAAA,KAAA,CAAA,OAAA,CAAA,QAAA,CAAA,MAAA,CAAA,CAAA;AACA;;;;;;;;;"}
@@ -0,0 +1,41 @@
1
+ import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
2
+ import * as api from '@opentelemetry/api';
3
+ import { setAsyncContextStrategy } from '@sentry/core';
4
+ import { getHubFromContext } from './utils/contextData.js';
5
+
6
+ /**
7
+ * Sets the async context strategy to use follow the OTEL context under the hood.
8
+ * We handle forking a hub inside of our custom OTEL Context Manager (./otelContextManager.ts)
9
+ */
10
+ function setOpenTelemetryContextAsyncContextStrategy() {
11
+ function getCurrentHub() {
12
+ const ctx = api.context.active();
13
+
14
+ // Returning undefined means the global hub will be used
15
+ // Need to cast from @sentry/type's `Hub` to @sentry/core's `Hub`
16
+ return getHubFromContext(ctx) ;
17
+ }
18
+
19
+ /* This is more or less a NOOP - we rely on the OTEL context manager for this */
20
+ function runWithAsyncContext(callback, options) {
21
+ const existingHub = getCurrentHub();
22
+
23
+ if (existingHub && _optionalChain([options, 'optionalAccess', _ => _.reuseExisting])) {
24
+ // We're already in an async context, so we don't need to create a new one
25
+ // just call the callback with the current hub
26
+ return callback();
27
+ }
28
+
29
+ const ctx = api.context.active();
30
+
31
+ // We depend on the otelContextManager to handle the context/hub
32
+ return api.context.with(ctx, () => {
33
+ return callback();
34
+ });
35
+ }
36
+
37
+ setAsyncContextStrategy({ getCurrentHub, runWithAsyncContext });
38
+ }
39
+
40
+ export { setOpenTelemetryContextAsyncContextStrategy };
41
+ //# sourceMappingURL=asyncContextStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContextStrategy.js","sources":["../../src/asyncContextStrategy.ts"],"sourcesContent":["import * as api from '@opentelemetry/api';\nimport type { Hub, RunWithAsyncContextOptions } from '@sentry/core';\nimport { setAsyncContextStrategy } from '@sentry/core';\n\nimport { getHubFromContext } from './utils/contextData';\n\n/**\n * Sets the async context strategy to use follow the OTEL context under the hood.\n * We handle forking a hub inside of our custom OTEL Context Manager (./otelContextManager.ts)\n */\nexport function setOpenTelemetryContextAsyncContextStrategy(): void {\n function getCurrentHub(): Hub | undefined {\n const ctx = api.context.active();\n\n // Returning undefined means the global hub will be used\n // Need to cast from @sentry/type's `Hub` to @sentry/core's `Hub`\n return getHubFromContext(ctx) as Hub | undefined;\n }\n\n /* This is more or less a NOOP - we rely on the OTEL context manager for this */\n function runWithAsyncContext<T>(callback: () => T, options: RunWithAsyncContextOptions): T {\n const existingHub = getCurrentHub();\n\n if (existingHub && options?.reuseExisting) {\n // We're already in an async context, so we don't need to create a new one\n // just call the callback with the current hub\n return callback();\n }\n\n const ctx = api.context.active();\n\n // We depend on the otelContextManager to handle the context/hub\n return api.context.with(ctx, () => {\n return callback();\n });\n }\n\n setAsyncContextStrategy({ getCurrentHub, runWithAsyncContext });\n}\n"],"names":[],"mappings":";;;;;AAMA,CAAA,CAAA;CACA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA;CACA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;CACA,CAAA;AACA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,2CAAA,CAAA,EAAA;EACA,CAAA,C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CAAA,CAAA,CAAA,CAAA;IACA,CAAA,CAAA;EACA;;EAEA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA;AACA;;"}
@@ -0,0 +1,13 @@
1
+ import { createContextKey } from '@opentelemetry/api';
2
+
3
+ const SENTRY_TRACE_HEADER = 'sentry-trace';
4
+ const SENTRY_BAGGAGE_HEADER = 'baggage';
5
+
6
+ /** Context Key to hold a PropagationContext. */
7
+ const SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY = createContextKey('SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY');
8
+
9
+ /** Context Key to hold a Hub. */
10
+ const SENTRY_HUB_CONTEXT_KEY = createContextKey('sentry_hub');
11
+
12
+ export { SENTRY_BAGGAGE_HEADER, SENTRY_HUB_CONTEXT_KEY, SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY, SENTRY_TRACE_HEADER };
13
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import { createContextKey } from '@opentelemetry/api';\n\nexport const SENTRY_TRACE_HEADER = 'sentry-trace';\nexport const SENTRY_BAGGAGE_HEADER = 'baggage';\n\n/** Context Key to hold a PropagationContext. */\nexport const SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY = createContextKey('SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY');\n\n/** Context Key to hold a Hub. */\nexport const SENTRY_HUB_CONTEXT_KEY = createContextKey('sentry_hub');\n"],"names":[],"mappings":";;AAEA,MAAA,mBAAA,GAAA,eAAA;AACA,MAAA,qBAAA,GAAA,UAAA;AACA;AACA;AACA,MAAA,sCAAA,GAAA,gBAAA,CAAA,wCAAA,EAAA;AACA;AACA;AACA,MAAA,sBAAA,GAAA,gBAAA,CAAA,YAAA;;;;"}
@@ -0,0 +1,57 @@
1
+ import { getCurrentHub, ensureHubOnCarrier, getHubFromCarrier } from './custom/hub.js';
2
+ import { setHubOnContext } from './utils/contextData.js';
3
+
4
+ function createNewHub(parent) {
5
+ const carrier = {};
6
+ ensureHubOnCarrier(carrier, parent);
7
+ return getHubFromCarrier(carrier);
8
+ }
9
+
10
+ // Typescript complains if we do not use `...args: any[]` for the mixin, with:
11
+ // A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+
14
+ /**
15
+ * Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.
16
+ *
17
+ * Usage:
18
+ * import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
19
+ * const SentryContextManager = wrapContextManagerClass(AsyncLocalStorageContextManager);
20
+ * const contextManager = new SentryContextManager();
21
+ */
22
+ function wrapContextManagerClass(
23
+ ContextManagerClass,
24
+ ) {
25
+ /**
26
+ * This is a custom ContextManager for OpenTelemetry, which extends the default AsyncLocalStorageContextManager.
27
+ * It ensures that we create a new hub per context, so that the OTEL Context & the Sentry Hub are always in sync.
28
+ *
29
+ * Note that we currently only support AsyncHooks with this,
30
+ * but since this should work for Node 14+ anyhow that should be good enough.
31
+ */
32
+
33
+ // @ts-expect-error TS does not like this, but we know this is fine
34
+ class SentryContextManager extends ContextManagerClass {
35
+ /**
36
+ * Overwrite with() of the original AsyncLocalStorageContextManager
37
+ * to ensure we also create a new hub per context.
38
+ */
39
+ with(
40
+ context,
41
+ fn,
42
+ thisArg,
43
+ ...args
44
+ ) {
45
+ const existingHub = getCurrentHub();
46
+ const newHub = createNewHub(existingHub);
47
+
48
+ return super.with(setHubOnContext(context, newHub), fn, thisArg, ...args);
49
+ }
50
+ }
51
+
52
+ return SentryContextManager ;
53
+ }
54
+ /* eslint-enable @typescript-eslint/no-explicit-any */
55
+
56
+ export { wrapContextManagerClass };
57
+ //# sourceMappingURL=contextManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextManager.js","sources":["../../src/contextManager.ts"],"sourcesContent":["import type { Context, ContextManager } from '@opentelemetry/api';\nimport type { Carrier, Hub } from '@sentry/core';\n\nimport { ensureHubOnCarrier, getCurrentHub, getHubFromCarrier } from './custom/hub';\nimport { setHubOnContext } from './utils/contextData';\n\nfunction createNewHub(parent: Hub | undefined): Hub {\n const carrier: Carrier = {};\n ensureHubOnCarrier(carrier, parent);\n return getHubFromCarrier(carrier);\n}\n\n// Typescript complains if we do not use `...args: any[]` for the mixin, with:\n// A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.\n *\n * Usage:\n * import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';\n * const SentryContextManager = wrapContextManagerClass(AsyncLocalStorageContextManager);\n * const contextManager = new SentryContextManager();\n */\nexport function wrapContextManagerClass<ContextManagerInstance extends ContextManager>(\n ContextManagerClass: new (...args: any[]) => ContextManagerInstance,\n): typeof ContextManagerClass {\n /**\n * This is a custom ContextManager for OpenTelemetry, which extends the default AsyncLocalStorageContextManager.\n * It ensures that we create a new hub per context, so that the OTEL Context & the Sentry Hub are always in sync.\n *\n * Note that we currently only support AsyncHooks with this,\n * but since this should work for Node 14+ anyhow that should be good enough.\n */\n\n // @ts-expect-error TS does not like this, but we know this is fine\n class SentryContextManager extends ContextManagerClass {\n /**\n * Overwrite with() of the original AsyncLocalStorageContextManager\n * to ensure we also create a new hub per context.\n */\n public with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n const existingHub = getCurrentHub();\n const newHub = createNewHub(existingHub);\n\n return super.with(setHubOnContext(context, newHub), fn, thisArg, ...args);\n }\n }\n\n return SentryContextManager as unknown as typeof ContextManagerClass;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any */\n"],"names":[],"mappings":";;;AAMA,SAAA,YAAA,CAAA,MAAA,EAAA;AACA,EAAA,MAAA,OAAA,GAAA,EAAA,CAAA;AACA,EAAA,kBAAA,CAAA,OAAA,EAAA,MAAA,CAAA,CAAA;AACA,EAAA,OAAA,iBAAA,CAAA,OAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,uBAAA;AACA,EAAA,mBAAA;AACA,EAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAA,MAAA,oBAAA,SAAA,mBAAA,CAAA;AACA;AACA;AACA;AACA;AACA,KAAA,IAAA;AACA,MAAA,OAAA;AACA,MAAA,EAAA;AACA,MAAA,OAAA;AACA,MAAA,GAAA,IAAA;AACA,MAAA;AACA,MAAA,MAAA,WAAA,GAAA,aAAA,EAAA,CAAA;AACA,MAAA,MAAA,MAAA,GAAA,YAAA,CAAA,WAAA,CAAA,CAAA;AACA;AACA,MAAA,OAAA,KAAA,CAAA,IAAA,CAAA,eAAA,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,EAAA,EAAA,OAAA,EAAA,GAAA,IAAA,CAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,oBAAA,EAAA;AACA,CAAA;AACA;;;;"}
@@ -0,0 +1,76 @@
1
+ import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';
2
+ import { trace } from '@opentelemetry/api';
3
+ import { SDK_VERSION } from '@sentry/core';
4
+ import { OpenTelemetryScope } from './scope.js';
5
+
6
+ // Typescript complains if we do not use `...args: any[]` for the mixin, with:
7
+ // A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+
10
+ /**
11
+ * Wrap an Client with things we need for OpenTelemetry support.
12
+ *
13
+ * Usage:
14
+ * const OpenTelemetryClient = getWrappedClientClass(NodeClient);
15
+ * const client = new OpenTelemetryClient(options);
16
+ */
17
+ function wrapClientClass
18
+
19
+ (ClientClass) {
20
+ class OpenTelemetryClient extends ClientClass {
21
+
22
+ constructor(...args) {
23
+ super(...args);
24
+ }
25
+
26
+ /** Get the OTEL tracer. */
27
+ get tracer() {
28
+ if (this._tracer) {
29
+ return this._tracer;
30
+ }
31
+
32
+ const name = '@sentry/opentelemetry';
33
+ const version = SDK_VERSION;
34
+ const tracer = trace.getTracer(name, version);
35
+ this._tracer = tracer;
36
+
37
+ return tracer;
38
+ }
39
+
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ async flush(timeout) {
44
+ const provider = this.traceProvider;
45
+ const spanProcessor = _optionalChain([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
46
+
47
+ if (spanProcessor) {
48
+ await spanProcessor.forceFlush();
49
+ }
50
+
51
+ return super.flush(timeout);
52
+ }
53
+
54
+ /**
55
+ * Extends the base `_prepareEvent` so that we can properly handle `captureContext`.
56
+ * This uses `Scope.clone()`, which we need to replace with `NodeExperimentalScope.clone()` for this client.
57
+ */
58
+ _prepareEvent(event, hint, scope) {
59
+ let actualScope = scope;
60
+
61
+ // Remove `captureContext` hint and instead clone already here
62
+ if (hint && hint.captureContext) {
63
+ actualScope = OpenTelemetryScope.clone(scope);
64
+ delete hint.captureContext;
65
+ }
66
+
67
+ return super._prepareEvent(event, hint, actualScope);
68
+ }
69
+ }
70
+
71
+ return OpenTelemetryClient ;
72
+ }
73
+ /* eslint-enable @typescript-eslint/no-explicit-any */
74
+
75
+ export { wrapClientClass };
76
+ //# sourceMappingURL=client.js.map