@ddd-ts-kit/tracing 0.0.0-stage → 0.1.1

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 (262) hide show
  1. package/README.md +400 -2
  2. package/dist/application/trace-application.d.ts +39 -0
  3. package/dist/application/trace-application.d.ts.map +1 -0
  4. package/dist/application/trace-application.js +31 -0
  5. package/dist/application/trace-application.js.map +1 -0
  6. package/dist/configuration/configure-tracing.d.ts +9 -0
  7. package/dist/configuration/configure-tracing.d.ts.map +1 -0
  8. package/dist/configuration/configure-tracing.js +21 -0
  9. package/dist/configuration/configure-tracing.js.map +1 -0
  10. package/dist/configuration/default-lifecycle-hooks.d.ts +2 -0
  11. package/dist/configuration/default-lifecycle-hooks.d.ts.map +1 -0
  12. package/dist/configuration/default-lifecycle-hooks.js +8 -0
  13. package/dist/configuration/default-lifecycle-hooks.js.map +1 -0
  14. package/dist/configuration/tracing-configuration.d.ts +16 -0
  15. package/dist/configuration/tracing-configuration.d.ts.map +1 -0
  16. package/dist/configuration/tracing-configuration.js +2 -0
  17. package/dist/configuration/tracing-configuration.js.map +1 -0
  18. package/dist/correlation/correlation-id-from-active-span.d.ts +6 -0
  19. package/dist/correlation/correlation-id-from-active-span.d.ts.map +1 -0
  20. package/dist/correlation/correlation-id-from-active-span.js +10 -0
  21. package/dist/correlation/correlation-id-from-active-span.js.map +1 -0
  22. package/dist/correlation/trace-log-fields.d.ts +13 -0
  23. package/dist/correlation/trace-log-fields.d.ts.map +1 -0
  24. package/dist/correlation/trace-log-fields.js +20 -0
  25. package/dist/correlation/trace-log-fields.js.map +1 -0
  26. package/dist/correlation/traced-error-reporter.d.ts +9 -0
  27. package/dist/correlation/traced-error-reporter.d.ts.map +1 -0
  28. package/dist/correlation/traced-error-reporter.js +23 -0
  29. package/dist/correlation/traced-error-reporter.js.map +1 -0
  30. package/dist/dependency/method.d.ts +2 -0
  31. package/dist/dependency/method.d.ts.map +1 -0
  32. package/dist/dependency/method.js +2 -0
  33. package/dist/dependency/method.js.map +1 -0
  34. package/dist/dependency/proxied.d.ts +8 -0
  35. package/dist/dependency/proxied.d.ts.map +1 -0
  36. package/dist/dependency/proxied.js +21 -0
  37. package/dist/dependency/proxied.js.map +1 -0
  38. package/dist/dependency/shadowed.d.ts +4 -0
  39. package/dist/dependency/shadowed.d.ts.map +1 -0
  40. package/dist/dependency/shadowed.js +14 -0
  41. package/dist/dependency/shadowed.js.map +1 -0
  42. package/dist/dependency/trace-bindings.d.ts +25 -0
  43. package/dist/dependency/trace-bindings.d.ts.map +1 -0
  44. package/dist/dependency/trace-bindings.js +35 -0
  45. package/dist/dependency/trace-bindings.js.map +1 -0
  46. package/dist/dependency/trace-dependency.d.ts +26 -0
  47. package/dist/dependency/trace-dependency.d.ts.map +1 -0
  48. package/dist/dependency/trace-dependency.js +56 -0
  49. package/dist/dependency/trace-dependency.js.map +1 -0
  50. package/dist/dependency/traceable-methods.d.ts +4 -0
  51. package/dist/dependency/traceable-methods.d.ts.map +1 -0
  52. package/dist/dependency/traceable-methods.js +46 -0
  53. package/dist/dependency/traceable-methods.js.map +1 -0
  54. package/dist/dependency/traced.d.ts +5 -0
  55. package/dist/dependency/traced.d.ts.map +1 -0
  56. package/dist/dependency/traced.js +56 -0
  57. package/dist/dependency/traced.js.map +1 -0
  58. package/dist/domain-events/traced-domain-events.d.ts +14 -0
  59. package/dist/domain-events/traced-domain-events.d.ts.map +1 -0
  60. package/dist/domain-events/traced-domain-events.js +49 -0
  61. package/dist/domain-events/traced-domain-events.js.map +1 -0
  62. package/dist/events/consumer-trace.d.ts +8 -0
  63. package/dist/events/consumer-trace.d.ts.map +1 -0
  64. package/dist/events/consumer-trace.js +2 -0
  65. package/dist/events/consumer-trace.js.map +1 -0
  66. package/dist/events/messaging-attributes.d.ts +12 -0
  67. package/dist/events/messaging-attributes.d.ts.map +1 -0
  68. package/dist/events/messaging-attributes.js +11 -0
  69. package/dist/events/messaging-attributes.js.map +1 -0
  70. package/dist/events/traced-consumer.d.ts +22 -0
  71. package/dist/events/traced-consumer.d.ts.map +1 -0
  72. package/dist/events/traced-consumer.js +65 -0
  73. package/dist/events/traced-consumer.js.map +1 -0
  74. package/dist/events/traced-publisher.d.ts +19 -0
  75. package/dist/events/traced-publisher.d.ts.map +1 -0
  76. package/dist/events/traced-publisher.js +69 -0
  77. package/dist/events/traced-publisher.js.map +1 -0
  78. package/dist/events/traced-subscriber.d.ts +15 -0
  79. package/dist/events/traced-subscriber.d.ts.map +1 -0
  80. package/dist/events/traced-subscriber.js +19 -0
  81. package/dist/events/traced-subscriber.js.map +1 -0
  82. package/dist/http/is-noise-path.d.ts +3 -0
  83. package/dist/http/is-noise-path.d.ts.map +1 -0
  84. package/dist/http/is-noise-path.js +7 -0
  85. package/dist/http/is-noise-path.js.map +1 -0
  86. package/dist/http/is-noise-route.d.ts +6 -0
  87. package/dist/http/is-noise-route.d.ts.map +1 -0
  88. package/dist/http/is-noise-route.js +7 -0
  89. package/dist/http/is-noise-route.js.map +1 -0
  90. package/dist/http/noise-paths.d.ts +3 -0
  91. package/dist/http/noise-paths.d.ts.map +1 -0
  92. package/dist/http/noise-paths.js +15 -0
  93. package/dist/http/noise-paths.js.map +1 -0
  94. package/dist/http/traced-routes.d.ts +28 -0
  95. package/dist/http/traced-routes.d.ts.map +1 -0
  96. package/dist/http/traced-routes.js +76 -0
  97. package/dist/http/traced-routes.js.map +1 -0
  98. package/dist/index.d.ts +36 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +32 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/jobs/traced-job.d.ts +16 -0
  103. package/dist/jobs/traced-job.d.ts.map +1 -0
  104. package/dist/jobs/traced-job.js +25 -0
  105. package/dist/jobs/traced-job.js.map +1 -0
  106. package/dist/local-root/admit-dependency-span.d.ts +7 -0
  107. package/dist/local-root/admit-dependency-span.d.ts.map +1 -0
  108. package/dist/local-root/admit-dependency-span.js +30 -0
  109. package/dist/local-root/admit-dependency-span.js.map +1 -0
  110. package/dist/local-root/correlate.d.ts +9 -0
  111. package/dist/local-root/correlate.d.ts.map +1 -0
  112. package/dist/local-root/correlate.js +23 -0
  113. package/dist/local-root/correlate.js.map +1 -0
  114. package/dist/local-root/local-root-tracker.d.ts +18 -0
  115. package/dist/local-root/local-root-tracker.d.ts.map +1 -0
  116. package/dist/local-root/local-root-tracker.js +26 -0
  117. package/dist/local-root/local-root-tracker.js.map +1 -0
  118. package/dist/local-root/local-root.d.ts +11 -0
  119. package/dist/local-root/local-root.d.ts.map +1 -0
  120. package/dist/local-root/local-root.js +2 -0
  121. package/dist/local-root/local-root.js.map +1 -0
  122. package/dist/local-root/local-roots.d.ts +4 -0
  123. package/dist/local-root/local-roots.d.ts.map +1 -0
  124. package/dist/local-root/local-roots.js +4 -0
  125. package/dist/local-root/local-roots.js.map +1 -0
  126. package/dist/local-root/work-attributes.d.ts +4 -0
  127. package/dist/local-root/work-attributes.d.ts.map +1 -0
  128. package/dist/local-root/work-attributes.js +11 -0
  129. package/dist/local-root/work-attributes.js.map +1 -0
  130. package/dist/node/default-instrumentations.d.ts +20 -0
  131. package/dist/node/default-instrumentations.d.ts.map +1 -0
  132. package/dist/node/default-instrumentations.js +55 -0
  133. package/dist/node/default-instrumentations.js.map +1 -0
  134. package/dist/node/init-tracing.d.ts +41 -0
  135. package/dist/node/init-tracing.d.ts.map +1 -0
  136. package/dist/node/init-tracing.js +71 -0
  137. package/dist/node/init-tracing.js.map +1 -0
  138. package/dist/node/instrumentations-off.d.ts +6 -0
  139. package/dist/node/instrumentations-off.d.ts.map +1 -0
  140. package/dist/node/instrumentations-off.js +39 -0
  141. package/dist/node/instrumentations-off.js.map +1 -0
  142. package/dist/node.d.ts +3 -0
  143. package/dist/node.d.ts.map +1 -0
  144. package/dist/node.js +3 -0
  145. package/dist/node.js.map +1 -0
  146. package/dist/processors/attribute-allow-list.d.ts +25 -0
  147. package/dist/processors/attribute-allow-list.d.ts.map +1 -0
  148. package/dist/processors/attribute-allow-list.js +38 -0
  149. package/dist/processors/attribute-allow-list.js.map +1 -0
  150. package/dist/processors/default-allowed-attributes.d.ts +8 -0
  151. package/dist/processors/default-allowed-attributes.d.ts.map +1 -0
  152. package/dist/processors/default-allowed-attributes.js +48 -0
  153. package/dist/processors/default-allowed-attributes.js.map +1 -0
  154. package/dist/processors/ended-span.d.ts +19 -0
  155. package/dist/processors/ended-span.d.ts.map +1 -0
  156. package/dist/processors/ended-span.js +2 -0
  157. package/dist/processors/ended-span.js.map +1 -0
  158. package/dist/processors/error-message-scrubber.d.ts +13 -0
  159. package/dist/processors/error-message-scrubber.d.ts.map +1 -0
  160. package/dist/processors/error-message-scrubber.js +21 -0
  161. package/dist/processors/error-message-scrubber.js.map +1 -0
  162. package/dist/processors/url-secret-span-processor.d.ts +12 -0
  163. package/dist/processors/url-secret-span-processor.d.ts.map +1 -0
  164. package/dist/processors/url-secret-span-processor.js +47 -0
  165. package/dist/processors/url-secret-span-processor.js.map +1 -0
  166. package/dist/propagation/capture-traceparent.d.ts +3 -0
  167. package/dist/propagation/capture-traceparent.d.ts.map +1 -0
  168. package/dist/propagation/capture-traceparent.js +7 -0
  169. package/dist/propagation/capture-traceparent.js.map +1 -0
  170. package/dist/propagation/context-with-traceparent.d.ts +4 -0
  171. package/dist/propagation/context-with-traceparent.d.ts.map +1 -0
  172. package/dist/propagation/context-with-traceparent.js +8 -0
  173. package/dist/propagation/context-with-traceparent.js.map +1 -0
  174. package/dist/propagation/run-with-traceparent.d.ts +6 -0
  175. package/dist/propagation/run-with-traceparent.d.ts.map +1 -0
  176. package/dist/propagation/run-with-traceparent.js +10 -0
  177. package/dist/propagation/run-with-traceparent.js.map +1 -0
  178. package/dist/propagation/span-context-from-traceparent.d.ts +4 -0
  179. package/dist/propagation/span-context-from-traceparent.d.ts.map +1 -0
  180. package/dist/propagation/span-context-from-traceparent.js +23 -0
  181. package/dist/propagation/span-context-from-traceparent.js.map +1 -0
  182. package/dist/propagation/traceparent-from-context.d.ts +4 -0
  183. package/dist/propagation/traceparent-from-context.d.ts.map +1 -0
  184. package/dist/propagation/traceparent-from-context.js +11 -0
  185. package/dist/propagation/traceparent-from-context.js.map +1 -0
  186. package/dist/span/constructor-name.d.ts +3 -0
  187. package/dist/span/constructor-name.d.ts.map +1 -0
  188. package/dist/span/constructor-name.js +9 -0
  189. package/dist/span/constructor-name.js.map +1 -0
  190. package/dist/span/failed-traces.d.ts +2 -0
  191. package/dist/span/failed-traces.d.ts.map +1 -0
  192. package/dist/span/failed-traces.js +3 -0
  193. package/dist/span/failed-traces.js.map +1 -0
  194. package/dist/span/in-span.d.ts +12 -0
  195. package/dist/span/in-span.d.ts.map +1 -0
  196. package/dist/span/in-span.js +19 -0
  197. package/dist/span/in-span.js.map +1 -0
  198. package/dist/span/is-thenable.d.ts +2 -0
  199. package/dist/span/is-thenable.d.ts.map +1 -0
  200. package/dist/span/is-thenable.js +7 -0
  201. package/dist/span/is-thenable.js.map +1 -0
  202. package/dist/span/mark-span-failed.d.ts +4 -0
  203. package/dist/span/mark-span-failed.d.ts.map +1 -0
  204. package/dist/span/mark-span-failed.js +36 -0
  205. package/dist/span/mark-span-failed.js.map +1 -0
  206. package/dist/span/outcome-attribute.d.ts +3 -0
  207. package/dist/span/outcome-attribute.d.ts.map +1 -0
  208. package/dist/span/outcome-attribute.js +3 -0
  209. package/dist/span/outcome-attribute.js.map +1 -0
  210. package/dist/span/refusal-code.d.ts +4 -0
  211. package/dist/span/refusal-code.d.ts.map +1 -0
  212. package/dist/span/refusal-code.js +10 -0
  213. package/dist/span/refusal-code.js.map +1 -0
  214. package/dist/span/tracer.d.ts +4 -0
  215. package/dist/span/tracer.d.ts.map +1 -0
  216. package/dist/span/tracer.js +7 -0
  217. package/dist/span/tracer.js.map +1 -0
  218. package/dist/span/with-span.d.ts +9 -0
  219. package/dist/span/with-span.d.ts.map +1 -0
  220. package/dist/span/with-span.js +36 -0
  221. package/dist/span/with-span.js.map +1 -0
  222. package/dist/testing/expect-span-tree.d.ts +10 -0
  223. package/dist/testing/expect-span-tree.d.ts.map +1 -0
  224. package/dist/testing/expect-span-tree.js +29 -0
  225. package/dist/testing/expect-span-tree.js.map +1 -0
  226. package/dist/testing/expected-span.d.ts +17 -0
  227. package/dist/testing/expected-span.d.ts.map +1 -0
  228. package/dist/testing/expected-span.js +2 -0
  229. package/dist/testing/expected-span.js.map +1 -0
  230. package/dist/testing/install-test-tracing.d.ts +23 -0
  231. package/dist/testing/install-test-tracing.d.ts.map +1 -0
  232. package/dist/testing/install-test-tracing.js +48 -0
  233. package/dist/testing/install-test-tracing.js.map +1 -0
  234. package/dist/testing/render-span-tree.d.ts +8 -0
  235. package/dist/testing/render-span-tree.d.ts.map +1 -0
  236. package/dist/testing/render-span-tree.js +23 -0
  237. package/dist/testing/render-span-tree.js.map +1 -0
  238. package/dist/testing/span-mismatches.d.ts +5 -0
  239. package/dist/testing/span-mismatches.d.ts.map +1 -0
  240. package/dist/testing/span-mismatches.js +34 -0
  241. package/dist/testing/span-mismatches.js.map +1 -0
  242. package/dist/testing/span-node.d.ts +13 -0
  243. package/dist/testing/span-node.d.ts.map +1 -0
  244. package/dist/testing/span-node.js +2 -0
  245. package/dist/testing/span-node.js.map +1 -0
  246. package/dist/testing/span-tree-of.d.ts +8 -0
  247. package/dist/testing/span-tree-of.d.ts.map +1 -0
  248. package/dist/testing/span-tree-of.js +34 -0
  249. package/dist/testing/span-tree-of.js.map +1 -0
  250. package/dist/testing/start-order.d.ts +12 -0
  251. package/dist/testing/start-order.d.ts.map +1 -0
  252. package/dist/testing/start-order.js +17 -0
  253. package/dist/testing/start-order.js.map +1 -0
  254. package/dist/testing.d.ts +6 -0
  255. package/dist/testing.d.ts.map +1 -0
  256. package/dist/testing.js +4 -0
  257. package/dist/testing.js.map +1 -0
  258. package/dist/use-case/trace-use-cases.d.ts +10 -0
  259. package/dist/use-case/trace-use-cases.d.ts.map +1 -0
  260. package/dist/use-case/trace-use-cases.js +41 -0
  261. package/dist/use-case/trace-use-cases.js.map +1 -0
  262. package/package.json +75 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-consumer.d.ts","sourceRoot":"","sources":["../../src/events/traced-consumer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAmC,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAMpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,WAAW,qBAAqB;IACpC,mGAAmG;IACnG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AAEzD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,wBAAwB,EACjC,OAAO,GAAE,qBAA0B,GAClC,wBAAwB,CAO1B"}
@@ -0,0 +1,65 @@
1
+ import { SpanKind, context, trace, } from '@opentelemetry/api';
2
+ import { CORRELATION_ID_ATTRIBUTE, ORIGIN_ATTRIBUTE } from '../local-root/correlate.js';
3
+ import { spanContextFromTraceparent } from '../propagation/span-context-from-traceparent.js';
4
+ import { inSpan } from '../span/in-span.js';
5
+ import { markSpanFailed } from '../span/mark-span-failed.js';
6
+ import { OUTCOME_ATTRIBUTE } from '../span/outcome-attribute.js';
7
+ import { messagingAttributes } from './messaging-attributes.js';
8
+ export const ATTEMPT_ATTRIBUTE = 'app.messaging.attempt';
9
+ /**
10
+ * Wraps what a provider calls at each delivery: every attempt runs in its own CONSUMER span,
11
+ * which says which attempt it is, so a redelivery reads as one. A failed attempt is an error
12
+ * with the code of what was thrown; the attempt after which the provider gives the event up
13
+ * says `dead-lettered`. The span starts the unit of work: it carries the correlation id of the
14
+ * event. Never the payload.
15
+ */
16
+ export function tracedConsumer(handler, options = {}) {
17
+ return async (event, delivery) => {
18
+ await inSpan(startOf(event, delivery, options), async (span) => {
19
+ await handler(event, delivery);
20
+ span.setAttribute(OUTCOME_ATTRIBUTE, 'succeeded');
21
+ });
22
+ };
23
+ }
24
+ function startOf(event, delivery, options) {
25
+ const producer = event.traceparent === undefined ? undefined : spanContextFromTraceparent(event.traceparent);
26
+ const linked = options.trace === 'link' && producer !== undefined;
27
+ const spanOptions = { kind: SpanKind.CONSUMER, attributes: attributesOf(event, delivery, options) };
28
+ return {
29
+ name: `process ${options.consumer ?? event.type}`,
30
+ options: linked ? { ...spanOptions, root: true, links: [{ context: producer }] } : spanOptions,
31
+ parent: parentOf(producer, linked),
32
+ onFailure: (span, error) => {
33
+ failed(span, error, delivery);
34
+ },
35
+ };
36
+ }
37
+ function parentOf(producer, linked) {
38
+ const active = context.active();
39
+ return producer === undefined || linked ? active : trace.setSpanContext(active, producer);
40
+ }
41
+ function attributesOf(event, delivery, options) {
42
+ const consumer = options.consumer ?? delivery?.consumer;
43
+ return {
44
+ ...messagingAttributes({ name: 'process', type: 'process', system: delivery?.system ?? options.system }, event),
45
+ ...(consumer === undefined ? {} : { 'messaging.consumer.group.name': consumer }),
46
+ ...(options.context === undefined ? {} : { 'app.context': options.context }),
47
+ ...deliveryAttributes(delivery),
48
+ [CORRELATION_ID_ATTRIBUTE]: event.correlationId ?? event.id,
49
+ [ORIGIN_ATTRIBUTE]: 'event',
50
+ };
51
+ }
52
+ function deliveryAttributes(delivery) {
53
+ const attempt = delivery?.attempt ?? 1;
54
+ return {
55
+ ...(delivery?.destination === undefined ? {} : { 'app.messaging.source': delivery.destination }),
56
+ [ATTEMPT_ATTRIBUTE]: attempt,
57
+ ...(attempt > 1 ? { 'app.messaging.redelivered': true } : {}),
58
+ };
59
+ }
60
+ function failed(span, error, delivery) {
61
+ const last = delivery?.maxAttempts !== undefined && delivery.attempt >= delivery.maxAttempts;
62
+ markSpanFailed(span, error);
63
+ span.setAttribute(OUTCOME_ATTRIBUTE, last ? 'dead-lettered' : 'failed');
64
+ }
65
+ //# sourceMappingURL=traced-consumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-consumer.js","sourceRoot":"","sources":["../../src/events/traced-consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,OAAO,EACP,KAAK,GAMN,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAkB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAahE,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAiC,EACjC,OAAO,GAA0B,EAAE;IAEnC,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/B,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC7D,MAAM,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CACd,KAAuB,EACvB,QAAmC,EACnC,OAA8B;IAE9B,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,S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,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { type IntegrationEventPublisher } from '@ddd-ts-kit/kernel';
2
+ export interface TracedPublisherOptions {
3
+ /** The transport, when the publisher does not name it itself (`messagingSystem`). `outbox` for one that only stores. */
4
+ readonly system?: string;
5
+ }
6
+ /**
7
+ * Decorates a publisher: one span per event, and its `traceparent` stamped on what goes out,
8
+ * so whatever handles the event next is a child of that span.
9
+ *
10
+ * A publisher that sends (`publish <type>`, PRODUCER) continues the trace the event already
11
+ * names: an outbox relay publishing later, from a timer and outside of any request, attaches
12
+ * its span to the trace of the request that stored the event, never to its own loop. A
13
+ * publisher that only stores (`outbox append <type>`, the operation `create`) is where that
14
+ * context is captured, inside the request. An event without `traceparent` continues the
15
+ * active span. The spans count against the caps of the local root: past them an event goes
16
+ * out without a span of its own, still naming the trace.
17
+ */
18
+ export declare function tracedPublisher(publisher: IntegrationEventPublisher, options?: TracedPublisherOptions): IntegrationEventPublisher;
19
+ //# sourceMappingURL=traced-publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-publisher.d.ts","sourceRoot":"","sources":["../../src/events/traced-publisher.ts"],"names":[],"mappings":"AACA,OAAO,EAA4C,KAAK,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAQ9G,MAAM,WAAW,sBAAsB;IACrC,wHAAwH;IACxH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAUD;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,yBAAyB,EACpC,OAAO,GAAE,sBAA2B,GACnC,yBAAyB,CAyB3B"}
@@ -0,0 +1,69 @@
1
+ import { SpanKind, context, trace } from '@opentelemetry/api';
2
+ import { messagingSystemOf } from '@ddd-ts-kit/kernel';
3
+ import { admitDependencySpan } from '../local-root/admit-dependency-span.js';
4
+ import { contextWithTraceparent } from '../propagation/context-with-traceparent.js';
5
+ import { traceparentFromContext } from '../propagation/traceparent-from-context.js';
6
+ import { markSpanFailed } from '../span/mark-span-failed.js';
7
+ import { tracer } from '../span/tracer.js';
8
+ import { messagingAttributes } from './messaging-attributes.js';
9
+ const OUTBOX = 'outbox';
10
+ /**
11
+ * Decorates a publisher: one span per event, and its `traceparent` stamped on what goes out,
12
+ * so whatever handles the event next is a child of that span.
13
+ *
14
+ * A publisher that sends (`publish <type>`, PRODUCER) continues the trace the event already
15
+ * names: an outbox relay publishing later, from a timer and outside of any request, attaches
16
+ * its span to the trace of the request that stored the event, never to its own loop. A
17
+ * publisher that only stores (`outbox append <type>`, the operation `create`) is where that
18
+ * context is captured, inside the request. An event without `traceparent` continues the
19
+ * active span. The spans count against the caps of the local root: past them an event goes
20
+ * out without a span of its own, still naming the trace.
21
+ */
22
+ export function tracedPublisher(publisher, options = {}) {
23
+ const system = options.system ?? messagingSystemOf(publisher);
24
+ return {
25
+ async publish(events) {
26
+ const active = context.active();
27
+ const publications = events.map((event) => publicationOf(event, active, system));
28
+ const spans = publications.flatMap(({ span }) => span ?? []);
29
+ try {
30
+ // One call for the whole batch: the provider keeps its atomicity and ordering.
31
+ await publisher.publish(publications.map(({ event }) => event));
32
+ }
33
+ catch (error) {
34
+ for (const span of spans) {
35
+ markSpanFailed(span, error);
36
+ }
37
+ throw error;
38
+ }
39
+ finally {
40
+ for (const span of spans) {
41
+ span.end();
42
+ }
43
+ }
44
+ },
45
+ };
46
+ }
47
+ function publicationOf(event, active, system) {
48
+ const parent = contextWithTraceparent(active, event.traceparent);
49
+ const stored = system === OUTBOX;
50
+ const name = stored ? `outbox append ${event.type}` : `publish ${event.type}`;
51
+ if (!admitDependencySpan(name)) {
52
+ return { event: stamped(event, parent) };
53
+ }
54
+ const operation = stored
55
+ ? { name: 'append', type: 'create', system }
56
+ : { name: 'publish', type: 'send', system };
57
+ const options = {
58
+ kind: stored ? SpanKind.INTERNAL : SpanKind.PRODUCER,
59
+ attributes: messagingAttributes(operation, event),
60
+ };
61
+ const span = tracer().startSpan(name, options, parent);
62
+ return { event: stamped(event, trace.setSpan(parent, span)), span };
63
+ }
64
+ /** The event naming the span carried by the context, or as it is when there is none. */
65
+ function stamped(event, from) {
66
+ const traceparent = traceparentFromContext(from);
67
+ return traceparent === undefined ? event : { ...event, traceparent };
68
+ }
69
+ //# sourceMappingURL=traced-publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-publisher.js","sourceRoot":"","sources":["../../src/events/traced-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAA2B,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAyD,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAA2B,MAAM,2BAA2B,CAAC;AAazF,MAAM,MAAM,GAAG,QAAQ,CAAC;AAExB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAoC,EACpC,OAAO,GAA2B,EAAE;IAEpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE9D,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,MAAmC;YAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC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C,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAE9C,MAAM,OAAO,GAAG;QACd,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ;QACpD,UAAU,EAAE,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC;KAClD,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAEvD,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AACtE,CAAC;AAED,wFAAwF;AACxF,SAAS,OAAO,CAAC,KAAuB,EAAE,IAAa;IACrD,MAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAEjD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,WAAW,EAAE,CAAC;AACvE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
2
+ import type { ConsumerTrace } from './consumer-trace.js';
3
+ export interface TracedSubscriberOptions {
4
+ /** Default `continue`. */
5
+ readonly trace?: ConsumerTrace;
6
+ /** The transport, when neither the deliveries nor the subscriber (`messagingSystem`) name it. */
7
+ readonly system?: string;
8
+ }
9
+ /**
10
+ * Decorates a subscriber, for a composition without `kernelModule`: every handler runs in a
11
+ * CONSUMER span `process <type>` (see `tracedConsumer`). That span is a local root, so the
12
+ * per-root cap of dependency spans applies to each delivery separately.
13
+ */
14
+ export declare function tracedSubscriber(subscriber: IntegrationEventSubscriber, options?: TracedSubscriberOptions): IntegrationEventSubscriber;
15
+ //# sourceMappingURL=traced-subscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-subscriber.d.ts","sourceRoot":"","sources":["../../src/events/traced-subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAEhC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,MAAM,WAAW,uBAAuB;IACtC,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,0BAA0B,EACtC,OAAO,GAAE,uBAA4B,GACpC,0BAA0B,CAc5B"}
@@ -0,0 +1,19 @@
1
+ import { messagingSystemOf, } from '@ddd-ts-kit/kernel';
2
+ import { tracedConsumer } from './traced-consumer.js';
3
+ /**
4
+ * Decorates a subscriber, for a composition without `kernelModule`: every handler runs in a
5
+ * CONSUMER span `process <type>` (see `tracedConsumer`). That span is a local root, so the
6
+ * per-root cap of dependency spans applies to each delivery separately.
7
+ */
8
+ export function tracedSubscriber(subscriber, options = {}) {
9
+ const system = options.system ?? messagingSystemOf(subscriber);
10
+ return {
11
+ subscribe(type, handler) {
12
+ return subscriber.subscribe(type, tracedConsumer(handler, {
13
+ ...(options.trace === undefined ? {} : { trace: options.trace }),
14
+ ...(system === undefined ? {} : { system }),
15
+ }));
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=traced-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-subscriber.js","sourceRoot":"","sources":["../../src/events/traced-subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAIlB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAStD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAsC,EACtC,OAAO,GAA4B,EAAE;IAErC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAE/D,OAAO;QACL,SAAS,CAAC,IAAY,EAAE,OAAiC;YACvD,OAAO,UAAU,CAAC,SAAS,CACzB,IAAI,EACJ,cAAc,CAAC,OAAO,EAAE;gBACtB,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;aAC5C,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Whether the path, without its query string, is one of the noise paths or below one of them. */
2
+ export declare function isNoisePath(url: string, paths?: readonly string[]): boolean;
3
+ //# sourceMappingURL=is-noise-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-noise-path.d.ts","sourceRoot":"","sources":["../../src/http/is-noise-path.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,MAAM,EAAgB,GAAG,OAAO,CAIxF"}
@@ -0,0 +1,7 @@
1
+ import { NOISE_PATHS } from './noise-paths.js';
2
+ /** Whether the path, without its query string, is one of the noise paths or below one of them. */
3
+ export function isNoisePath(url, paths = NOISE_PATHS) {
4
+ const path = url.split('?', 1).join('');
5
+ return paths.some((noise) => path === noise || path.startsWith(`${noise}/`));
6
+ }
7
+ //# sourceMappingURL=is-noise-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-noise-path.js","sourceRoot":"","sources":["../../src/http/is-noise-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,kGAAkG;AAClG,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,KAAK,GAAsB,WAAW;IAC7E,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAExC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** A route nobody follows in a trace: probes, metrics, and the documentation routes of the kit. */
2
+ export declare function isNoiseRoute(route: {
3
+ readonly path: string;
4
+ readonly operationId: string;
5
+ }): boolean;
6
+ //# sourceMappingURL=is-noise-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-noise-route.d.ts","sourceRoot":"","sources":["../../src/http/is-noise-route.ts"],"names":[],"mappings":"AAIA,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAEpG"}
@@ -0,0 +1,7 @@
1
+ import { isNoisePath } from './is-noise-path.js';
2
+ const DOCUMENTATION_OPERATIONS = new Set(['getOpenApiDocument', 'getOpenApiUi']);
3
+ /** A route nobody follows in a trace: probes, metrics, and the documentation routes of the kit. */
4
+ export function isNoiseRoute(route) {
5
+ return DOCUMENTATION_OPERATIONS.has(route.operationId) || isNoisePath(route.path);
6
+ }
7
+ //# sourceMappingURL=is-noise-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-noise-route.js","sourceRoot":"","sources":["../../src/http/is-noise-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC,CAAC;AAEjF,mGAAmG;AACnG,MAAM,UAAU,YAAY,CAAC,KAA8D;IACzF,OAAO,wBAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Paths that get no span by default: probes, metrics scrapes, documentation, browser plumbing. */
2
+ export declare const NOISE_PATHS: readonly string[];
3
+ //# sourceMappingURL=noise-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noise-paths.d.ts","sourceRoot":"","sources":["../../src/http/noise-paths.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAYxC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** Paths that get no span by default: probes, metrics scrapes, documentation, browser plumbing. */
2
+ export const NOISE_PATHS = [
3
+ '/health',
4
+ '/healthz',
5
+ '/livez',
6
+ '/live',
7
+ '/ready',
8
+ '/readyz',
9
+ '/startup',
10
+ '/metrics',
11
+ '/docs',
12
+ '/openapi.json',
13
+ '/favicon.ico',
14
+ ];
15
+ //# sourceMappingURL=noise-paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noise-paths.js","sourceRoot":"","sources":["../../src/http/noise-paths.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,CAAC,MAAM,WAAW,GAAsB;IAC5C,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,UAAU;IACV,UAAU;IACV,OAAO;IACP,eAAe;IACf,cAAc;CACf,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** The route a request was matched to, as the HTTP pipeline of the kit describes it. */
2
+ export interface TracedRoute {
3
+ readonly method: string;
4
+ /** The template (`/orders/:id`), never the URL that was called. */
5
+ readonly path: string;
6
+ readonly operationId: string;
7
+ }
8
+ /** What the pipeline answered. */
9
+ export interface TracedResponse {
10
+ readonly status: number;
11
+ readonly headers: Readonly<Record<string, string>>;
12
+ readonly body?: unknown;
13
+ }
14
+ export interface TracedRoutesOptions {
15
+ /** Routes that get no span of their own. Defaults to health, readiness, metrics and documentation routes. */
16
+ readonly ignore?: (route: TracedRoute) => boolean;
17
+ }
18
+ type Around = <R extends TracedResponse>(route: TracedRoute, respond: () => Promise<R>) => Promise<R>;
19
+ /**
20
+ * The `around` hook of `@ddd-ts-kit/http` (`ExecuteOptions`): the SERVER span of each request,
21
+ * named by method and route template, `POST /orders/:id/lines`, never by the URL. The span an
22
+ * HTTP instrumentation already opened for the request is renamed and completed; without one,
23
+ * the span is started here. It says the operation, the status, the correlation id, and for a
24
+ * refusal the code of the problem answered: a 4xx is an answer, a 5xx an error.
25
+ */
26
+ export declare function tracedRoutes(options?: TracedRoutesOptions): Around;
27
+ export {};
28
+ //# sourceMappingURL=traced-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-routes.d.ts","sourceRoot":"","sources":["../../src/http/traced-routes.ts"],"names":[],"mappings":"AASA,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,kCAAkC;AAClC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,6GAA6G;IAC7G,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;CACnD;AAED,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtG;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CA8BtE"}
@@ -0,0 +1,76 @@
1
+ import { SpanKind, SpanStatusCode, context, trace } from '@opentelemetry/api';
2
+ import { CORRELATION_ID_ATTRIBUTE, ORIGIN_ATTRIBUTE } from '../local-root/correlate.js';
3
+ import { localRoots } from '../local-root/local-roots.js';
4
+ import { markSpanFailed } from '../span/mark-span-failed.js';
5
+ import { OUTCOME_ATTRIBUTE } from '../span/outcome-attribute.js';
6
+ import { refusalCode } from '../span/refusal-code.js';
7
+ import { tracer } from '../span/tracer.js';
8
+ import { isNoiseRoute } from './is-noise-route.js';
9
+ /**
10
+ * The `around` hook of `@ddd-ts-kit/http` (`ExecuteOptions`): the SERVER span of each request,
11
+ * named by method and route template, `POST /orders/:id/lines`, never by the URL. The span an
12
+ * HTTP instrumentation already opened for the request is renamed and completed; without one,
13
+ * the span is started here. It says the operation, the status, the correlation id, and for a
14
+ * refusal the code of the problem answered: a 4xx is an answer, a 5xx an error.
15
+ */
16
+ export function tracedRoutes(options = {}) {
17
+ const ignored = options.ignore ?? isNoiseRoute;
18
+ return async (route, respond) => {
19
+ if (ignored(route)) {
20
+ return respond();
21
+ }
22
+ const existing = serverSpanInProgress();
23
+ const span = existing ?? started(route);
24
+ span.updateName(`${route.method} ${route.path}`);
25
+ span.setAttributes({ 'http.route': route.path, 'app.operation': route.operationId });
26
+ try {
27
+ const response = await context.with(trace.setSpan(context.active(), span), respond);
28
+ answered(span, response);
29
+ return response;
30
+ }
31
+ catch (error) {
32
+ markSpanFailed(span, error);
33
+ throw error;
34
+ }
35
+ finally {
36
+ if (existing === undefined) {
37
+ span.end();
38
+ }
39
+ }
40
+ };
41
+ }
42
+ /** The active span when it is the local root and a SERVER span: the one an HTTP instrumentation opened for the request. */
43
+ function serverSpanInProgress() {
44
+ const active = trace.getActiveSpan();
45
+ if (active === undefined || !active.isRecording() || localRoots.get(active)?.span !== active) {
46
+ return undefined;
47
+ }
48
+ // The API of a span does not say its kind; the span of the SDK does.
49
+ return Reflect.get(active, 'kind') === SpanKind.SERVER ? active : undefined;
50
+ }
51
+ function started(route) {
52
+ return tracer().startSpan(`${route.method} ${route.path}`, {
53
+ kind: SpanKind.SERVER,
54
+ attributes: { 'http.request.method': route.method },
55
+ });
56
+ }
57
+ function answered(span, { status, headers, body }) {
58
+ const correlationId = headers['x-correlation-id'];
59
+ span.setAttributes({
60
+ 'http.response.status_code': status,
61
+ [ORIGIN_ATTRIBUTE]: 'http',
62
+ ...(correlationId === undefined ? {} : { [CORRELATION_ID_ATTRIBUTE]: correlationId }),
63
+ [OUTCOME_ATTRIBUTE]: outcomeOf(status),
64
+ ...(status >= 400 ? refusalCode(body) : {}),
65
+ });
66
+ if (status >= 500) {
67
+ span.setStatus({ code: SpanStatusCode.ERROR });
68
+ }
69
+ }
70
+ function outcomeOf(status) {
71
+ if (status >= 500) {
72
+ return 'failed';
73
+ }
74
+ return status >= 400 ? 'refused' : 'succeeded';
75
+ }
76
+ //# sourceMappingURL=traced-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-routes.js","sourceRoot":"","sources":["../../src/http/traced-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,E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MAAM,CAAC;QACtC,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAClB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AACjD,CAAC"}
@@ -0,0 +1,36 @@
1
+ export type { DependencyKind } from '@ddd-ts-kit/kernel';
2
+ export { traceApplication, type TraceApplicationOptions, type TracedApplication, } from './application/trace-application.js';
3
+ export { configureTracing, resetTracingConfiguration } from './configuration/configure-tracing.js';
4
+ export { DEFAULT_LIFECYCLE_HOOKS } from './configuration/default-lifecycle-hooks.js';
5
+ export type { TracingConfiguration } from './configuration/tracing-configuration.js';
6
+ export { correlationIdFromActiveSpan } from './correlation/correlation-id-from-active-span.js';
7
+ export { traceLogFields, type TraceLogFields } from './correlation/trace-log-fields.js';
8
+ export { tracedErrorReporter } from './correlation/traced-error-reporter.js';
9
+ export { traceBindings, type TracedBinding } from './dependency/trace-bindings.js';
10
+ export { traceDependency, type TraceDependencyOptions } from './dependency/trace-dependency.js';
11
+ export { tracedDomainEvents } from './domain-events/traced-domain-events.js';
12
+ export type { ConsumerTrace } from './events/consumer-trace.js';
13
+ export { ATTEMPT_ATTRIBUTE, tracedConsumer, type TracedConsumerOptions } from './events/traced-consumer.js';
14
+ export { tracedPublisher, type TracedPublisherOptions } from './events/traced-publisher.js';
15
+ export { tracedSubscriber, type TracedSubscriberOptions } from './events/traced-subscriber.js';
16
+ export { isNoisePath } from './http/is-noise-path.js';
17
+ export { isNoiseRoute } from './http/is-noise-route.js';
18
+ export { NOISE_PATHS } from './http/noise-paths.js';
19
+ export { tracedRoutes, type TracedResponse, type TracedRoute, type TracedRoutesOptions } from './http/traced-routes.js';
20
+ export { tracedJob, type TracedJobOptions } from './jobs/traced-job.js';
21
+ export { DROPPED_SPANS_ATTRIBUTE } from './local-root/admit-dependency-span.js';
22
+ export { CORRELATION_ID_ATTRIBUTE, ORIGIN_ATTRIBUTE } from './local-root/correlate.js';
23
+ export { LocalRootTracker } from './local-root/local-root-tracker.js';
24
+ export { AttributeAllowList, type AttributeAllowListOptions } from './processors/attribute-allow-list.js';
25
+ export { DEFAULT_ALLOWED_ATTRIBUTES } from './processors/default-allowed-attributes.js';
26
+ export type { EndedSpan } from './processors/ended-span.js';
27
+ export { ErrorMessageScrubber } from './processors/error-message-scrubber.js';
28
+ export { UrlSecretSpanProcessor } from './processors/url-secret-span-processor.js';
29
+ export { captureTraceparent } from './propagation/capture-traceparent.js';
30
+ export { runWithTraceparent } from './propagation/run-with-traceparent.js';
31
+ export { spanContextFromTraceparent } from './propagation/span-context-from-traceparent.js';
32
+ export { traceparentFromContext } from './propagation/traceparent-from-context.js';
33
+ export { OUTCOME_ATTRIBUTE } from './span/outcome-attribute.js';
34
+ export { withSpan } from './span/with-span.js';
35
+ export { traceUseCases } from './use-case/trace-use-cases.js';
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM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OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAC1G,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AACxF,YAAY,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ export { traceApplication, } from './application/trace-application.js';
2
+ export { configureTracing, resetTracingConfiguration } from './configuration/configure-tracing.js';
3
+ export { DEFAULT_LIFECYCLE_HOOKS } from './configuration/default-lifecycle-hooks.js';
4
+ export { correlationIdFromActiveSpan } from './correlation/correlation-id-from-active-span.js';
5
+ export { traceLogFields } from './correlation/trace-log-fields.js';
6
+ export { tracedErrorReporter } from './correlation/traced-error-reporter.js';
7
+ export { traceBindings } from './dependency/trace-bindings.js';
8
+ export { traceDependency } from './dependency/trace-dependency.js';
9
+ export { tracedDomainEvents } from './domain-events/traced-domain-events.js';
10
+ export { ATTEMPT_ATTRIBUTE, tracedConsumer } from './events/traced-consumer.js';
11
+ export { tracedPublisher } from './events/traced-publisher.js';
12
+ export { tracedSubscriber } from './events/traced-subscriber.js';
13
+ export { isNoisePath } from './http/is-noise-path.js';
14
+ export { isNoiseRoute } from './http/is-noise-route.js';
15
+ export { NOISE_PATHS } from './http/noise-paths.js';
16
+ export { tracedRoutes } from './http/traced-routes.js';
17
+ export { tracedJob } from './jobs/traced-job.js';
18
+ export { DROPPED_SPANS_ATTRIBUTE } from './local-root/admit-dependency-span.js';
19
+ export { CORRELATION_ID_ATTRIBUTE, ORIGIN_ATTRIBUTE } from './local-root/correlate.js';
20
+ export { LocalRootTracker } from './local-root/local-root-tracker.js';
21
+ export { AttributeAllowList } from './processors/attribute-allow-list.js';
22
+ export { DEFAULT_ALLOWED_ATTRIBUTES } from './processors/default-allowed-attributes.js';
23
+ export { ErrorMessageScrubber } from './processors/error-message-scrubber.js';
24
+ export { UrlSecretSpanProcessor } from './processors/url-secret-span-processor.js';
25
+ export { captureTraceparent } from './propagation/capture-traceparent.js';
26
+ export { runWithTraceparent } from './propagation/run-with-traceparent.js';
27
+ export { spanContextFromTraceparent } from './propagation/span-context-from-traceparent.js';
28
+ export { traceparentFromContext } from './propagation/traceparent-from-context.js';
29
+ export { OUTCOME_ATTRIBUTE } from './span/outcome-attribute.js';
30
+ export { withSpan } from './span/with-span.js';
31
+ export { traceUseCases } from './use-case/trace-use-cases.js';
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,GAGjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAErF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAuB,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAsB,MAAM,gCAAgC,CAAC;AACnF,OAA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AC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { JobExecution } from '@ddd-ts-kit/kernel';
2
+ export interface TracedJobOptions {
3
+ /** Name of the job, `<context>.<job>`: the span is `job <name>`. */
4
+ readonly name: string;
5
+ /** Bounded context the job belongs to. */
6
+ readonly context?: string;
7
+ }
8
+ type JobRun = (execution: JobExecution) => Promise<void>;
9
+ /**
10
+ * Wraps the run of a scheduled job: one trace per run, whose root span `job <name>` says the
11
+ * instant the run was due, the attempt and the outcome, and whose children are the commands
12
+ * the job sends. Always a root: a run never continues the trace of whatever armed its timer.
13
+ */
14
+ export declare function tracedJob(run: JobRun, options: TracedJobOptions): JobRun;
15
+ export {};
16
+ //# sourceMappingURL=traced-job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-job.d.ts","sourceRoot":"","sources":["../../src/jobs/traced-job.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKvD,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,KAAK,MAAM,GAAG,CAAC,SAAS,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAkBxE"}
@@ -0,0 +1,25 @@
1
+ import { SpanKind } from '@opentelemetry/api';
2
+ import { workAttributes } from '../local-root/work-attributes.js';
3
+ import { inSpan } from '../span/in-span.js';
4
+ import { OUTCOME_ATTRIBUTE } from '../span/outcome-attribute.js';
5
+ /**
6
+ * Wraps the run of a scheduled job: one trace per run, whose root span `job <name>` says the
7
+ * instant the run was due, the attempt and the outcome, and whose children are the commands
8
+ * the job sends. Always a root: a run never continues the trace of whatever armed its timer.
9
+ */
10
+ export function tracedJob(run, options) {
11
+ return (execution) => {
12
+ const attributes = {
13
+ 'app.job.name': options.name,
14
+ ...(options.context === undefined ? {} : { 'app.context': options.context }),
15
+ 'app.job.scheduled_at': execution.scheduledAt.toISOString(),
16
+ 'app.job.attempt': execution.attempt,
17
+ ...workAttributes(),
18
+ };
19
+ return inSpan({ name: `job ${options.name}`, options: { kind: SpanKind.INTERNAL, root: true, attributes } }, async (span) => {
20
+ await run(execution);
21
+ span.setAttribute(OUTCOME_ATTRIBUTE, 'succeeded');
22
+ });
23
+ };
24
+ }
25
+ //# sourceMappingURL=traced-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traced-job.js","sourceRoot":"","sources":["../../src/jobs/traced-job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAWjE;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,OAAyB;IAC9D,OAAO,CAAC,SAAS,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG;YACjB,cAAc,EAAE,OAAO,CAAC,IAAI;YAC5B,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;YAC5E,sBAAsB,EAAE,SAAS,CAAC,WAAW,CAAC,WAAW,EAAE;YAC3D,iBAAiB,EAAE,SAAS,CAAC,OAAO;YACpC,GAAG,cAAc,EAAE;SACpB,CAAC;QAEF,OAAO,MAAM,CACX,EAAE,IAAI,EAAE,OAAO,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAC7F,KAAK,EAAE,IAAI,EAAE,EAAE;YACb,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;YACrB,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const DROPPED_SPANS_ATTRIBUTE = "app.dependency_spans.dropped";
2
+ /**
3
+ * Counts one more dependency span under the active local root, or refuses it once a cap
4
+ * is reached. A loop of a thousand repository calls must not become a thousand spans.
5
+ */
6
+ export declare function admitDependencySpan(name: string): boolean;
7
+ //# sourceMappingURL=admit-dependency-span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admit-dependency-span.d.ts","sourceRoot":"","sources":["../../src/local-root/admit-dependency-span.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA2BzD"}
@@ -0,0 +1,30 @@
1
+ import { context, trace } from '@opentelemetry/api';
2
+ import { tracingConfiguration } from '../configuration/configure-tracing.js';
3
+ import { correlate } from './correlate.js';
4
+ import { localRoots } from './local-roots.js';
5
+ export const DROPPED_SPANS_ATTRIBUTE = 'app.dependency_spans.dropped';
6
+ /**
7
+ * Counts one more dependency span under the active local root, or refuses it once a cap
8
+ * is reached. A loop of a thousand repository calls must not become a thousand spans.
9
+ */
10
+ export function admitDependencySpan(name) {
11
+ const active = trace.getSpan(context.active());
12
+ const root = active === undefined ? undefined : localRoots.get(active);
13
+ if (root === undefined) {
14
+ return true;
15
+ }
16
+ correlate(root);
17
+ const { maxSpansPerName, maxSpansPerRoot } = tracingConfiguration();
18
+ const sameName = root.perName.get(name) ?? 0;
19
+ if (root.total >= maxSpansPerRoot || sameName >= maxSpansPerName) {
20
+ root.dropped += 1;
21
+ if (root.span.isRecording()) {
22
+ root.span.setAttribute(DROPPED_SPANS_ATTRIBUTE, root.dropped);
23
+ }
24
+ return false;
25
+ }
26
+ root.perName.set(name, sameName + 1);
27
+ root.total += 1;
28
+ return true;
29
+ }
30
+ //# sourceMappingURL=admit-dependency-span.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admit-dependency-span.js","sourceRoot":"","sources":["../../src/local-root/admit-dependency-span.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAEtE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEvE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,IAAI,CAAC,CAAC;IAEhB,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,oBAAoB,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7C,IAAI,IAAI,CAAC,KAAK,IAAI,eAAe,IAAI,QAAQ,IAAI,eAAe,EAAE,CAAC;QACjE,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAElB,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;IAEhB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { LocalRoot } from './local-root.js';
2
+ export declare const CORRELATION_ID_ATTRIBUTE = "app.correlation_id";
3
+ export declare const ORIGIN_ATTRIBUTE = "app.origin";
4
+ /**
5
+ * Names the execution context on the local root, once. Identifiers of the work only: who acts
6
+ * and for which tenant never become span attributes.
7
+ */
8
+ export declare function correlate(root: LocalRoot): void;
9
+ //# sourceMappingURL=correlate.d.ts.map