@sentry/node 10.60.0 → 10.62.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 (182) hide show
  1. package/build/cjs/index.js +2 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/fs/index.js +8 -17
  4. package/build/cjs/integrations/fs/index.js.map +1 -1
  5. package/build/cjs/integrations/fs/vendored/instrumentation.js +110 -161
  6. package/build/cjs/integrations/fs/vendored/instrumentation.js.map +1 -1
  7. package/build/cjs/integrations/node-fetch/vendored/undici.js +1 -2
  8. package/build/cjs/integrations/node-fetch/vendored/undici.js.map +1 -1
  9. package/build/cjs/integrations/tracing/amqplib/index.js +2 -10
  10. package/build/cjs/integrations/tracing/amqplib/index.js.map +1 -1
  11. package/build/cjs/integrations/tracing/amqplib/vendored/instrumentation.js +117 -0
  12. package/build/cjs/integrations/tracing/amqplib/vendored/instrumentation.js.map +1 -0
  13. package/build/cjs/integrations/tracing/amqplib/vendored/patches.js +185 -0
  14. package/build/cjs/integrations/tracing/amqplib/vendored/patches.js.map +1 -0
  15. package/build/cjs/integrations/tracing/amqplib/vendored/semconv.js +21 -1
  16. package/build/cjs/integrations/tracing/amqplib/vendored/semconv.js.map +1 -1
  17. package/build/cjs/integrations/tracing/amqplib/vendored/types.js +0 -6
  18. package/build/cjs/integrations/tracing/amqplib/vendored/types.js.map +1 -1
  19. package/build/cjs/integrations/tracing/amqplib/vendored/utils.js +71 -80
  20. package/build/cjs/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
  21. package/build/cjs/integrations/tracing/dataloader/vendored/instrumentation.js +5 -6
  22. package/build/cjs/integrations/tracing/dataloader/vendored/instrumentation.js.map +1 -1
  23. package/build/cjs/integrations/tracing/firebase/firebase.js +1 -24
  24. package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -1
  25. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js +3 -11
  26. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -1
  27. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +33 -72
  28. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
  29. package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js +46 -105
  30. package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js.map +1 -1
  31. package/build/cjs/integrations/tracing/kafka/vendored/utils.js +2 -2
  32. package/build/cjs/integrations/tracing/kafka/vendored/utils.js.map +1 -1
  33. package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js +1 -2
  34. package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
  35. package/build/cjs/integrations/tracing/mongo/vendored/utils.js +1 -2
  36. package/build/cjs/integrations/tracing/mongo/vendored/utils.js.map +1 -1
  37. package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js +1 -2
  38. package/build/cjs/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
  39. package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js +1 -2
  40. package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
  41. package/build/cjs/integrations/tracing/postgres/vendored/instrumentation.js +2 -3
  42. package/build/cjs/integrations/tracing/postgres/vendored/instrumentation.js.map +1 -1
  43. package/build/cjs/integrations/tracing/postgres/vendored/utils.js +1 -2
  44. package/build/cjs/integrations/tracing/postgres/vendored/utils.js.map +1 -1
  45. package/build/cjs/integrations/tracing/redis/index.js +6 -2
  46. package/build/cjs/integrations/tracing/redis/index.js.map +1 -1
  47. package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js +2 -3
  48. package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
  49. package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js +3 -4
  50. package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
  51. package/build/cjs/integrations/tracing/tedious/vendored/instrumentation.js +1 -2
  52. package/build/cjs/integrations/tracing/tedious/vendored/instrumentation.js.map +1 -1
  53. package/build/cjs/integrations/tracing/vercelai/index.js +3 -0
  54. package/build/cjs/integrations/tracing/vercelai/index.js.map +1 -1
  55. package/build/esm/index.js +1 -1
  56. package/build/esm/integrations/fs/index.js +9 -18
  57. package/build/esm/integrations/fs/index.js.map +1 -1
  58. package/build/esm/integrations/fs/vendored/instrumentation.js +111 -162
  59. package/build/esm/integrations/fs/vendored/instrumentation.js.map +1 -1
  60. package/build/esm/integrations/node-fetch/vendored/undici.js +2 -3
  61. package/build/esm/integrations/node-fetch/vendored/undici.js.map +1 -1
  62. package/build/esm/integrations/tracing/amqplib/index.js +3 -11
  63. package/build/esm/integrations/tracing/amqplib/index.js.map +1 -1
  64. package/build/esm/integrations/tracing/amqplib/vendored/instrumentation.js +115 -0
  65. package/build/esm/integrations/tracing/amqplib/vendored/instrumentation.js.map +1 -0
  66. package/build/esm/integrations/tracing/amqplib/vendored/patches.js +177 -0
  67. package/build/esm/integrations/tracing/amqplib/vendored/patches.js.map +1 -0
  68. package/build/esm/integrations/tracing/amqplib/vendored/semconv.js +12 -2
  69. package/build/esm/integrations/tracing/amqplib/vendored/semconv.js.map +1 -1
  70. package/build/esm/integrations/tracing/amqplib/vendored/types.js +1 -6
  71. package/build/esm/integrations/tracing/amqplib/vendored/types.js.map +1 -1
  72. package/build/esm/integrations/tracing/amqplib/vendored/utils.js +68 -78
  73. package/build/esm/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
  74. package/build/esm/integrations/tracing/dataloader/vendored/instrumentation.js +6 -7
  75. package/build/esm/integrations/tracing/dataloader/vendored/instrumentation.js.map +1 -1
  76. package/build/esm/integrations/tracing/firebase/firebase.js +3 -26
  77. package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -1
  78. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js +3 -11
  79. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -1
  80. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +34 -73
  81. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
  82. package/build/esm/integrations/tracing/firebase/otel/patches/functions.js +47 -106
  83. package/build/esm/integrations/tracing/firebase/otel/patches/functions.js.map +1 -1
  84. package/build/esm/integrations/tracing/kafka/vendored/utils.js +4 -4
  85. package/build/esm/integrations/tracing/kafka/vendored/utils.js.map +1 -1
  86. package/build/esm/integrations/tracing/knex/vendored/instrumentation.js +2 -3
  87. package/build/esm/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
  88. package/build/esm/integrations/tracing/mongo/vendored/utils.js +2 -3
  89. package/build/esm/integrations/tracing/mongo/vendored/utils.js.map +1 -1
  90. package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js +2 -3
  91. package/build/esm/integrations/tracing/mongoose/vendored/mongoose.js.map +1 -1
  92. package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js +2 -3
  93. package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
  94. package/build/esm/integrations/tracing/postgres/vendored/instrumentation.js +3 -4
  95. package/build/esm/integrations/tracing/postgres/vendored/instrumentation.js.map +1 -1
  96. package/build/esm/integrations/tracing/postgres/vendored/utils.js +2 -3
  97. package/build/esm/integrations/tracing/postgres/vendored/utils.js.map +1 -1
  98. package/build/esm/integrations/tracing/redis/index.js +6 -2
  99. package/build/esm/integrations/tracing/redis/index.js.map +1 -1
  100. package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js +3 -4
  101. package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
  102. package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js +4 -5
  103. package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
  104. package/build/esm/integrations/tracing/tedious/vendored/instrumentation.js +2 -3
  105. package/build/esm/integrations/tracing/tedious/vendored/instrumentation.js.map +1 -1
  106. package/build/esm/integrations/tracing/vercelai/index.js +3 -0
  107. package/build/esm/integrations/tracing/vercelai/index.js.map +1 -1
  108. package/build/esm/package.json +1 -1
  109. package/build/types/index.d.ts +1 -1
  110. package/build/types/index.d.ts.map +1 -1
  111. package/build/types/integrations/fs/index.d.ts +2 -14
  112. package/build/types/integrations/fs/index.d.ts.map +1 -1
  113. package/build/types/integrations/fs/vendored/instrumentation.d.ts +2 -10
  114. package/build/types/integrations/fs/vendored/instrumentation.d.ts.map +1 -1
  115. package/build/types/integrations/fs/vendored/types.d.ts +1 -2
  116. package/build/types/integrations/fs/vendored/types.d.ts.map +1 -1
  117. package/build/types/integrations/node-fetch/vendored/undici.d.ts.map +1 -1
  118. package/build/types/integrations/tracing/amqplib/index.d.ts +1 -1
  119. package/build/types/integrations/tracing/amqplib/index.d.ts.map +1 -1
  120. package/build/types/integrations/tracing/amqplib/vendored/instrumentation.d.ts +11 -0
  121. package/build/types/integrations/tracing/amqplib/vendored/instrumentation.d.ts.map +1 -0
  122. package/build/types/integrations/tracing/amqplib/vendored/patches.d.ts +11 -0
  123. package/build/types/integrations/tracing/amqplib/vendored/patches.d.ts.map +1 -0
  124. package/build/types/integrations/tracing/amqplib/vendored/semconv.d.ts +25 -37
  125. package/build/types/integrations/tracing/amqplib/vendored/semconv.d.ts.map +1 -1
  126. package/build/types/integrations/tracing/amqplib/vendored/types.d.ts +0 -81
  127. package/build/types/integrations/tracing/amqplib/vendored/types.d.ts.map +1 -1
  128. package/build/types/integrations/tracing/amqplib/vendored/utils.d.ts +16 -9
  129. package/build/types/integrations/tracing/amqplib/vendored/utils.d.ts.map +1 -1
  130. package/build/types/integrations/tracing/dataloader/vendored/instrumentation.d.ts.map +1 -1
  131. package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -1
  132. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +4 -9
  133. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts.map +1 -1
  134. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts +2 -5
  135. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts.map +1 -1
  136. package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts +3 -8
  137. package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts.map +1 -1
  138. package/build/types/integrations/tracing/firebase/otel/types.d.ts +0 -20
  139. package/build/types/integrations/tracing/firebase/otel/types.d.ts.map +1 -1
  140. package/build/types/integrations/tracing/kafka/vendored/utils.d.ts.map +1 -1
  141. package/build/types/integrations/tracing/knex/vendored/instrumentation.d.ts.map +1 -1
  142. package/build/types/integrations/tracing/mongo/vendored/utils.d.ts.map +1 -1
  143. package/build/types/integrations/tracing/mongoose/vendored/mongoose.d.ts.map +1 -1
  144. package/build/types/integrations/tracing/mysql2/vendored/instrumentation.d.ts.map +1 -1
  145. package/build/types/integrations/tracing/postgres/vendored/instrumentation.d.ts.map +1 -1
  146. package/build/types/integrations/tracing/postgres/vendored/utils.d.ts.map +1 -1
  147. package/build/types/integrations/tracing/redis/index.d.ts.map +1 -1
  148. package/build/types/integrations/tracing/redis/vendored/ioredis-instrumentation.d.ts.map +1 -1
  149. package/build/types/integrations/tracing/redis/vendored/redis-instrumentation.d.ts.map +1 -1
  150. package/build/types/integrations/tracing/tedious/vendored/instrumentation.d.ts.map +1 -1
  151. package/build/types/integrations/tracing/vercelai/index.d.ts +0 -1
  152. package/build/types/integrations/tracing/vercelai/index.d.ts.map +1 -1
  153. package/build/types-ts3.8/index.d.ts +1 -1
  154. package/build/types-ts3.8/integrations/fs/index.d.ts +2 -14
  155. package/build/types-ts3.8/integrations/fs/vendored/instrumentation.d.ts +2 -10
  156. package/build/types-ts3.8/integrations/fs/vendored/types.d.ts +1 -2
  157. package/build/types-ts3.8/integrations/tracing/amqplib/index.d.ts +1 -1
  158. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/instrumentation.d.ts +11 -0
  159. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/patches.d.ts +11 -0
  160. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/semconv.d.ts +25 -37
  161. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/types.d.ts +0 -81
  162. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/utils.d.ts +16 -9
  163. package/build/types-ts3.8/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +4 -9
  164. package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/firestore.d.ts +2 -5
  165. package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/functions.d.ts +3 -8
  166. package/build/types-ts3.8/integrations/tracing/firebase/otel/types.d.ts +0 -20
  167. package/build/types-ts3.8/integrations/tracing/vercelai/index.d.ts +0 -1
  168. package/package.json +5 -5
  169. package/build/cjs/integrations/tracing/amqplib/vendored/amqplib.js +0 -452
  170. package/build/cjs/integrations/tracing/amqplib/vendored/amqplib.js.map +0 -1
  171. package/build/cjs/integrations/tracing/amqplib/vendored/semconv-obsolete.js +0 -24
  172. package/build/cjs/integrations/tracing/amqplib/vendored/semconv-obsolete.js.map +0 -1
  173. package/build/esm/integrations/tracing/amqplib/vendored/amqplib.js +0 -450
  174. package/build/esm/integrations/tracing/amqplib/vendored/amqplib.js.map +0 -1
  175. package/build/esm/integrations/tracing/amqplib/vendored/semconv-obsolete.js +0 -13
  176. package/build/esm/integrations/tracing/amqplib/vendored/semconv-obsolete.js.map +0 -1
  177. package/build/types/integrations/tracing/amqplib/vendored/amqplib.d.ts +0 -26
  178. package/build/types/integrations/tracing/amqplib/vendored/amqplib.d.ts.map +0 -1
  179. package/build/types/integrations/tracing/amqplib/vendored/semconv-obsolete.d.ts +0 -63
  180. package/build/types/integrations/tracing/amqplib/vendored/semconv-obsolete.d.ts.map +0 -1
  181. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/amqplib.d.ts +0 -26
  182. package/build/types-ts3.8/integrations/tracing/amqplib/vendored/semconv-obsolete.d.ts +0 -63
@@ -1,35 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const net = require('node:net');
4
- const api = require('@opentelemetry/api');
5
4
  const instrumentation = require('@opentelemetry/instrumentation');
6
5
  const InstrumentationNodeModuleFile = require('../../../InstrumentationNodeModuleFile.js');
7
6
  const semanticConventions = require('@opentelemetry/semantic-conventions');
7
+ const core = require('@sentry/core');
8
8
 
9
- function patchFirestore(tracer, firestoreSupportedVersions, wrap, unwrap, config) {
10
- const defaultFirestoreSpanCreationHook = () => {
11
- };
12
- let firestoreSpanCreationHook = defaultFirestoreSpanCreationHook;
13
- const configFirestoreSpanCreationHook = config.firestoreSpanCreationHook;
14
- if (typeof configFirestoreSpanCreationHook === "function") {
15
- firestoreSpanCreationHook = (span) => {
16
- instrumentation.safeExecuteInTheMiddle(
17
- () => configFirestoreSpanCreationHook(span),
18
- (error) => {
19
- if (!error) {
20
- return;
21
- }
22
- api.diag.error(error?.message);
23
- },
24
- true
25
- );
26
- };
27
- }
9
+ function patchFirestore(firestoreSupportedVersions, wrap, unwrap) {
28
10
  const moduleFirestoreCJS = new instrumentation.InstrumentationNodeModuleDefinition(
29
11
  "@firebase/firestore",
30
12
  firestoreSupportedVersions,
31
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- (moduleExports) => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook)
14
+ (moduleExports) => wrapMethods(moduleExports, wrap, unwrap)
33
15
  );
34
16
  const files = [
35
17
  "@firebase/firestore/dist/lite/index.node.cjs.js",
@@ -42,19 +24,19 @@ function patchFirestore(tracer, firestoreSupportedVersions, wrap, unwrap, config
42
24
  new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
43
25
  file,
44
26
  firestoreSupportedVersions,
45
- (moduleExports) => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook),
27
+ (moduleExports) => wrapMethods(moduleExports, wrap, unwrap),
46
28
  (moduleExports) => unwrapMethods(moduleExports, unwrap)
47
29
  )
48
30
  );
49
31
  }
50
32
  return moduleFirestoreCJS;
51
33
  }
52
- function wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook) {
34
+ function wrapMethods(moduleExports, wrap, unwrap) {
53
35
  unwrapMethods(moduleExports, unwrap);
54
- wrap(moduleExports, "addDoc", patchAddDoc(tracer, firestoreSpanCreationHook));
55
- wrap(moduleExports, "getDocs", patchGetDocs(tracer, firestoreSpanCreationHook));
56
- wrap(moduleExports, "setDoc", patchSetDoc(tracer, firestoreSpanCreationHook));
57
- wrap(moduleExports, "deleteDoc", patchDeleteDoc(tracer, firestoreSpanCreationHook));
36
+ wrap(moduleExports, "addDoc", patchAddDoc());
37
+ wrap(moduleExports, "getDocs", patchGetDocs());
38
+ wrap(moduleExports, "setDoc", patchSetDoc());
39
+ wrap(moduleExports, "deleteDoc", patchDeleteDoc());
58
40
  return moduleExports;
59
41
  }
60
42
  function unwrapMethods(moduleExports, unwrap) {
@@ -65,71 +47,50 @@ function unwrapMethods(moduleExports, unwrap) {
65
47
  }
66
48
  return moduleExports;
67
49
  }
68
- function patchAddDoc(tracer, firestoreSpanCreationHook) {
50
+ function patchAddDoc() {
69
51
  return function addDoc(original) {
70
52
  return function(reference, data) {
71
- const span = startDBSpan(tracer, "addDoc", reference);
72
- firestoreSpanCreationHook(span);
73
- return executeContextWithSpan(span, () => {
74
- return original(reference, data);
75
- });
53
+ return startFirestoreSpan("addDoc", reference, () => original(reference, data));
76
54
  };
77
55
  };
78
56
  }
79
- function patchDeleteDoc(tracer, firestoreSpanCreationHook) {
57
+ function patchDeleteDoc() {
80
58
  return function deleteDoc(original) {
81
59
  return function(reference) {
82
- const span = startDBSpan(tracer, "deleteDoc", reference.parent || reference);
83
- firestoreSpanCreationHook(span);
84
- return executeContextWithSpan(span, () => {
85
- return original(reference);
86
- });
60
+ return startFirestoreSpan("deleteDoc", reference.parent || reference, () => original(reference));
87
61
  };
88
62
  };
89
63
  }
90
- function patchGetDocs(tracer, firestoreSpanCreationHook) {
64
+ function patchGetDocs() {
91
65
  return function getDocs(original) {
92
66
  return function(reference) {
93
- const span = startDBSpan(tracer, "getDocs", reference);
94
- firestoreSpanCreationHook(span);
95
- return executeContextWithSpan(span, () => {
96
- return original(reference);
97
- });
67
+ return startFirestoreSpan("getDocs", reference, () => original(reference));
98
68
  };
99
69
  };
100
70
  }
101
- function patchSetDoc(tracer, firestoreSpanCreationHook) {
71
+ function patchSetDoc() {
102
72
  return function setDoc(original) {
103
73
  return function(reference, data, options) {
104
- const span = startDBSpan(tracer, "setDoc", reference.parent || reference);
105
- firestoreSpanCreationHook(span);
106
- return executeContextWithSpan(span, () => {
74
+ return startFirestoreSpan("setDoc", reference.parent || reference, () => {
107
75
  return typeof options !== "undefined" ? original(reference, data, options) : original(reference, data);
108
76
  });
109
77
  };
110
78
  };
111
79
  }
112
- function executeContextWithSpan(span, callback) {
113
- return api.context.with(api.trace.setSpan(api.context.active(), span), () => {
114
- return instrumentation.safeExecuteInTheMiddle(
115
- () => {
116
- return callback();
117
- },
118
- (err) => {
119
- if (err) {
120
- span.recordException(err);
121
- }
122
- span.end();
123
- },
124
- true
125
- );
126
- });
127
- }
128
- function startDBSpan(tracer, spanName, reference) {
129
- const span = tracer.startSpan(`${spanName} ${reference.path}`, { kind: api.SpanKind.CLIENT });
130
- addAttributes(span, reference);
131
- span.setAttribute(semanticConventions.ATTR_DB_OPERATION_NAME, spanName);
132
- return span;
80
+ function startFirestoreSpan(spanName, reference, callback) {
81
+ return core.startSpan(
82
+ {
83
+ name: `${spanName} ${reference.path}`,
84
+ op: "db.query",
85
+ kind: core.SPAN_KIND.CLIENT,
86
+ attributes: {
87
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.firebase.otel.firestore",
88
+ [semanticConventions.ATTR_DB_OPERATION_NAME]: spanName,
89
+ ...buildAttributes(reference)
90
+ }
91
+ },
92
+ callback
93
+ );
133
94
  }
134
95
  function getPortAndAddress(settings) {
135
96
  let address;
@@ -164,7 +125,7 @@ function getPortAndAddress(settings) {
164
125
  port: port ? parseInt(port, 10) : void 0
165
126
  };
166
127
  }
167
- function addAttributes(span, reference) {
128
+ function buildAttributes(reference) {
168
129
  const firestoreApp = reference.firestore.app;
169
130
  const firestoreOptions = firestoreApp.options;
170
131
  const json = reference.firestore.toJSON() || {};
@@ -186,7 +147,7 @@ function addAttributes(span, reference) {
186
147
  if (port) {
187
148
  attributes[semanticConventions.ATTR_SERVER_PORT] = port;
188
149
  }
189
- span.setAttributes(attributes);
150
+ return attributes;
190
151
  }
191
152
 
192
153
  exports.getPortAndAddress = getPortAndAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"firestore.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/firestore.ts"],"sourcesContent":["import * as net from 'node:net';\nimport type { Span, Tracer } from '@opentelemetry/api';\nimport { context, diag, SpanKind, trace } from '@opentelemetry/api';\nimport { InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AddDocType,\n CollectionReference,\n DeleteDocType,\n DocumentData,\n DocumentReference,\n FirebaseApp,\n FirebaseInstrumentationConfig,\n FirebaseOptions,\n FirestoreSettings,\n FirestoreSpanCreationHook,\n GetDocsType,\n PartialWithFieldValue,\n QuerySnapshot,\n SetDocType,\n SetOptions,\n WithFieldValue,\n} from '../types';\n\n// Inline minimal types used from `shimmer` to avoid importing shimmer's types directly.\n// We only need the shape for `wrap` and `unwrap` used in this file.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ShimmerWrap = (target: any, name: string, wrapper: (...args: any[]) => any) => void;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ShimmerUnwrap = (target: any, name: string) => void;\n\n/**\n *\n * @param tracer - Opentelemetry Tracer\n * @param firestoreSupportedVersions - supported version of firebase/firestore\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation wrap function\n */\nexport function patchFirestore(\n tracer: Tracer,\n firestoreSupportedVersions: string[],\n wrap: ShimmerWrap,\n unwrap: ShimmerUnwrap,\n config: FirebaseInstrumentationConfig,\n): InstrumentationNodeModuleDefinition {\n const defaultFirestoreSpanCreationHook: FirestoreSpanCreationHook = () => {};\n\n let firestoreSpanCreationHook: FirestoreSpanCreationHook = defaultFirestoreSpanCreationHook;\n const configFirestoreSpanCreationHook = config.firestoreSpanCreationHook;\n\n if (typeof configFirestoreSpanCreationHook === 'function') {\n firestoreSpanCreationHook = (span: Span) => {\n safeExecuteInTheMiddle(\n () => configFirestoreSpanCreationHook(span),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n\n const moduleFirestoreCJS = new InstrumentationNodeModuleDefinition(\n '@firebase/firestore',\n firestoreSupportedVersions,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports: any) => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook),\n );\n const files: string[] = [\n '@firebase/firestore/dist/lite/index.node.cjs.js',\n '@firebase/firestore/dist/lite/index.node.mjs.js',\n '@firebase/firestore/dist/lite/index.rn.esm2017.js',\n '@firebase/firestore/dist/lite/index.cjs.js',\n ];\n\n for (const file of files) {\n moduleFirestoreCJS.files.push(\n new InstrumentationNodeModuleFile(\n file,\n firestoreSupportedVersions,\n moduleExports => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook),\n moduleExports => unwrapMethods(moduleExports, unwrap),\n ),\n );\n }\n\n return moduleFirestoreCJS;\n}\n\nfunction wrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n wrap: ShimmerWrap,\n unwrap: ShimmerUnwrap,\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n unwrapMethods(moduleExports, unwrap);\n\n wrap(moduleExports, 'addDoc', patchAddDoc(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'getDocs', patchGetDocs(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'setDoc', patchSetDoc(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'deleteDoc', patchDeleteDoc(tracer, firestoreSpanCreationHook));\n\n return moduleExports;\n}\n\nfunction unwrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n unwrap: ShimmerUnwrap,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n for (const method of ['addDoc', 'getDocs', 'setDoc', 'deleteDoc']) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n\nfunction patchAddDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: AddDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n) => Promise<DocumentReference<AppModelType, DbModelType>> {\n return function addDoc(original: AddDocType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n ): Promise<DocumentReference<AppModelType, DbModelType>> {\n const span = startDBSpan(tracer, 'addDoc', reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<DocumentReference<AppModelType, DbModelType>>>(span, () => {\n return original(reference, data);\n });\n };\n };\n}\n\nfunction patchDeleteDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: DeleteDocType<AppModelType, DbModelType>,\n) => (this: FirebaseInstrumentation, reference: DocumentReference<AppModelType, DbModelType>) => Promise<void> {\n return function deleteDoc(original: DeleteDocType<AppModelType, DbModelType>) {\n return function (reference: DocumentReference<AppModelType, DbModelType>): Promise<void> {\n const span = startDBSpan(tracer, 'deleteDoc', reference.parent || reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<void>>(span, () => {\n return original(reference);\n });\n };\n };\n}\n\nfunction patchGetDocs<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: GetDocsType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n) => Promise<QuerySnapshot<AppModelType, DbModelType>> {\n return function getDocs(original: GetDocsType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n ): Promise<QuerySnapshot<AppModelType, DbModelType>> {\n const span = startDBSpan(tracer, 'getDocs', reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<QuerySnapshot<AppModelType, DbModelType>>>(span, () => {\n return original(reference);\n });\n };\n };\n}\n\nfunction patchSetDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: SetDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n) => Promise<void> {\n return function setDoc(original: SetDocType<AppModelType, DbModelType>) {\n return function (\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n ): Promise<void> {\n const span = startDBSpan(tracer, 'setDoc', reference.parent || reference);\n firestoreSpanCreationHook(span);\n\n return executeContextWithSpan<Promise<void>>(span, () => {\n return typeof options !== 'undefined' ? original(reference, data, options) : original(reference, data);\n });\n };\n };\n}\n\nfunction executeContextWithSpan<T>(span: Span, callback: () => T): T {\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle(\n (): T => {\n return callback();\n },\n err => {\n if (err) {\n span.recordException(err);\n }\n span.end();\n },\n true,\n );\n });\n}\n\nfunction startDBSpan<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n spanName: string,\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n): Span {\n const span = tracer.startSpan(`${spanName} ${reference.path}`, { kind: SpanKind.CLIENT });\n addAttributes(span, reference);\n span.setAttribute(ATTR_DB_OPERATION_NAME, spanName);\n return span;\n}\n\n/**\n * Gets the server address and port attributes from the Firestore settings.\n * It's best effort to extract the address and port from the settings, especially for IPv6.\n * @param span - The span to set attributes on.\n * @param settings - The Firestore settings containing host information.\n */\nexport function getPortAndAddress(settings: FirestoreSettings): {\n address?: string;\n port?: number;\n} {\n let address: string | undefined;\n let port: string | undefined;\n\n if (typeof settings.host === 'string') {\n if (settings.host.startsWith('[')) {\n // IPv6 addresses can be enclosed in square brackets, e.g., [2001:db8::1]:8080\n if (settings.host.endsWith(']')) {\n // IPv6 with square brackets without port\n address = settings.host.replace(/^\\[|\\]$/g, '');\n } else if (settings.host.includes(']:')) {\n // IPv6 with square brackets with port\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(1, lastColonIndex).replace(/^\\[|\\]$/g, '');\n port = settings.host.slice(lastColonIndex + 1);\n }\n }\n } else {\n // IPv4 or IPv6 without square brackets\n // If it's an IPv6 address without square brackets, we assume it does not have a port.\n if (net.isIPv6(settings.host)) {\n address = settings.host;\n }\n // If it's an IPv4 address, we can extract the port if it exists.\n else {\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(0, lastColonIndex);\n port = settings.host.slice(lastColonIndex + 1);\n } else {\n address = settings.host;\n }\n }\n }\n }\n return {\n address: address,\n port: port ? parseInt(port, 10) : undefined,\n };\n}\n\nfunction addAttributes<AppModelType, DbModelType extends DocumentData>(\n span: Span,\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n): void {\n const firestoreApp: FirebaseApp = reference.firestore.app;\n const firestoreOptions: FirebaseOptions = firestoreApp.options;\n const json: { settings?: FirestoreSettings } = reference.firestore.toJSON() || {};\n const settings: FirestoreSettings = json.settings || {};\n\n const attributes: SpanAttributes = {\n [ATTR_DB_COLLECTION_NAME]: reference.path,\n [ATTR_DB_NAMESPACE]: firestoreApp.name,\n [ATTR_DB_SYSTEM_NAME]: 'firebase.firestore',\n 'firebase.firestore.type': reference.type,\n 'firebase.firestore.options.projectId': firestoreOptions.projectId,\n 'firebase.firestore.options.appId': firestoreOptions.appId,\n 'firebase.firestore.options.messagingSenderId': firestoreOptions.messagingSenderId,\n 'firebase.firestore.options.storageBucket': firestoreOptions.storageBucket,\n };\n\n const { address, port } = getPortAndAddress(settings);\n\n if (address) {\n attributes[ATTR_SERVER_ADDRESS] = address;\n }\n if (port) {\n attributes[ATTR_SERVER_PORT] = port;\n }\n\n span.setAttributes(attributes);\n}\n"],"names":["safeExecuteInTheMiddle","diag","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","isWrapped","context","trace","SpanKind","ATTR_DB_OPERATION_NAME","ATTR_DB_COLLECTION_NAME","ATTR_DB_NAMESPACE","ATTR_DB_SYSTEM_NAME","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT"],"mappings":";;;;;;;;AAgDO,SAAS,cAAA,CACd,MAAA,EACA,0BAAA,EACA,IAAA,EACA,QACA,MAAA,EACqC;AACrC,EAAA,MAAM,mCAA8D,MAAM;AAAA,EAAC,CAAA;AAE3E,EAAA,IAAI,yBAAA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K,QAAA,IAAY,EAAC;AAEtD,EAAA,MAAM,UAAA,GAA6B;AAAA,IACjC,CAACC,2CAAuB,GAAG,SAAA,CAAU,IAAA;AAAA,IACrC,CAACC,qCAAiB,GAAG,YAAA,CAAa,IAAA;AAAA,IAClC,CAACC,uCAAmB,GAAG,oBAAA;AAAA,IACvB,2BAA2B,SAAA,CAAU,IAAA;AAAA,IACrC,wCAAwC,gBAAA,CAAiB,SAAA;AAAA,IACzD,oCAAoC,gBAAA,CAAiB,KAAA;AAAA,IACrD,gDAAgD,gBAAA,CAAiB,iBAAA;AAAA,IACjE,4CAA4C,gBAAA,CAAiB;AAAA,GAC/D;AAEA,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,kBAAkB,QAAQ,CAAA;AAEpD,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,UAAA,CAAWC,uCAAmB,CAAA,GAAI,OAAA;AAAA,EACpC;AACA,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,UAAA,CAAWC,oCAAgB,CAAA,GAAI,IAAA;AAAA,EACjC;AAEA,EAAA,IAAA,CAAK,cAAc,UAAU,CAAA;AAC/B;;;;;"}
1
+ {"version":3,"file":"firestore.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/firestore.ts"],"sourcesContent":["import * as net from 'node:net';\nimport { InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_KIND, startSpan } from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AddDocType,\n CollectionReference,\n DeleteDocType,\n DocumentData,\n DocumentReference,\n FirebaseApp,\n FirebaseOptions,\n FirestoreSettings,\n GetDocsType,\n PartialWithFieldValue,\n QuerySnapshot,\n SetDocType,\n SetOptions,\n WithFieldValue,\n} from '../types';\n\n// Inline minimal types used from `shimmer` to avoid importing shimmer's types directly.\n// We only need the shape for `wrap` and `unwrap` used in this file.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ShimmerWrap = (target: any, name: string, wrapper: (...args: any[]) => any) => void;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ShimmerUnwrap = (target: any, name: string) => void;\n\n/**\n *\n * @param firestoreSupportedVersions - supported version of firebase/firestore\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation wrap function\n */\nexport function patchFirestore(\n firestoreSupportedVersions: string[],\n wrap: ShimmerWrap,\n unwrap: ShimmerUnwrap,\n): InstrumentationNodeModuleDefinition {\n const moduleFirestoreCJS = new InstrumentationNodeModuleDefinition(\n '@firebase/firestore',\n firestoreSupportedVersions,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports: any) => wrapMethods(moduleExports, wrap, unwrap),\n );\n const files: string[] = [\n '@firebase/firestore/dist/lite/index.node.cjs.js',\n '@firebase/firestore/dist/lite/index.node.mjs.js',\n '@firebase/firestore/dist/lite/index.rn.esm2017.js',\n '@firebase/firestore/dist/lite/index.cjs.js',\n ];\n\n for (const file of files) {\n moduleFirestoreCJS.files.push(\n new InstrumentationNodeModuleFile(\n file,\n firestoreSupportedVersions,\n moduleExports => wrapMethods(moduleExports, wrap, unwrap),\n moduleExports => unwrapMethods(moduleExports, unwrap),\n ),\n );\n }\n\n return moduleFirestoreCJS;\n}\n\nfunction wrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n wrap: ShimmerWrap,\n unwrap: ShimmerUnwrap,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n unwrapMethods(moduleExports, unwrap);\n\n wrap(moduleExports, 'addDoc', patchAddDoc());\n wrap(moduleExports, 'getDocs', patchGetDocs());\n wrap(moduleExports, 'setDoc', patchSetDoc());\n wrap(moduleExports, 'deleteDoc', patchDeleteDoc());\n\n return moduleExports;\n}\n\nfunction unwrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n unwrap: ShimmerUnwrap,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n for (const method of ['addDoc', 'getDocs', 'setDoc', 'deleteDoc']) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n\nfunction patchAddDoc<AppModelType, DbModelType extends DocumentData>(): (\n original: AddDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n) => Promise<DocumentReference<AppModelType, DbModelType>> {\n return function addDoc(original: AddDocType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n ): Promise<DocumentReference<AppModelType, DbModelType>> {\n return startFirestoreSpan('addDoc', reference, () => original(reference, data));\n };\n };\n}\n\nfunction patchDeleteDoc<AppModelType, DbModelType extends DocumentData>(): (\n original: DeleteDocType<AppModelType, DbModelType>,\n) => (this: FirebaseInstrumentation, reference: DocumentReference<AppModelType, DbModelType>) => Promise<void> {\n return function deleteDoc(original: DeleteDocType<AppModelType, DbModelType>) {\n return function (reference: DocumentReference<AppModelType, DbModelType>): Promise<void> {\n return startFirestoreSpan('deleteDoc', reference.parent || reference, () => original(reference));\n };\n };\n}\n\nfunction patchGetDocs<AppModelType, DbModelType extends DocumentData>(): (\n original: GetDocsType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n) => Promise<QuerySnapshot<AppModelType, DbModelType>> {\n return function getDocs(original: GetDocsType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n ): Promise<QuerySnapshot<AppModelType, DbModelType>> {\n return startFirestoreSpan('getDocs', reference, () => original(reference));\n };\n };\n}\n\nfunction patchSetDoc<AppModelType, DbModelType extends DocumentData>(): (\n original: SetDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n) => Promise<void> {\n return function setDoc(original: SetDocType<AppModelType, DbModelType>) {\n return function (\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n ): Promise<void> {\n return startFirestoreSpan('setDoc', reference.parent || reference, () => {\n return typeof options !== 'undefined' ? original(reference, data, options) : original(reference, data);\n });\n };\n };\n}\n\nfunction startFirestoreSpan<AppModelType, DbModelType extends DocumentData, T>(\n spanName: string,\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n callback: () => T,\n): T {\n return startSpan(\n {\n name: `${spanName} ${reference.path}`,\n op: 'db.query',\n kind: SPAN_KIND.CLIENT,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.firebase.otel.firestore',\n [ATTR_DB_OPERATION_NAME]: spanName,\n ...buildAttributes(reference),\n },\n },\n callback,\n );\n}\n\n/**\n * Gets the server address and port attributes from the Firestore settings.\n * It's best effort to extract the address and port from the settings, especially for IPv6.\n * @param settings - The Firestore settings containing host information.\n */\nexport function getPortAndAddress(settings: FirestoreSettings): {\n address?: string;\n port?: number;\n} {\n let address: string | undefined;\n let port: string | undefined;\n\n if (typeof settings.host === 'string') {\n if (settings.host.startsWith('[')) {\n // IPv6 addresses can be enclosed in square brackets, e.g., [2001:db8::1]:8080\n if (settings.host.endsWith(']')) {\n // IPv6 with square brackets without port\n address = settings.host.replace(/^\\[|\\]$/g, '');\n } else if (settings.host.includes(']:')) {\n // IPv6 with square brackets with port\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(1, lastColonIndex).replace(/^\\[|\\]$/g, '');\n port = settings.host.slice(lastColonIndex + 1);\n }\n }\n } else {\n // IPv4 or IPv6 without square brackets\n // If it's an IPv6 address without square brackets, we assume it does not have a port.\n if (net.isIPv6(settings.host)) {\n address = settings.host;\n }\n // If it's an IPv4 address, we can extract the port if it exists.\n else {\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(0, lastColonIndex);\n port = settings.host.slice(lastColonIndex + 1);\n } else {\n address = settings.host;\n }\n }\n }\n }\n return {\n address: address,\n port: port ? parseInt(port, 10) : undefined,\n };\n}\n\nfunction buildAttributes<AppModelType, DbModelType extends DocumentData>(\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n): SpanAttributes {\n const firestoreApp: FirebaseApp = reference.firestore.app;\n const firestoreOptions: FirebaseOptions = firestoreApp.options;\n const json: { settings?: FirestoreSettings } = reference.firestore.toJSON() || {};\n const settings: FirestoreSettings = json.settings || {};\n\n const attributes: SpanAttributes = {\n [ATTR_DB_COLLECTION_NAME]: reference.path,\n [ATTR_DB_NAMESPACE]: firestoreApp.name,\n [ATTR_DB_SYSTEM_NAME]: 'firebase.firestore',\n 'firebase.firestore.type': reference.type,\n 'firebase.firestore.options.projectId': firestoreOptions.projectId,\n 'firebase.firestore.options.appId': firestoreOptions.appId,\n 'firebase.firestore.options.messagingSenderId': firestoreOptions.messagingSenderId,\n 'firebase.firestore.options.storageBucket': firestoreOptions.storageBucket,\n };\n\n const { address, port } = getPortAndAddress(settings);\n\n if (address) {\n attributes[ATTR_SERVER_ADDRESS] = address;\n }\n if (port) {\n attributes[ATTR_SERVER_PORT] = port;\n }\n\n return attributes;\n}\n"],"names":["InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","isWrapped","startSpan","SPAN_KIND","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","ATTR_DB_OPERATION_NAME","ATTR_DB_COLLECTION_NAME","ATTR_DB_NAMESPACE","ATTR_DB_SYSTEM_NAME","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT"],"mappings":";;;;;;;;AA4CO,SAAS,cAAA,CACd,0BAAA,EACA,IAAA,EACA,MAAA,EACqC;AACrC,EAAA,MAAM,qBAAqB,IAAIA,mDAAA;AAAA,IAC7B,qBAAA;AAAA,IACA,0BAAA;AAAA;AAAA,IAEA,CAAC,aAAA,KAAuB,WAAA,CAAY,aAAA,EAAe,MAAM,MAAM;AAAA,GACjE;AACA,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,iDAAA;AAAA,IACA,iDAAA;AAAA,IACA,mDAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,kBAAA,CAAmB,KAAA,CAAM,IAAA;AAAA,MACvB,IAAIC,2DAAA;AAAA,QACF,IAAA;AAAA,QACA,0BAAA;AAAA,QACA,CAAA,aAAA,KAAiB,WAAA,CAAY,aAAA,EAAe,IAAA,EAAM,MAAM,CAAA;AAAA,QACxD,CAAA,aAAA,KAAiB,aAAA,CAAc,aAAA,EAAe,MAAM;AAAA;AACtD,KACF;AAAA,EACF;AAEA,EAAA,OAAO,kBAAA;AACT;AAEA,SAAS,WAAA,CAEP,aAAA,EACA,IAAA,EACA,MAAA,EAEK;AACL,EAAA,aAAA,CAAc,eAAe,MAAM,CAAA;AAEnC,EAAA,IAAA,CAAK,aAAA,EAAe,QAAA,EAAU,WAAA,EAAa,CAAA;AAC3C,EAAA,IAAA,CAAK,aAAA,EAAe,SAAA,EAAW,YAAA,EAAc,CAAA;AAC7C,EAAA,IAAA,CAAK,aAAA,EAAe,QAAA,EAAU,WAAA,EAA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AAY,EAAC;AAEtD,EAAA,MAAM,UAAA,GAA6B;AAAA,IACjC,CAACC,2CAAuB,GAAG,SAAA,CAAU,IAAA;AAAA,IACrC,CAACC,qCAAiB,GAAG,YAAA,CAAa,IAAA;AAAA,IAClC,CAACC,uCAAmB,GAAG,oBAAA;AAAA,IACvB,2BAA2B,SAAA,CAAU,IAAA;AAAA,IACrC,wCAAwC,gBAAA,CAAiB,SAAA;AAAA,IACzD,oCAAoC,gBAAA,CAAiB,KAAA;AAAA,IACrD,gDAAgD,gBAAA,CAAiB,iBAAA;AAAA,IACjE,4CAA4C,gBAAA,CAAiB;AAAA,GAC/D;AAEA,EAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,kBAAkB,QAAQ,CAAA;AAEpD,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,UAAA,CAAWC,uCAAmB,CAAA,GAAI,OAAA;AAAA,EACpC;AACA,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,UAAA,CAAWC,oCAAgB,CAAA,GAAI,IAAA;AAAA,EACjC;AAEA,EAAA,OAAO,UAAA;AACT;;;;;"}
@@ -1,45 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const api = require('@opentelemetry/api');
4
3
  const instrumentation = require('@opentelemetry/instrumentation');
5
4
  const InstrumentationNodeModuleFile = require('../../../InstrumentationNodeModuleFile.js');
5
+ const core = require('@sentry/core');
6
6
 
7
- function patchFunctions(tracer, functionsSupportedVersions, wrap, unwrap, config) {
8
- let requestHook = () => {
9
- };
10
- let responseHook = () => {
11
- };
12
- const errorHook = config.functions?.errorHook;
13
- const configRequestHook = config.functions?.requestHook;
14
- const configResponseHook = config.functions?.responseHook;
15
- if (typeof configResponseHook === "function") {
16
- responseHook = (span, err) => {
17
- instrumentation.safeExecuteInTheMiddle(
18
- () => configResponseHook(span, err),
19
- (error) => {
20
- if (!error) {
21
- return;
22
- }
23
- api.diag.error(error?.message);
24
- },
25
- true
26
- );
27
- };
28
- }
29
- if (typeof configRequestHook === "function") {
30
- requestHook = (span) => {
31
- instrumentation.safeExecuteInTheMiddle(
32
- () => configRequestHook(span),
33
- (error) => {
34
- if (!error) {
35
- return;
36
- }
37
- api.diag.error(error?.message);
38
- },
39
- true
40
- );
41
- };
42
- }
7
+ function patchFunctions(functionsSupportedVersions, wrap, unwrap) {
43
8
  const moduleFunctionsCJS = new instrumentation.InstrumentationNodeModuleDefinition("firebase-functions", functionsSupportedVersions);
44
9
  const modulesToInstrument = [
45
10
  { name: "firebase-functions/lib/v2/providers/https.js", triggerType: "function" },
@@ -52,21 +17,14 @@ function patchFunctions(tracer, functionsSupportedVersions, wrap, unwrap, config
52
17
  new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
53
18
  name,
54
19
  functionsSupportedVersions,
55
- (moduleExports) => wrapCommonFunctions(
56
- moduleExports,
57
- wrap,
58
- unwrap,
59
- tracer,
60
- { requestHook, responseHook, errorHook },
61
- triggerType
62
- ),
20
+ (moduleExports) => wrapCommonFunctions(moduleExports, wrap, unwrap, triggerType),
63
21
  (moduleExports) => unwrapCommonFunctions(moduleExports, unwrap)
64
22
  )
65
23
  );
66
24
  });
67
25
  return moduleFunctionsCJS;
68
26
  }
69
- function patchV2Functions(tracer, functionsConfig, triggerType) {
27
+ function patchV2Functions(triggerType) {
70
28
  return function v2FunctionsWrapper(original) {
71
29
  return function(...args) {
72
30
  const handler = typeof args[0] === "function" ? args[0] : args[1];
@@ -76,10 +34,8 @@ function patchV2Functions(tracer, functionsConfig, triggerType) {
76
34
  }
77
35
  const wrappedHandler = async function(...handlerArgs) {
78
36
  const functionName = process.env.FUNCTION_TARGET || process.env.K_SERVICE || "unknown";
79
- const span = tracer.startSpan(`firebase.function.${triggerType}`, {
80
- kind: api.SpanKind.SERVER
81
- });
82
37
  const attributes = {
38
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.firebase.otel.functions",
83
39
  "faas.name": functionName,
84
40
  "faas.trigger": triggerType,
85
41
  "faas.provider": "firebase"
@@ -90,27 +46,32 @@ function patchV2Functions(tracer, functionsConfig, triggerType) {
90
46
  if (process.env.EVENTARC_CLOUD_EVENT_SOURCE) {
91
47
  attributes["cloud.event_source"] = process.env.EVENTARC_CLOUD_EVENT_SOURCE;
92
48
  }
93
- span.setAttributes(attributes);
94
- functionsConfig?.requestHook?.(span);
95
- return api.context.with(api.trace.setSpan(api.context.active(), span), async () => {
96
- let error;
97
- let result;
98
- try {
99
- result = await handler.apply(this, handlerArgs);
100
- } catch (e) {
101
- error = e;
102
- }
103
- functionsConfig?.responseHook?.(span, error);
104
- if (error) {
105
- span.recordException(error);
106
- }
107
- span.end();
108
- if (error) {
109
- await functionsConfig?.errorHook?.(span, error);
110
- throw error;
49
+ return core.startSpanManual(
50
+ {
51
+ name: `firebase.function.${triggerType}`,
52
+ op: "http.request",
53
+ kind: core.SPAN_KIND.SERVER,
54
+ attributes
55
+ },
56
+ async (span) => {
57
+ try {
58
+ const result = await handler.apply(this, handlerArgs);
59
+ span.end();
60
+ return result;
61
+ } catch (error) {
62
+ span.setStatus({ code: core.SPAN_STATUS_ERROR });
63
+ core.captureException(error, {
64
+ mechanism: {
65
+ type: "auto.firebase.otel.functions",
66
+ handled: false
67
+ }
68
+ });
69
+ span.end();
70
+ await core.flush(2e3);
71
+ throw error;
72
+ }
111
73
  }
112
- return result;
113
- });
74
+ );
114
75
  };
115
76
  if (documentOrOptions) {
116
77
  return original.call(this, documentOrOptions, wrappedHandler);
@@ -120,51 +81,31 @@ function patchV2Functions(tracer, functionsConfig, triggerType) {
120
81
  };
121
82
  };
122
83
  }
123
- function wrapCommonFunctions(moduleExports, wrap, unwrap, tracer, functionsConfig, triggerType) {
84
+ function wrapCommonFunctions(moduleExports, wrap, unwrap, triggerType) {
124
85
  unwrapCommonFunctions(moduleExports, unwrap);
125
86
  switch (triggerType) {
126
87
  case "function":
127
- wrap(moduleExports, "onRequest", patchV2Functions(tracer, functionsConfig, "http.request"));
128
- wrap(moduleExports, "onCall", patchV2Functions(tracer, functionsConfig, "http.call"));
88
+ wrap(moduleExports, "onRequest", patchV2Functions("http.request"));
89
+ wrap(moduleExports, "onCall", patchV2Functions("http.call"));
129
90
  break;
130
91
  case "firestore":
131
- wrap(moduleExports, "onDocumentCreated", patchV2Functions(tracer, functionsConfig, "firestore.document.created"));
132
- wrap(moduleExports, "onDocumentUpdated", patchV2Functions(tracer, functionsConfig, "firestore.document.updated"));
133
- wrap(moduleExports, "onDocumentDeleted", patchV2Functions(tracer, functionsConfig, "firestore.document.deleted"));
134
- wrap(moduleExports, "onDocumentWritten", patchV2Functions(tracer, functionsConfig, "firestore.document.written"));
135
- wrap(
136
- moduleExports,
137
- "onDocumentCreatedWithAuthContext",
138
- patchV2Functions(tracer, functionsConfig, "firestore.document.created")
139
- );
140
- wrap(
141
- moduleExports,
142
- "onDocumentUpdatedWithAuthContext",
143
- patchV2Functions(tracer, functionsConfig, "firestore.document.updated")
144
- );
145
- wrap(
146
- moduleExports,
147
- "onDocumentDeletedWithAuthContext",
148
- patchV2Functions(tracer, functionsConfig, "firestore.document.deleted")
149
- );
150
- wrap(
151
- moduleExports,
152
- "onDocumentWrittenWithAuthContext",
153
- patchV2Functions(tracer, functionsConfig, "firestore.document.written")
154
- );
92
+ wrap(moduleExports, "onDocumentCreated", patchV2Functions("firestore.document.created"));
93
+ wrap(moduleExports, "onDocumentUpdated", patchV2Functions("firestore.document.updated"));
94
+ wrap(moduleExports, "onDocumentDeleted", patchV2Functions("firestore.document.deleted"));
95
+ wrap(moduleExports, "onDocumentWritten", patchV2Functions("firestore.document.written"));
96
+ wrap(moduleExports, "onDocumentCreatedWithAuthContext", patchV2Functions("firestore.document.created"));
97
+ wrap(moduleExports, "onDocumentUpdatedWithAuthContext", patchV2Functions("firestore.document.updated"));
98
+ wrap(moduleExports, "onDocumentDeletedWithAuthContext", patchV2Functions("firestore.document.deleted"));
99
+ wrap(moduleExports, "onDocumentWrittenWithAuthContext", patchV2Functions("firestore.document.written"));
155
100
  break;
156
101
  case "scheduler":
157
- wrap(moduleExports, "onSchedule", patchV2Functions(tracer, functionsConfig, "scheduler.scheduled"));
102
+ wrap(moduleExports, "onSchedule", patchV2Functions("scheduler.scheduled"));
158
103
  break;
159
104
  case "storage":
160
- wrap(moduleExports, "onObjectFinalized", patchV2Functions(tracer, functionsConfig, "storage.object.finalized"));
161
- wrap(moduleExports, "onObjectArchived", patchV2Functions(tracer, functionsConfig, "storage.object.archived"));
162
- wrap(moduleExports, "onObjectDeleted", patchV2Functions(tracer, functionsConfig, "storage.object.deleted"));
163
- wrap(
164
- moduleExports,
165
- "onObjectMetadataUpdated",
166
- patchV2Functions(tracer, functionsConfig, "storage.object.metadataUpdated")
167
- );
105
+ wrap(moduleExports, "onObjectFinalized", patchV2Functions("storage.object.finalized"));
106
+ wrap(moduleExports, "onObjectArchived", patchV2Functions("storage.object.archived"));
107
+ wrap(moduleExports, "onObjectDeleted", patchV2Functions("storage.object.deleted"));
108
+ wrap(moduleExports, "onObjectMetadataUpdated", patchV2Functions("storage.object.metadataUpdated"));
168
109
  break;
169
110
  }
170
111
  return moduleExports;
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/functions.ts"],"sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport { context, diag, SpanKind, trace } from '@opentelemetry/api';\nimport type { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';\nimport type { SpanAttributes } from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AvailableFirebaseFunctions,\n FirebaseFunctions,\n FirebaseInstrumentationConfig,\n OverloadedParameters,\n RequestHook,\n ResponseHook,\n} from '../types';\n\n/**\n * Patches Firebase Functions v2 to add OpenTelemetry instrumentation\n * @param tracer - Opentelemetry Tracer\n * @param functionsSupportedVersions - supported versions of firebase-functions\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation unwrap function\n * @param config - Firebase instrumentation config\n */\nexport function patchFunctions(\n tracer: Tracer,\n functionsSupportedVersions: string[],\n wrap: InstrumentationBase['_wrap'],\n unwrap: InstrumentationBase['_unwrap'],\n config: FirebaseInstrumentationConfig,\n): InstrumentationNodeModuleDefinition {\n let requestHook: RequestHook = () => {};\n let responseHook: ResponseHook = () => {};\n const errorHook = config.functions?.errorHook;\n const configRequestHook = config.functions?.requestHook;\n const configResponseHook = config.functions?.responseHook;\n\n if (typeof configResponseHook === 'function') {\n responseHook = (span: Span, err: unknown) => {\n safeExecuteInTheMiddle(\n () => configResponseHook(span, err),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n if (typeof configRequestHook === 'function') {\n requestHook = (span: Span) => {\n safeExecuteInTheMiddle(\n () => configRequestHook(span),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n\n const moduleFunctionsCJS = new InstrumentationNodeModuleDefinition('firebase-functions', functionsSupportedVersions);\n const modulesToInstrument = [\n { name: 'firebase-functions/lib/v2/providers/https.js', triggerType: 'function' },\n { name: 'firebase-functions/lib/v2/providers/firestore.js', triggerType: 'firestore' },\n { name: 'firebase-functions/lib/v2/providers/scheduler.js', triggerType: 'scheduler' },\n { name: 'firebase-functions/lib/v2/storage.js', triggerType: 'storage' },\n ] as const;\n\n modulesToInstrument.forEach(({ name, triggerType }) => {\n moduleFunctionsCJS.files.push(\n new InstrumentationNodeModuleFile(\n name,\n functionsSupportedVersions,\n moduleExports =>\n wrapCommonFunctions(\n moduleExports,\n wrap,\n unwrap,\n tracer,\n { requestHook, responseHook, errorHook },\n triggerType,\n ),\n moduleExports => unwrapCommonFunctions(moduleExports, unwrap),\n ),\n );\n });\n\n return moduleFunctionsCJS;\n}\n\n/**\n * Patches Cloud Functions for Firebase (v2) to add OpenTelemetry instrumentation\n *\n * @param tracer - Opentelemetry Tracer\n * @param functionsConfig - Firebase instrumentation config\n * @param triggerType - Type of trigger\n * @returns A function that patches the function\n */\nexport function patchV2Functions<T extends FirebaseFunctions = FirebaseFunctions>(\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: string,\n): (original: T) => (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function v2FunctionsWrapper(original: T): (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function (this: FirebaseInstrumentation, ...args: OverloadedParameters<T>): ReturnType<T> {\n const handler = typeof args[0] === 'function' ? args[0] : args[1];\n const documentOrOptions = typeof args[0] === 'function' ? undefined : args[0];\n\n if (!handler) {\n return original.call(this, ...args);\n }\n\n const wrappedHandler = async function (this: unknown, ...handlerArgs: unknown[]): Promise<unknown> {\n const functionName = process.env.FUNCTION_TARGET || process.env.K_SERVICE || 'unknown';\n const span = tracer.startSpan(`firebase.function.${triggerType}`, {\n kind: SpanKind.SERVER,\n });\n\n const attributes: SpanAttributes = {\n 'faas.name': functionName,\n 'faas.trigger': triggerType,\n 'faas.provider': 'firebase',\n };\n\n if (process.env.GCLOUD_PROJECT) {\n attributes['cloud.project_id'] = process.env.GCLOUD_PROJECT;\n }\n\n if (process.env.EVENTARC_CLOUD_EVENT_SOURCE) {\n attributes['cloud.event_source'] = process.env.EVENTARC_CLOUD_EVENT_SOURCE;\n }\n\n span.setAttributes(attributes);\n functionsConfig?.requestHook?.(span);\n\n // Can be changed to safeExecuteInTheMiddleAsync once following is merged and released\n // https://github.com/open-telemetry/opentelemetry-js/pull/6032\n return context.with(trace.setSpan(context.active(), span), async () => {\n let error: Error | undefined;\n let result: T | undefined;\n\n try {\n result = await handler.apply(this, handlerArgs);\n } catch (e) {\n error = e as Error;\n }\n\n functionsConfig?.responseHook?.(span, error);\n\n if (error) {\n span.recordException(error);\n }\n\n span.end();\n\n if (error) {\n await functionsConfig?.errorHook?.(span, error);\n throw error;\n }\n\n return result;\n });\n };\n\n if (documentOrOptions) {\n return original.call(this, documentOrOptions, wrappedHandler);\n } else {\n return original.call(this, wrappedHandler);\n }\n };\n };\n}\n\nfunction wrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n wrap: InstrumentationBase<FirebaseInstrumentationConfig>['_wrap'],\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: 'function' | 'firestore' | 'scheduler' | 'storage',\n): AvailableFirebaseFunctions {\n unwrapCommonFunctions(moduleExports, unwrap);\n\n switch (triggerType) {\n case 'function':\n wrap(moduleExports, 'onRequest', patchV2Functions(tracer, functionsConfig, 'http.request'));\n wrap(moduleExports, 'onCall', patchV2Functions(tracer, functionsConfig, 'http.call'));\n break;\n\n case 'firestore':\n wrap(moduleExports, 'onDocumentCreated', patchV2Functions(tracer, functionsConfig, 'firestore.document.created'));\n wrap(moduleExports, 'onDocumentUpdated', patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'));\n wrap(moduleExports, 'onDocumentDeleted', patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'));\n wrap(moduleExports, 'onDocumentWritten', patchV2Functions(tracer, functionsConfig, 'firestore.document.written'));\n wrap(\n moduleExports,\n 'onDocumentCreatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.created'),\n );\n wrap(\n moduleExports,\n 'onDocumentUpdatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentDeletedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentWrittenWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.written'),\n );\n break;\n\n case 'scheduler':\n wrap(moduleExports, 'onSchedule', patchV2Functions(tracer, functionsConfig, 'scheduler.scheduled'));\n break;\n\n case 'storage':\n wrap(moduleExports, 'onObjectFinalized', patchV2Functions(tracer, functionsConfig, 'storage.object.finalized'));\n wrap(moduleExports, 'onObjectArchived', patchV2Functions(tracer, functionsConfig, 'storage.object.archived'));\n wrap(moduleExports, 'onObjectDeleted', patchV2Functions(tracer, functionsConfig, 'storage.object.deleted'));\n wrap(\n moduleExports,\n 'onObjectMetadataUpdated',\n patchV2Functions(tracer, functionsConfig, 'storage.object.metadataUpdated'),\n );\n break;\n }\n\n return moduleExports;\n}\n\nfunction unwrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n): AvailableFirebaseFunctions {\n const methods: (keyof AvailableFirebaseFunctions)[] = [\n 'onSchedule',\n 'onRequest',\n 'onCall',\n 'onObjectFinalized',\n 'onObjectArchived',\n 'onObjectDeleted',\n 'onObjectMetadataUpdated',\n 'onDocumentCreated',\n 'onDocumentUpdated',\n 'onDocumentDeleted',\n 'onDocumentWritten',\n 'onDocumentCreatedWithAuthContext',\n 'onDocumentUpdatedWithAuthContext',\n 'onDocumentDeletedWithAuthContext',\n 'onDocumentWrittenWithAuthContext',\n ];\n\n for (const method of methods) {\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n"],"names":["safeExecuteInTheMiddle","diag","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","SpanKind","context","trace","isWrapped"],"mappings":";;;;;;AAwBO,SAAS,cAAA,CACd,MAAA,EACA,0BAAA,EACA,IAAA,EACA,QACA,MAAA,EACqC;AACrC,EAAA,IAAI,cAA2B,MAAM;AAAA,EAAC,CAAA;AACtC,EAAA,IAAI,eAA6B,MAAM;AAAA,EAAC,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,OAAO,SAAA,EAAW,SAAA;AACpC,EAAA,MAAM,iBAAA,GAAoB,OAAO,SAAA,EAAW,WAA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A;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,IAAIE,yBAAA,CAAU,aAAA,CAAc,MAAM,CAAC,CAAA,EAAG;AACpC,MAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAAA,IAC9B;AAAA,EACF;AACA,EAAA,OAAO,aAAA;AACT;;;;;"}
1
+ {"version":3,"file":"functions.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/functions.ts"],"sourcesContent":["import type { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';\nimport type { SpanAttributes } from '@sentry/core';\nimport {\n captureException,\n flush,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startSpanManual,\n} from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type { AvailableFirebaseFunctions, FirebaseFunctions, OverloadedParameters } from '../types';\n\n/**\n * Patches Firebase Functions v2 to add OpenTelemetry instrumentation\n * @param functionsSupportedVersions - supported versions of firebase-functions\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation unwrap function\n */\nexport function patchFunctions(\n functionsSupportedVersions: string[],\n wrap: InstrumentationBase['_wrap'],\n unwrap: InstrumentationBase['_unwrap'],\n): InstrumentationNodeModuleDefinition {\n const moduleFunctionsCJS = new InstrumentationNodeModuleDefinition('firebase-functions', functionsSupportedVersions);\n const modulesToInstrument = [\n { name: 'firebase-functions/lib/v2/providers/https.js', triggerType: 'function' },\n { name: 'firebase-functions/lib/v2/providers/firestore.js', triggerType: 'firestore' },\n { name: 'firebase-functions/lib/v2/providers/scheduler.js', triggerType: 'scheduler' },\n { name: 'firebase-functions/lib/v2/storage.js', triggerType: 'storage' },\n ] as const;\n\n modulesToInstrument.forEach(({ name, triggerType }) => {\n moduleFunctionsCJS.files.push(\n new InstrumentationNodeModuleFile(\n name,\n functionsSupportedVersions,\n moduleExports => wrapCommonFunctions(moduleExports, wrap, unwrap, triggerType),\n moduleExports => unwrapCommonFunctions(moduleExports, unwrap),\n ),\n );\n });\n\n return moduleFunctionsCJS;\n}\n\n/**\n * Patches Cloud Functions for Firebase (v2) to add OpenTelemetry instrumentation\n *\n * @param triggerType - Type of trigger\n * @returns A function that patches the function\n */\nexport function patchV2Functions<T extends FirebaseFunctions = FirebaseFunctions>(\n triggerType: string,\n): (original: T) => (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function v2FunctionsWrapper(original: T): (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function (this: FirebaseInstrumentation, ...args: OverloadedParameters<T>): ReturnType<T> {\n const handler = typeof args[0] === 'function' ? args[0] : args[1];\n const documentOrOptions = typeof args[0] === 'function' ? undefined : args[0];\n\n if (!handler) {\n return original.call(this, ...args);\n }\n\n const wrappedHandler = async function (this: unknown, ...handlerArgs: unknown[]): Promise<unknown> {\n const functionName = process.env.FUNCTION_TARGET || process.env.K_SERVICE || 'unknown';\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.firebase.otel.functions',\n 'faas.name': functionName,\n 'faas.trigger': triggerType,\n 'faas.provider': 'firebase',\n };\n\n if (process.env.GCLOUD_PROJECT) {\n attributes['cloud.project_id'] = process.env.GCLOUD_PROJECT;\n }\n\n if (process.env.EVENTARC_CLOUD_EVENT_SOURCE) {\n attributes['cloud.event_source'] = process.env.EVENTARC_CLOUD_EVENT_SOURCE;\n }\n\n // `startSpanManual` to keep the span active but while still allowing us to end it before flushing on error.\n return startSpanManual(\n {\n name: `firebase.function.${triggerType}`,\n op: 'http.request',\n kind: SPAN_KIND.SERVER,\n attributes,\n },\n async span => {\n try {\n const result = await handler.apply(this, handlerArgs);\n span.end();\n return result;\n } catch (error) {\n span.setStatus({ code: SPAN_STATUS_ERROR });\n captureException(error, {\n mechanism: {\n type: 'auto.firebase.otel.functions',\n handled: false,\n },\n });\n span.end();\n await flush(2000);\n throw error;\n }\n },\n );\n };\n\n if (documentOrOptions) {\n return original.call(this, documentOrOptions, wrappedHandler);\n } else {\n return original.call(this, wrappedHandler);\n }\n };\n };\n}\n\nfunction wrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n wrap: InstrumentationBase['_wrap'],\n unwrap: InstrumentationBase['_unwrap'],\n triggerType: 'function' | 'firestore' | 'scheduler' | 'storage',\n): AvailableFirebaseFunctions {\n unwrapCommonFunctions(moduleExports, unwrap);\n\n switch (triggerType) {\n case 'function':\n wrap(moduleExports, 'onRequest', patchV2Functions('http.request'));\n wrap(moduleExports, 'onCall', patchV2Functions('http.call'));\n break;\n\n case 'firestore':\n wrap(moduleExports, 'onDocumentCreated', patchV2Functions('firestore.document.created'));\n wrap(moduleExports, 'onDocumentUpdated', patchV2Functions('firestore.document.updated'));\n wrap(moduleExports, 'onDocumentDeleted', patchV2Functions('firestore.document.deleted'));\n wrap(moduleExports, 'onDocumentWritten', patchV2Functions('firestore.document.written'));\n wrap(moduleExports, 'onDocumentCreatedWithAuthContext', patchV2Functions('firestore.document.created'));\n wrap(moduleExports, 'onDocumentUpdatedWithAuthContext', patchV2Functions('firestore.document.updated'));\n wrap(moduleExports, 'onDocumentDeletedWithAuthContext', patchV2Functions('firestore.document.deleted'));\n wrap(moduleExports, 'onDocumentWrittenWithAuthContext', patchV2Functions('firestore.document.written'));\n break;\n\n case 'scheduler':\n wrap(moduleExports, 'onSchedule', patchV2Functions('scheduler.scheduled'));\n break;\n\n case 'storage':\n wrap(moduleExports, 'onObjectFinalized', patchV2Functions('storage.object.finalized'));\n wrap(moduleExports, 'onObjectArchived', patchV2Functions('storage.object.archived'));\n wrap(moduleExports, 'onObjectDeleted', patchV2Functions('storage.object.deleted'));\n wrap(moduleExports, 'onObjectMetadataUpdated', patchV2Functions('storage.object.metadataUpdated'));\n break;\n }\n\n return moduleExports;\n}\n\nfunction unwrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n unwrap: InstrumentationBase['_unwrap'],\n): AvailableFirebaseFunctions {\n const methods: (keyof AvailableFirebaseFunctions)[] = [\n 'onSchedule',\n 'onRequest',\n 'onCall',\n 'onObjectFinalized',\n 'onObjectArchived',\n 'onObjectDeleted',\n 'onObjectMetadataUpdated',\n 'onDocumentCreated',\n 'onDocumentUpdated',\n 'onDocumentDeleted',\n 'onDocumentWritten',\n 'onDocumentCreatedWithAuthContext',\n 'onDocumentUpdatedWithAuthContext',\n 'onDocumentDeletedWithAuthContext',\n 'onDocumentWrittenWithAuthContext',\n ];\n\n for (const method of methods) {\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n"],"names":["InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpanManual","SPAN_KIND","SPAN_STATUS_ERROR","captureException","flush","isWrapped"],"mappings":";;;;;;AAqBO,SAAS,cAAA,CACd,0BAAA,EACA,IAAA,EACA,MAAA,EACqC;AACrC,EAAA,MAAM,kBAAA,GAAqB,IAAIA,mDAAA,CAAoC,oBAAA,EAAsB,0BAA0B,CAAA;AACnH,EAAA,MAAM,mBAAA,GAAsB;AAAA,IAC1B,EAAE,IAAA,EAAM,8CAAA,EAAgD,WAAA,EAAa,UAAA,EAAW;AAAA,IAChF,EAAE,IAAA,EAAM,kDAAA,EAAoD,WAAA,EAAa,WAAA,EAAY;AAAA,IACrF,EAAE,IAAA,EAAM,kDAAA,EAAoD,WAAA,EAAa,WAAA,EAAY;AAAA,IACrF,EAAE,IAAA,EAAM,sCAAA,EAAwC,WAAA,EAAa,SAAA;AAAU,GACzE;AAEA,EAAA,mB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AA,EAAe,mBAAA,EAAqB,gBAAA,CAAiB,0BAA0B,CAAC,CAAA;AACrF,MAAA,IAAA,CAAK,aAAA,EAAe,kBAAA,EAAoB,gBAAA,CAAiB,yBAAyB,CAAC,CAAA;AACnF,MAAA,IAAA,CAAK,aAAA,EAAe,iBAAA,EAAmB,gBAAA,CAAiB,wBAAwB,CAAC,CAAA;AACjF,MAAA,IAAA,CAAK,aAAA,EAAe,yBAAA,EAA2B,gBAAA,CAAiB,gCAAgC,CAAC,CAAA;AACjG,MAAA;AAAA;AAGJ,EAAA,OAAO,aAAA;AACT;AAEA,SAAS,qBAAA,CACP,eACA,MAAA,EAC4B;AAC5B,EAAA,MAAM,OAAA,GAAgD;AAAA,IACpD,YAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA;AAAA,IACA,mBAAA;AAAA,IACA,kBAAA;AAAA,IACA,iBAAA;AAAA,IACA,yBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,IAAIC,yBAAA,CAAU,aAAA,CAAc,MAAM,CAAC,CAAA,EAAG;AACpC,MAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAAA,IAC9B;AAAA,EACF;AACA,EAAA,OAAO,aAAA;AACT;;;;;"}
@@ -40,7 +40,7 @@ function startConsumerSpan({ topic, message, operationType, links, attributes })
40
40
  const operationName = operationType === semconv.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? "poll" : operationType;
41
41
  return core.startInactiveSpan({
42
42
  name: `${operationName} ${topic}`,
43
- kind: operationType === semconv.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? api.SpanKind.CLIENT : api.SpanKind.CONSUMER,
43
+ kind: operationType === semconv.MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? core.SPAN_KIND.CLIENT : core.SPAN_KIND.CONSUMER,
44
44
  links,
45
45
  attributes: {
46
46
  ...attributes,
@@ -60,7 +60,7 @@ function startConsumerSpan({ topic, message, operationType, links, attributes })
60
60
  function startProducerSpan(topic, message) {
61
61
  const span = core.startInactiveSpan({
62
62
  name: `send ${topic}`,
63
- kind: api.SpanKind.PRODUCER,
63
+ kind: core.SPAN_KIND.PRODUCER,
64
64
  attributes: {
65
65
  [semconv.ATTR_MESSAGING_SYSTEM]: semconv.MESSAGING_SYSTEM_VALUE_KAFKA,
66
66
  [semconv.ATTR_MESSAGING_DESTINATION_NAME]: topic,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/kafka/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-kafkajs\n * - Upstream version: @opentelemetry/instrumentation-kafkajs@0.27.0\n * - Span creation extracted here and migrated to the @sentry/core API; origin folded into span creation\n */\n\nimport { SpanKind, TraceFlags } from '@opentelemetry/api';\nimport type { Span, SpanAttributes, SpanLink } from '@sentry/core';\nimport {\n getTraceData,\n propagationContextFromHeaders,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { KafkaMessage, Message } from './kafkajs-types';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_MESSAGING_DESTINATION_NAME,\n ATTR_MESSAGING_DESTINATION_PARTITION_ID,\n ATTR_MESSAGING_KAFKA_MESSAGE_KEY,\n ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE,\n ATTR_MESSAGING_KAFKA_OFFSET,\n ATTR_MESSAGING_OPERATION_NAME,\n ATTR_MESSAGING_OPERATION_TYPE,\n ATTR_MESSAGING_SYSTEM,\n ERROR_TYPE_VALUE_OTHER,\n MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n MESSAGING_OPERATION_TYPE_VALUE_SEND,\n MESSAGING_SYSTEM_VALUE_KAFKA,\n} from './semconv';\n\nconst PRODUCER_ORIGIN = 'auto.kafkajs.otel.producer';\nconst CONSUMER_ORIGIN = 'auto.kafkajs.otel.consumer';\n\nexport interface ConsumerSpanOptions {\n topic: string;\n message: KafkaMessage | undefined;\n operationType: string;\n attributes: SpanAttributes;\n links?: SpanLink[];\n}\n\n/**\n * Reads a header value off a kafkajs message as a string. kafkajs delivers headers as `Buffer`s (or\n * arrays of them), so we normalize to a string before handing them to Sentry's trace helpers.\n */\nexport function getHeaderAsString(headers: KafkaMessage['headers'], key: string): string | undefined {\n const value = headers?.[key];\n if (value == null) {\n return undefined;\n }\n return Array.isArray(value) ? value[0]?.toString() : value.toString();\n}\n\n/**\n * Builds a span link to the producer span carried in the message headers, mirroring the upstream\n * behavior of linking each batch-processed message to its originating producer span.\n */\nexport function getLinksFromHeaders(headers: KafkaMessage['headers']): SpanLink[] | undefined {\n const sentryTrace = getHeaderAsString(headers, 'sentry-trace');\n if (!sentryTrace) {\n return undefined;\n }\n\n const { traceId, parentSpanId, sampled } = propagationContextFromHeaders(\n sentryTrace,\n getHeaderAsString(headers, 'baggage'),\n );\n if (!parentSpanId) {\n return undefined;\n }\n\n return [\n {\n context: {\n traceId,\n spanId: parentSpanId,\n isRemote: true,\n traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,\n },\n },\n ];\n}\n\n/** Starts an inactive consumer (process/receive) span carrying the kafkajs messaging attributes. */\nexport function startConsumerSpan({ topic, message, operationType, links, attributes }: ConsumerSpanOptions): Span {\n const operationName =\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? 'poll' // for batch processing spans\n : operationType; // for individual message processing spans\n\n return startInactiveSpan({\n name: `${operationName} ${topic}`,\n kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SpanKind.CLIENT : SpanKind.CONSUMER,\n links,\n attributes: {\n ...attributes,\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_OPERATION_TYPE]: operationType,\n [ATTR_MESSAGING_OPERATION_NAME]: operationName,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,\n // Mirror the upstream behavior of only tagging per-message processing spans (not the batch\n // receiving span, which carries no message) with the auto origin.\n ...(message ? { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: CONSUMER_ORIGIN } : {}),\n },\n });\n}\n\n/** Starts an inactive producer span and propagates its trace into the message headers. */\nexport function startProducerSpan(topic: string, message: Message): Span {\n const span = startInactiveSpan({\n name: `send ${topic}`,\n kind: SpanKind.PRODUCER,\n attributes: {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]:\n message.partition !== undefined ? String(message.partition) : undefined,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRODUCER_ORIGIN,\n },\n });\n\n // Propagate the producer span's trace to consumers via the message headers.\n message.headers = message.headers ?? {};\n const traceData = getTraceData({ span });\n if (traceData['sentry-trace']) {\n message.headers['sentry-trace'] = traceData['sentry-trace'];\n }\n if (traceData.baggage) {\n message.headers['baggage'] = traceData.baggage;\n }\n\n return span;\n}\n\n/**\n * Resolves once `sendPromise` settles, ending all `spans` and, on failure, marking them with the\n * error status and `error.type` before re-throwing.\n */\nexport function endSpansOnPromise<T>(spans: Span[], sendPromise: Promise<T>): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string | undefined;\n let errorType: string = ERROR_TYPE_VALUE_OTHER;\n if (typeof reason === 'string' || reason === undefined) {\n errorMessage = reason;\n } else if (typeof reason === 'object' && Object.prototype.hasOwnProperty.call(reason, 'message')) {\n errorMessage = reason.message;\n errorType = reason.constructor.name;\n }\n\n spans.forEach(span => {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: errorMessage,\n });\n });\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n}\n"],"names":["propagationContextFromHeaders","TraceFlags","MESSAGING_OPERATION_TYPE_VALUE_RECEIVE","startInactiveSpan","SpanKind","ATTR_MESSAGING_SYSTEM","MESSAGING_SYSTEM_VALUE_KAFKA","ATTR_MESSAGING_DESTINATION_NAME","ATTR_MESSAGING_OPERATION_TYPE","ATTR_MESSAGING_OPERATION_NAME","ATTR_MESSAGING_KAFKA_MESSAGE_KEY","ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE","ATTR_MESSAGING_KAFKA_OFFSET","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","ATTR_MESSAGING_DESTINATION_PARTITION_ID","MESSAGING_OPERATION_TYPE_VALUE_SEND","getTraceData","ERROR_TYPE_VALUE_OTHER","ATTR_ERROR_TYPE","SPAN_STATUS_ERROR"],"mappings":";;;;;;AAoCA,MAAM,eAAA,GAAkB,4BAAA;AACxB,MAAM,eAAA,GAAkB,4BAAA;AAcjB,SAAS,iBAAA,CAAkB,SAAkC,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,QACN,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAC,CAAA;AAED,IAAA,MAAM,MAAA;AAAA,EACR,CAAC,CAAA,CACA,OAAA,CAAQ,MAAM;AACb,IAAA,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAA,KAAQ,IAAA,CAAK,GAAA,EAAK,CAAA;AAAA,EAClC,CAAC,CAAA;AACL;;;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../../../src/integrations/tracing/kafka/vendored/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n * SPDX-License-Identifier: Apache-2.0\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-kafkajs\n * - Upstream version: @opentelemetry/instrumentation-kafkajs@0.27.0\n * - Span creation extracted here and migrated to the @sentry/core API; origin folded into span creation\n */\n\nimport { TraceFlags } from '@opentelemetry/api';\nimport type { Span, SpanAttributes, SpanLink } from '@sentry/core';\nimport {\n getTraceData,\n propagationContextFromHeaders,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_KIND,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n} from '@sentry/core';\nimport type { KafkaMessage, Message } from './kafkajs-types';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_MESSAGING_DESTINATION_NAME,\n ATTR_MESSAGING_DESTINATION_PARTITION_ID,\n ATTR_MESSAGING_KAFKA_MESSAGE_KEY,\n ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE,\n ATTR_MESSAGING_KAFKA_OFFSET,\n ATTR_MESSAGING_OPERATION_NAME,\n ATTR_MESSAGING_OPERATION_TYPE,\n ATTR_MESSAGING_SYSTEM,\n ERROR_TYPE_VALUE_OTHER,\n MESSAGING_OPERATION_TYPE_VALUE_RECEIVE,\n MESSAGING_OPERATION_TYPE_VALUE_SEND,\n MESSAGING_SYSTEM_VALUE_KAFKA,\n} from './semconv';\n\nconst PRODUCER_ORIGIN = 'auto.kafkajs.otel.producer';\nconst CONSUMER_ORIGIN = 'auto.kafkajs.otel.consumer';\n\nexport interface ConsumerSpanOptions {\n topic: string;\n message: KafkaMessage | undefined;\n operationType: string;\n attributes: SpanAttributes;\n links?: SpanLink[];\n}\n\n/**\n * Reads a header value off a kafkajs message as a string. kafkajs delivers headers as `Buffer`s (or\n * arrays of them), so we normalize to a string before handing them to Sentry's trace helpers.\n */\nexport function getHeaderAsString(headers: KafkaMessage['headers'], key: string): string | undefined {\n const value = headers?.[key];\n if (value == null) {\n return undefined;\n }\n return Array.isArray(value) ? value[0]?.toString() : value.toString();\n}\n\n/**\n * Builds a span link to the producer span carried in the message headers, mirroring the upstream\n * behavior of linking each batch-processed message to its originating producer span.\n */\nexport function getLinksFromHeaders(headers: KafkaMessage['headers']): SpanLink[] | undefined {\n const sentryTrace = getHeaderAsString(headers, 'sentry-trace');\n if (!sentryTrace) {\n return undefined;\n }\n\n const { traceId, parentSpanId, sampled } = propagationContextFromHeaders(\n sentryTrace,\n getHeaderAsString(headers, 'baggage'),\n );\n if (!parentSpanId) {\n return undefined;\n }\n\n return [\n {\n context: {\n traceId,\n spanId: parentSpanId,\n isRemote: true,\n traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,\n },\n },\n ];\n}\n\n/** Starts an inactive consumer (process/receive) span carrying the kafkajs messaging attributes. */\nexport function startConsumerSpan({ topic, message, operationType, links, attributes }: ConsumerSpanOptions): Span {\n const operationName =\n operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE\n ? 'poll' // for batch processing spans\n : operationType; // for individual message processing spans\n\n return startInactiveSpan({\n name: `${operationName} ${topic}`,\n kind: operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE ? SPAN_KIND.CLIENT : SPAN_KIND.CONSUMER,\n links,\n attributes: {\n ...attributes,\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_OPERATION_TYPE]: operationType,\n [ATTR_MESSAGING_OPERATION_NAME]: operationName,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message?.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message?.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,\n // Mirror the upstream behavior of only tagging per-message processing spans (not the batch\n // receiving span, which carries no message) with the auto origin.\n ...(message ? { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: CONSUMER_ORIGIN } : {}),\n },\n });\n}\n\n/** Starts an inactive producer span and propagates its trace into the message headers. */\nexport function startProducerSpan(topic: string, message: Message): Span {\n const span = startInactiveSpan({\n name: `send ${topic}`,\n kind: SPAN_KIND.PRODUCER,\n attributes: {\n [ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,\n [ATTR_MESSAGING_DESTINATION_NAME]: topic,\n [ATTR_MESSAGING_KAFKA_MESSAGE_KEY]: message.key ? String(message.key) : undefined,\n [ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]: message.key && message.value === null ? true : undefined,\n [ATTR_MESSAGING_DESTINATION_PARTITION_ID]:\n message.partition !== undefined ? String(message.partition) : undefined,\n [ATTR_MESSAGING_OPERATION_NAME]: 'send',\n [ATTR_MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: PRODUCER_ORIGIN,\n },\n });\n\n // Propagate the producer span's trace to consumers via the message headers.\n message.headers = message.headers ?? {};\n const traceData = getTraceData({ span });\n if (traceData['sentry-trace']) {\n message.headers['sentry-trace'] = traceData['sentry-trace'];\n }\n if (traceData.baggage) {\n message.headers['baggage'] = traceData.baggage;\n }\n\n return span;\n}\n\n/**\n * Resolves once `sendPromise` settles, ending all `spans` and, on failure, marking them with the\n * error status and `error.type` before re-throwing.\n */\nexport function endSpansOnPromise<T>(spans: Span[], sendPromise: Promise<T>): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string | undefined;\n let errorType: string = ERROR_TYPE_VALUE_OTHER;\n if (typeof reason === 'string' || reason === undefined) {\n errorMessage = reason;\n } else if (typeof reason === 'object' && Object.prototype.hasOwnProperty.call(reason, 'message')) {\n errorMessage = reason.message;\n errorType = reason.constructor.name;\n }\n\n spans.forEach(span => {\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message: errorMessage,\n });\n });\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n}\n"],"names":["propagationContextFromHeaders","TraceFlags","MESSAGING_OPERATION_TYPE_VALUE_RECEIVE","startInactiveSpan","SPAN_KIND","ATTR_MESSAGING_SYSTEM","MESSAGING_SYSTEM_VALUE_KAFKA","ATTR_MESSAGING_DESTINATION_NAME","ATTR_MESSAGING_OPERATION_TYPE","ATTR_MESSAGING_OPERATION_NAME","ATTR_MESSAGING_KAFKA_MESSAGE_KEY","ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE","ATTR_MESSAGING_KAFKA_OFFSET","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","ATTR_MESSAGING_DESTINATION_PARTITION_ID","MESSAGING_OPERATION_TYPE_VALUE_SEND","getTraceData","ERROR_TYPE_VALUE_OTHER","ATTR_ERROR_TYPE","SPAN_STATUS_ERROR"],"mappings":";;;;;;AAqCA,MAAM,eAAA,GAAkB,4BAAA;AACxB,MAAM,eAAA,GAAkB,4BAAA;AAcjB,SAAS,iBAAA,CAAkB,SAAkC,GAAA,EAAiC;AACnG,EAAA,MAAM,KAAA,GAAQ,UAAU,GAAG,CAAA;AAC3B,EAAA,IAAI,SAAS,IAAA,EAAM;AACjB,IAAA,OAAO,MAAA;AAAA,EACT;AAC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A,KAAA,CAAM,OAAA,CAAQ,CAAA,IAAA,KAAQ,IAAA,CAAK,GAAA,EAAK,CAAA;AAAA,EAClC,CAAC,CAAA;AACL;;;;;;;;"}
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const api = require('@opentelemetry/api');
4
3
  const instrumentation = require('@opentelemetry/instrumentation');
5
4
  const core = require('@sentry/core');
6
5
  const InstrumentationNodeModuleFile = require('../../InstrumentationNodeModuleFile.js');
@@ -94,7 +93,7 @@ class KnexInstrumentation extends instrumentation.InstrumentationBase {
94
93
  return core.startSpan(
95
94
  {
96
95
  name: utils.getName(name, operation, table),
97
- kind: api.SpanKind.CLIENT,
96
+ kind: core.SPAN_KIND.CLIENT,
98
97
  attributes,
99
98
  parentSpan,
100
99
  onlyIfParent: true