@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.
- package/README.md +400 -2
- package/dist/application/trace-application.d.ts +39 -0
- package/dist/application/trace-application.d.ts.map +1 -0
- package/dist/application/trace-application.js +31 -0
- package/dist/application/trace-application.js.map +1 -0
- package/dist/configuration/configure-tracing.d.ts +9 -0
- package/dist/configuration/configure-tracing.d.ts.map +1 -0
- package/dist/configuration/configure-tracing.js +21 -0
- package/dist/configuration/configure-tracing.js.map +1 -0
- package/dist/configuration/default-lifecycle-hooks.d.ts +2 -0
- package/dist/configuration/default-lifecycle-hooks.d.ts.map +1 -0
- package/dist/configuration/default-lifecycle-hooks.js +8 -0
- package/dist/configuration/default-lifecycle-hooks.js.map +1 -0
- package/dist/configuration/tracing-configuration.d.ts +16 -0
- package/dist/configuration/tracing-configuration.d.ts.map +1 -0
- package/dist/configuration/tracing-configuration.js +2 -0
- package/dist/configuration/tracing-configuration.js.map +1 -0
- package/dist/correlation/correlation-id-from-active-span.d.ts +6 -0
- package/dist/correlation/correlation-id-from-active-span.d.ts.map +1 -0
- package/dist/correlation/correlation-id-from-active-span.js +10 -0
- package/dist/correlation/correlation-id-from-active-span.js.map +1 -0
- package/dist/correlation/trace-log-fields.d.ts +13 -0
- package/dist/correlation/trace-log-fields.d.ts.map +1 -0
- package/dist/correlation/trace-log-fields.js +20 -0
- package/dist/correlation/trace-log-fields.js.map +1 -0
- package/dist/correlation/traced-error-reporter.d.ts +9 -0
- package/dist/correlation/traced-error-reporter.d.ts.map +1 -0
- package/dist/correlation/traced-error-reporter.js +23 -0
- package/dist/correlation/traced-error-reporter.js.map +1 -0
- package/dist/dependency/method.d.ts +2 -0
- package/dist/dependency/method.d.ts.map +1 -0
- package/dist/dependency/method.js +2 -0
- package/dist/dependency/method.js.map +1 -0
- package/dist/dependency/proxied.d.ts +8 -0
- package/dist/dependency/proxied.d.ts.map +1 -0
- package/dist/dependency/proxied.js +21 -0
- package/dist/dependency/proxied.js.map +1 -0
- package/dist/dependency/shadowed.d.ts +4 -0
- package/dist/dependency/shadowed.d.ts.map +1 -0
- package/dist/dependency/shadowed.js +14 -0
- package/dist/dependency/shadowed.js.map +1 -0
- package/dist/dependency/trace-bindings.d.ts +25 -0
- package/dist/dependency/trace-bindings.d.ts.map +1 -0
- package/dist/dependency/trace-bindings.js +35 -0
- package/dist/dependency/trace-bindings.js.map +1 -0
- package/dist/dependency/trace-dependency.d.ts +26 -0
- package/dist/dependency/trace-dependency.d.ts.map +1 -0
- package/dist/dependency/trace-dependency.js +56 -0
- package/dist/dependency/trace-dependency.js.map +1 -0
- package/dist/dependency/traceable-methods.d.ts +4 -0
- package/dist/dependency/traceable-methods.d.ts.map +1 -0
- package/dist/dependency/traceable-methods.js +46 -0
- package/dist/dependency/traceable-methods.js.map +1 -0
- package/dist/dependency/traced.d.ts +5 -0
- package/dist/dependency/traced.d.ts.map +1 -0
- package/dist/dependency/traced.js +56 -0
- package/dist/dependency/traced.js.map +1 -0
- package/dist/domain-events/traced-domain-events.d.ts +14 -0
- package/dist/domain-events/traced-domain-events.d.ts.map +1 -0
- package/dist/domain-events/traced-domain-events.js +49 -0
- package/dist/domain-events/traced-domain-events.js.map +1 -0
- package/dist/events/consumer-trace.d.ts +8 -0
- package/dist/events/consumer-trace.d.ts.map +1 -0
- package/dist/events/consumer-trace.js +2 -0
- package/dist/events/consumer-trace.js.map +1 -0
- package/dist/events/messaging-attributes.d.ts +12 -0
- package/dist/events/messaging-attributes.d.ts.map +1 -0
- package/dist/events/messaging-attributes.js +11 -0
- package/dist/events/messaging-attributes.js.map +1 -0
- package/dist/events/traced-consumer.d.ts +22 -0
- package/dist/events/traced-consumer.d.ts.map +1 -0
- package/dist/events/traced-consumer.js +65 -0
- package/dist/events/traced-consumer.js.map +1 -0
- package/dist/events/traced-publisher.d.ts +19 -0
- package/dist/events/traced-publisher.d.ts.map +1 -0
- package/dist/events/traced-publisher.js +69 -0
- package/dist/events/traced-publisher.js.map +1 -0
- package/dist/events/traced-subscriber.d.ts +15 -0
- package/dist/events/traced-subscriber.d.ts.map +1 -0
- package/dist/events/traced-subscriber.js +19 -0
- package/dist/events/traced-subscriber.js.map +1 -0
- package/dist/http/is-noise-path.d.ts +3 -0
- package/dist/http/is-noise-path.d.ts.map +1 -0
- package/dist/http/is-noise-path.js +7 -0
- package/dist/http/is-noise-path.js.map +1 -0
- package/dist/http/is-noise-route.d.ts +6 -0
- package/dist/http/is-noise-route.d.ts.map +1 -0
- package/dist/http/is-noise-route.js +7 -0
- package/dist/http/is-noise-route.js.map +1 -0
- package/dist/http/noise-paths.d.ts +3 -0
- package/dist/http/noise-paths.d.ts.map +1 -0
- package/dist/http/noise-paths.js +15 -0
- package/dist/http/noise-paths.js.map +1 -0
- package/dist/http/traced-routes.d.ts +28 -0
- package/dist/http/traced-routes.d.ts.map +1 -0
- package/dist/http/traced-routes.js +76 -0
- package/dist/http/traced-routes.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/traced-job.d.ts +16 -0
- package/dist/jobs/traced-job.d.ts.map +1 -0
- package/dist/jobs/traced-job.js +25 -0
- package/dist/jobs/traced-job.js.map +1 -0
- package/dist/local-root/admit-dependency-span.d.ts +7 -0
- package/dist/local-root/admit-dependency-span.d.ts.map +1 -0
- package/dist/local-root/admit-dependency-span.js +30 -0
- package/dist/local-root/admit-dependency-span.js.map +1 -0
- package/dist/local-root/correlate.d.ts +9 -0
- package/dist/local-root/correlate.d.ts.map +1 -0
- package/dist/local-root/correlate.js +23 -0
- package/dist/local-root/correlate.js.map +1 -0
- package/dist/local-root/local-root-tracker.d.ts +18 -0
- package/dist/local-root/local-root-tracker.d.ts.map +1 -0
- package/dist/local-root/local-root-tracker.js +26 -0
- package/dist/local-root/local-root-tracker.js.map +1 -0
- package/dist/local-root/local-root.d.ts +11 -0
- package/dist/local-root/local-root.d.ts.map +1 -0
- package/dist/local-root/local-root.js +2 -0
- package/dist/local-root/local-root.js.map +1 -0
- package/dist/local-root/local-roots.d.ts +4 -0
- package/dist/local-root/local-roots.d.ts.map +1 -0
- package/dist/local-root/local-roots.js +4 -0
- package/dist/local-root/local-roots.js.map +1 -0
- package/dist/local-root/work-attributes.d.ts +4 -0
- package/dist/local-root/work-attributes.d.ts.map +1 -0
- package/dist/local-root/work-attributes.js +11 -0
- package/dist/local-root/work-attributes.js.map +1 -0
- package/dist/node/default-instrumentations.d.ts +20 -0
- package/dist/node/default-instrumentations.d.ts.map +1 -0
- package/dist/node/default-instrumentations.js +55 -0
- package/dist/node/default-instrumentations.js.map +1 -0
- package/dist/node/init-tracing.d.ts +41 -0
- package/dist/node/init-tracing.d.ts.map +1 -0
- package/dist/node/init-tracing.js +71 -0
- package/dist/node/init-tracing.js.map +1 -0
- package/dist/node/instrumentations-off.d.ts +6 -0
- package/dist/node/instrumentations-off.d.ts.map +1 -0
- package/dist/node/instrumentations-off.js +39 -0
- package/dist/node/instrumentations-off.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/processors/attribute-allow-list.d.ts +25 -0
- package/dist/processors/attribute-allow-list.d.ts.map +1 -0
- package/dist/processors/attribute-allow-list.js +38 -0
- package/dist/processors/attribute-allow-list.js.map +1 -0
- package/dist/processors/default-allowed-attributes.d.ts +8 -0
- package/dist/processors/default-allowed-attributes.d.ts.map +1 -0
- package/dist/processors/default-allowed-attributes.js +48 -0
- package/dist/processors/default-allowed-attributes.js.map +1 -0
- package/dist/processors/ended-span.d.ts +19 -0
- package/dist/processors/ended-span.d.ts.map +1 -0
- package/dist/processors/ended-span.js +2 -0
- package/dist/processors/ended-span.js.map +1 -0
- package/dist/processors/error-message-scrubber.d.ts +13 -0
- package/dist/processors/error-message-scrubber.d.ts.map +1 -0
- package/dist/processors/error-message-scrubber.js +21 -0
- package/dist/processors/error-message-scrubber.js.map +1 -0
- package/dist/processors/url-secret-span-processor.d.ts +12 -0
- package/dist/processors/url-secret-span-processor.d.ts.map +1 -0
- package/dist/processors/url-secret-span-processor.js +47 -0
- package/dist/processors/url-secret-span-processor.js.map +1 -0
- package/dist/propagation/capture-traceparent.d.ts +3 -0
- package/dist/propagation/capture-traceparent.d.ts.map +1 -0
- package/dist/propagation/capture-traceparent.js +7 -0
- package/dist/propagation/capture-traceparent.js.map +1 -0
- package/dist/propagation/context-with-traceparent.d.ts +4 -0
- package/dist/propagation/context-with-traceparent.d.ts.map +1 -0
- package/dist/propagation/context-with-traceparent.js +8 -0
- package/dist/propagation/context-with-traceparent.js.map +1 -0
- package/dist/propagation/run-with-traceparent.d.ts +6 -0
- package/dist/propagation/run-with-traceparent.d.ts.map +1 -0
- package/dist/propagation/run-with-traceparent.js +10 -0
- package/dist/propagation/run-with-traceparent.js.map +1 -0
- package/dist/propagation/span-context-from-traceparent.d.ts +4 -0
- package/dist/propagation/span-context-from-traceparent.d.ts.map +1 -0
- package/dist/propagation/span-context-from-traceparent.js +23 -0
- package/dist/propagation/span-context-from-traceparent.js.map +1 -0
- package/dist/propagation/traceparent-from-context.d.ts +4 -0
- package/dist/propagation/traceparent-from-context.d.ts.map +1 -0
- package/dist/propagation/traceparent-from-context.js +11 -0
- package/dist/propagation/traceparent-from-context.js.map +1 -0
- package/dist/span/constructor-name.d.ts +3 -0
- package/dist/span/constructor-name.d.ts.map +1 -0
- package/dist/span/constructor-name.js +9 -0
- package/dist/span/constructor-name.js.map +1 -0
- package/dist/span/failed-traces.d.ts +2 -0
- package/dist/span/failed-traces.d.ts.map +1 -0
- package/dist/span/failed-traces.js +3 -0
- package/dist/span/failed-traces.js.map +1 -0
- package/dist/span/in-span.d.ts +12 -0
- package/dist/span/in-span.d.ts.map +1 -0
- package/dist/span/in-span.js +19 -0
- package/dist/span/in-span.js.map +1 -0
- package/dist/span/is-thenable.d.ts +2 -0
- package/dist/span/is-thenable.d.ts.map +1 -0
- package/dist/span/is-thenable.js +7 -0
- package/dist/span/is-thenable.js.map +1 -0
- package/dist/span/mark-span-failed.d.ts +4 -0
- package/dist/span/mark-span-failed.d.ts.map +1 -0
- package/dist/span/mark-span-failed.js +36 -0
- package/dist/span/mark-span-failed.js.map +1 -0
- package/dist/span/outcome-attribute.d.ts +3 -0
- package/dist/span/outcome-attribute.d.ts.map +1 -0
- package/dist/span/outcome-attribute.js +3 -0
- package/dist/span/outcome-attribute.js.map +1 -0
- package/dist/span/refusal-code.d.ts +4 -0
- package/dist/span/refusal-code.d.ts.map +1 -0
- package/dist/span/refusal-code.js +10 -0
- package/dist/span/refusal-code.js.map +1 -0
- package/dist/span/tracer.d.ts +4 -0
- package/dist/span/tracer.d.ts.map +1 -0
- package/dist/span/tracer.js +7 -0
- package/dist/span/tracer.js.map +1 -0
- package/dist/span/with-span.d.ts +9 -0
- package/dist/span/with-span.d.ts.map +1 -0
- package/dist/span/with-span.js +36 -0
- package/dist/span/with-span.js.map +1 -0
- package/dist/testing/expect-span-tree.d.ts +10 -0
- package/dist/testing/expect-span-tree.d.ts.map +1 -0
- package/dist/testing/expect-span-tree.js +29 -0
- package/dist/testing/expect-span-tree.js.map +1 -0
- package/dist/testing/expected-span.d.ts +17 -0
- package/dist/testing/expected-span.d.ts.map +1 -0
- package/dist/testing/expected-span.js +2 -0
- package/dist/testing/expected-span.js.map +1 -0
- package/dist/testing/install-test-tracing.d.ts +23 -0
- package/dist/testing/install-test-tracing.d.ts.map +1 -0
- package/dist/testing/install-test-tracing.js +48 -0
- package/dist/testing/install-test-tracing.js.map +1 -0
- package/dist/testing/render-span-tree.d.ts +8 -0
- package/dist/testing/render-span-tree.d.ts.map +1 -0
- package/dist/testing/render-span-tree.js +23 -0
- package/dist/testing/render-span-tree.js.map +1 -0
- package/dist/testing/span-mismatches.d.ts +5 -0
- package/dist/testing/span-mismatches.d.ts.map +1 -0
- package/dist/testing/span-mismatches.js +34 -0
- package/dist/testing/span-mismatches.js.map +1 -0
- package/dist/testing/span-node.d.ts +13 -0
- package/dist/testing/span-node.d.ts.map +1 -0
- package/dist/testing/span-node.js +2 -0
- package/dist/testing/span-node.js.map +1 -0
- package/dist/testing/span-tree-of.d.ts +8 -0
- package/dist/testing/span-tree-of.d.ts.map +1 -0
- package/dist/testing/span-tree-of.js +34 -0
- package/dist/testing/span-tree-of.js.map +1 -0
- package/dist/testing/start-order.d.ts +12 -0
- package/dist/testing/start-order.d.ts.map +1 -0
- package/dist/testing/start-order.js +17 -0
- package/dist/testing/start-order.js.map +1 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +4 -0
- package/dist/testing.js.map +1 -0
- package/dist/use-case/trace-use-cases.d.ts +10 -0
- package/dist/use-case/trace-use-cases.d.ts.map +1 -0
- package/dist/use-case/trace-use-cases.js +41 -0
- package/dist/use-case/trace-use-cases.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isSpanContextValid, trace } from '@opentelemetry/api';
|
|
2
|
+
import { logFieldsOf } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { tracingConfiguration } from '../configuration/configure-tracing.js';
|
|
4
|
+
/**
|
|
5
|
+
* Fields for a logger mixin (pino `mixin`, winston format...): the trace and span ids inside a
|
|
6
|
+
* span, and, inside the execution scope given here or to `configureTracing`, the log fields of
|
|
7
|
+
* the execution context (`logFieldsOf`: correlation, causation, origin, actor and tenant ids).
|
|
8
|
+
* Empty outside of both.
|
|
9
|
+
*/
|
|
10
|
+
export function traceLogFields(scope) {
|
|
11
|
+
const execution = (scope ?? tracingConfiguration().executionScope)?.current();
|
|
12
|
+
const spanContext = trace.getActiveSpan()?.spanContext();
|
|
13
|
+
return {
|
|
14
|
+
...(execution === undefined ? {} : logFieldsOf(execution)),
|
|
15
|
+
...(spanContext !== undefined && isSpanContextValid(spanContext)
|
|
16
|
+
? { trace_id: spanContext.traceId, span_id: spanContext.spanId }
|
|
17
|
+
: {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=trace-log-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-log-fields.js","sourceRoot":"","sources":["../../src/correlation/trace-log-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAuC,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAO7E;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB;IACnD,MAAM,SAAS,GAAG,CAAC,KAAK,IAAI,oBAAoB,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;IAC9E,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC;IAEzD,OAAO;QACL,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC1D,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI,kBAAkB,CAAC,WAAW,CAAC;YAC9D,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE;YAChE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ErrorReporter } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/**
|
|
3
|
+
* Decorates an error reporter: a report that names no trace takes the one the failure
|
|
4
|
+
* happened in, so the error tracker leads to the trace. That is the active trace, or, for a
|
|
5
|
+
* failure reported once its spans are over (a job, a buried event), the trace of the span
|
|
6
|
+
* that saw the error first.
|
|
7
|
+
*/
|
|
8
|
+
export declare function tracedErrorReporter(reporter: ErrorReporter): ErrorReporter;
|
|
9
|
+
//# sourceMappingURL=traced-error-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-error-reporter.d.ts","sourceRoot":"","sources":["../../src/correlation/traced-error-reporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,CAS1E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isSpanContextValid, trace } from '@opentelemetry/api';
|
|
2
|
+
import { failedTraces } from '../span/failed-traces.js';
|
|
3
|
+
/**
|
|
4
|
+
* Decorates an error reporter: a report that names no trace takes the one the failure
|
|
5
|
+
* happened in, so the error tracker leads to the trace. That is the active trace, or, for a
|
|
6
|
+
* failure reported once its spans are over (a job, a buried event), the trace of the span
|
|
7
|
+
* that saw the error first.
|
|
8
|
+
*/
|
|
9
|
+
export function tracedErrorReporter(reporter) {
|
|
10
|
+
return {
|
|
11
|
+
report(error, report) {
|
|
12
|
+
const traceId = report.traceId ?? traceOf(error);
|
|
13
|
+
reporter.report(error, traceId === undefined ? report : { ...report, traceId });
|
|
14
|
+
},
|
|
15
|
+
flush: (timeoutMs) => reporter.flush(timeoutMs),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function traceOf(error) {
|
|
19
|
+
const failedIn = typeof error === 'object' && error !== null ? failedTraces.get(error) : undefined;
|
|
20
|
+
const active = trace.getActiveSpan()?.spanContext();
|
|
21
|
+
return failedIn ?? (active !== undefined && isSpanContextValid(active) ? active.traceId : undefined);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=traced-error-reporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-error-reporter.js","sourceRoot":"","sources":["../../src/correlation/traced-error-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAuB;IACzD,OAAO;QACL,MAAM,CAAC,KAAK,EAAE,MAAM;YAClB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;YAEjD,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,KAAK,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;KAChD,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnG,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC;IAEpD,OAAO,QAAQ,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AACvG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../src/dependency/method.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method.js","sourceRoot":"","sources":["../../src/dependency/method.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Method } from './method.js';
|
|
2
|
+
/**
|
|
3
|
+
* A sealed or frozen instance cannot receive own methods, so it is fronted by a proxy.
|
|
4
|
+
* Methods and getters run with the real instance as `this`: a proxy is not the object a
|
|
5
|
+
* built-in (a `Map`, a `Date`) or a class with hard-private members accepts as receiver.
|
|
6
|
+
*/
|
|
7
|
+
export declare function proxied<T extends object>(instance: T, wrappers: ReadonlyMap<string, Method>): T;
|
|
8
|
+
//# sourceMappingURL=proxied.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxied.d.ts","sourceRoot":"","sources":["../../src/dependency/proxied.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAkB/F"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sealed or frozen instance cannot receive own methods, so it is fronted by a proxy.
|
|
3
|
+
* Methods and getters run with the real instance as `this`: a proxy is not the object a
|
|
4
|
+
* built-in (a `Map`, a `Date`) or a class with hard-private members accepts as receiver.
|
|
5
|
+
*/
|
|
6
|
+
export function proxied(instance, wrappers) {
|
|
7
|
+
const bound = new Map();
|
|
8
|
+
for (const [name, wrapper] of wrappers) {
|
|
9
|
+
bound.set(name, function (...args) {
|
|
10
|
+
return wrapper.apply(this === proxy ? instance : this, args);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const proxy = new Proxy(instance, {
|
|
14
|
+
get(target, property) {
|
|
15
|
+
const method = typeof property === 'string' ? bound.get(property) : undefined;
|
|
16
|
+
return method ?? Reflect.get(target, property, target);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return proxy;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=proxied.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxied.js","sourceRoot":"","sources":["../../src/dependency/proxied.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAmB,QAAW,EAAE,QAAqC;IAC1F,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAExC,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;QACvC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,UAAyB,GAAG,IAAe;YACzD,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,GAAM,IAAI,KAAK,CAAC,QAAQ,EAAE;QACnC,GAAG,CAAC,MAAM,EAAE,QAAQ;YAClB,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAE9E,OAAO,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Method } from './method.js';
|
|
2
|
+
/** The instance itself, its traced methods defined over the ones it had or inherited. */
|
|
3
|
+
export declare function shadowed<T extends object>(instance: T, wrappers: ReadonlyMap<string, Method>): T;
|
|
4
|
+
//# sourceMappingURL=shadowed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadowed.d.ts","sourceRoot":"","sources":["../../src/dependency/shadowed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAahG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The instance itself, its traced methods defined over the ones it had or inherited. */
|
|
2
|
+
export function shadowed(instance, wrappers) {
|
|
3
|
+
for (const [name, wrapper] of wrappers) {
|
|
4
|
+
const own = Object.getOwnPropertyDescriptor(instance, name);
|
|
5
|
+
Object.defineProperty(instance, name, {
|
|
6
|
+
value: wrapper,
|
|
7
|
+
writable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
enumerable: own?.enumerable ?? false,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return instance;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=shadowed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadowed.js","sourceRoot":"","sources":["../../src/dependency/shadowed.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,UAAU,QAAQ,CAAmB,QAAW,EAAE,QAAqC;IAC3F,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAE5D,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE;YACpC,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,GAAG,EAAE,UAAU,IAAI,KAAK;SACrC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DependencyKind } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { type Token } from '@ddd-ts-kit/kernel/declarations';
|
|
3
|
+
/**
|
|
4
|
+
* What an application says about the binding an instance comes from: the `decorate` hook of
|
|
5
|
+
* `createApplication` and a binding aspect both fit.
|
|
6
|
+
*/
|
|
7
|
+
export interface TracedBinding {
|
|
8
|
+
/** Name of the module that declared the binding. */
|
|
9
|
+
readonly context: string;
|
|
10
|
+
/** The role the binding was declared with. A binding without one is not traced. */
|
|
11
|
+
readonly kind?: DependencyKind;
|
|
12
|
+
/** The port the binding is made under, or its description. */
|
|
13
|
+
readonly token?: Token<unknown> | string;
|
|
14
|
+
/** The bound class, when the application knows it. */
|
|
15
|
+
readonly className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Traces the bindings of an application, as a `decorate` hook or as the `binding` of
|
|
19
|
+
* `traceApplication()`: every instance of a repository, a gateway, an external adapter, a
|
|
20
|
+
* publisher or a domain event handler is wrapped by `traceDependency` under the name of its
|
|
21
|
+
* context and of its port. Use cases, consumers and jobs are left alone, since each already
|
|
22
|
+
* has its span; so is a binding without kind.
|
|
23
|
+
*/
|
|
24
|
+
export declare function traceBindings(): <T>(instance: T, binding: TracedBinding) => T;
|
|
25
|
+
//# sourceMappingURL=trace-bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-bindings.d.ts","sourceRoot":"","sources":["../../src/dependency/trace-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAiB,KAAK,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAG5E;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC;IAC/B,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IACzC,sDAAsD;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAQD;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,KAAK,CAAC,CAiB7E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describeToken } from '@ddd-ts-kit/kernel/declarations';
|
|
2
|
+
import { traceDependency } from './trace-dependency.js';
|
|
3
|
+
/** Each has a span of its own kind already: the use case middleware, `process <consumer>`, `job <name>`. */
|
|
4
|
+
const TRACED_ELSEWHERE = new Set(['use-case', 'consumer', 'job']);
|
|
5
|
+
/** Named after their class: the token of a handler is the handler. */
|
|
6
|
+
const NAMED_BY_CLASS = new Set(['domain-event-handler']);
|
|
7
|
+
/**
|
|
8
|
+
* Traces the bindings of an application, as a `decorate` hook or as the `binding` of
|
|
9
|
+
* `traceApplication()`: every instance of a repository, a gateway, an external adapter, a
|
|
10
|
+
* publisher or a domain event handler is wrapped by `traceDependency` under the name of its
|
|
11
|
+
* context and of its port. Use cases, consumers and jobs are left alone, since each already
|
|
12
|
+
* has its span; so is a binding without kind.
|
|
13
|
+
*/
|
|
14
|
+
export function traceBindings() {
|
|
15
|
+
return (instance, binding) => {
|
|
16
|
+
const { context, kind, className } = binding;
|
|
17
|
+
if (kind === undefined || TRACED_ELSEWHERE.has(kind) || typeof instance !== 'object' || instance === null) {
|
|
18
|
+
return instance;
|
|
19
|
+
}
|
|
20
|
+
const port = NAMED_BY_CLASS.has(kind) ? undefined : portOf(binding.token);
|
|
21
|
+
return traceDependency(instance, {
|
|
22
|
+
kind,
|
|
23
|
+
context,
|
|
24
|
+
...(className === undefined ? {} : { className }),
|
|
25
|
+
...(port === undefined ? {} : { port }),
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function portOf(token) {
|
|
30
|
+
if (token === undefined) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return typeof token === 'string' ? token : describeToken(token);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=trace-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-bindings.js","sourceRoot":"","sources":["../../src/dependency/trace-bindings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAc,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAiBxD,4GAA4G;AAC5G,MAAM,gBAAgB,GAAgC,IAAI,GAAG,CAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;AAE/G,sEAAsE;AACtE,MAAM,cAAc,GAAgC,IAAI,GAAG,CAAiB,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAEtG;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;QAC3B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAE7C,IAAI,IAAI,KAAK,SAAS,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC1G,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE1E,OAAO,eAAe,CAAC,QAAQ,EAAE;YAC/B,IAAI;YACJ,OAAO;YACP,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;YACjD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;SACxC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,KAA6B;IAC3C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DependencyKind } from '@ddd-ts-kit/kernel';
|
|
2
|
+
export interface TraceDependencyOptions {
|
|
3
|
+
readonly kind: DependencyKind;
|
|
4
|
+
/** Defaults to the constructor name; set it when the build minifies class names. */
|
|
5
|
+
readonly className?: string;
|
|
6
|
+
/** Bounded context owning the dependency. */
|
|
7
|
+
readonly context?: string;
|
|
8
|
+
/** Name of the port the instance is bound under: it names the spans in place of the class. */
|
|
9
|
+
readonly port?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wraps the async methods of an adapter so each call is one span named
|
|
13
|
+
* `<kind> <Port>.<method>` (`repository OrderRepository.save`), after the port when it is
|
|
14
|
+
* known and after the class otherwise; the handler of a domain event is `handler <ClassName>`.
|
|
15
|
+
* Meant for the composition root only: the wrapped class imports nothing from this package.
|
|
16
|
+
*
|
|
17
|
+
* The methods are shadowed on the instance itself, so the returned value is the same
|
|
18
|
+
* object: `instanceof`, `this` and private members keep working, and wrapping twice
|
|
19
|
+
* is a no-op. A span never carries arguments, results or error messages.
|
|
20
|
+
*
|
|
21
|
+
* A method declared `async` is traced from its first call. Any other method is traced
|
|
22
|
+
* once it has been seen returning a thenable (that first call is not traced). A function
|
|
23
|
+
* held in a field, `private` or not, is a method like any other.
|
|
24
|
+
*/
|
|
25
|
+
export declare function traceDependency<T extends object>(instance: T, options: TraceDependencyOptions): T;
|
|
26
|
+
//# sourceMappingURL=trace-dependency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-dependency.d.ts","sourceRoot":"","sources":["../../src/dependency/trace-dependency.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASzD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,GAAG,CAAC,CAYjG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { tracingConfiguration } from '../configuration/configure-tracing.js';
|
|
2
|
+
import { constructorName } from '../span/constructor-name.js';
|
|
3
|
+
import { proxied } from './proxied.js';
|
|
4
|
+
import { shadowed } from './shadowed.js';
|
|
5
|
+
import { traceableMethods } from './traceable-methods.js';
|
|
6
|
+
import { traced } from './traced.js';
|
|
7
|
+
const wrapped = new WeakSet();
|
|
8
|
+
/**
|
|
9
|
+
* Wraps the async methods of an adapter so each call is one span named
|
|
10
|
+
* `<kind> <Port>.<method>` (`repository OrderRepository.save`), after the port when it is
|
|
11
|
+
* known and after the class otherwise; the handler of a domain event is `handler <ClassName>`.
|
|
12
|
+
* Meant for the composition root only: the wrapped class imports nothing from this package.
|
|
13
|
+
*
|
|
14
|
+
* The methods are shadowed on the instance itself, so the returned value is the same
|
|
15
|
+
* object: `instanceof`, `this` and private members keep working, and wrapping twice
|
|
16
|
+
* is a no-op. A span never carries arguments, results or error messages.
|
|
17
|
+
*
|
|
18
|
+
* A method declared `async` is traced from its first call. Any other method is traced
|
|
19
|
+
* once it has been seen returning a thenable (that first call is not traced). A function
|
|
20
|
+
* held in a field, `private` or not, is a method like any other.
|
|
21
|
+
*/
|
|
22
|
+
export function traceDependency(instance, options) {
|
|
23
|
+
if (wrapped.has(instance)) {
|
|
24
|
+
return instance;
|
|
25
|
+
}
|
|
26
|
+
const wrappers = tracedMethods(instance, options);
|
|
27
|
+
const result = Object.isExtensible(instance) ? shadowed(instance, wrappers) : proxied(instance, wrappers);
|
|
28
|
+
wrapped.add(result);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function tracedMethods(instance, options) {
|
|
32
|
+
const className = options.className ?? ownClassName(instance);
|
|
33
|
+
const skipped = new Set(tracingConfiguration().lifecycleHooks);
|
|
34
|
+
const wrappers = new Map();
|
|
35
|
+
for (const [name, method] of traceableMethods(instance, skipped)) {
|
|
36
|
+
const attributes = {
|
|
37
|
+
'code.namespace': className,
|
|
38
|
+
'code.function': name,
|
|
39
|
+
'app.dependency.kind': options.kind,
|
|
40
|
+
...(options.context === undefined ? {} : { 'app.context': options.context }),
|
|
41
|
+
};
|
|
42
|
+
wrappers.set(name, traced(method, spanName({ ...options, className }, name), attributes));
|
|
43
|
+
}
|
|
44
|
+
return wrappers;
|
|
45
|
+
}
|
|
46
|
+
function spanName(options, method) {
|
|
47
|
+
if (options.kind === 'domain-event-handler') {
|
|
48
|
+
return method === 'handle' ? `handler ${options.className}` : `handler ${options.className}.${method}`;
|
|
49
|
+
}
|
|
50
|
+
return `${options.kind} ${options.port ?? options.className}.${method}`;
|
|
51
|
+
}
|
|
52
|
+
function ownClassName(instance) {
|
|
53
|
+
const name = constructorName(instance);
|
|
54
|
+
return typeof name === 'string' ? name : 'Object';
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=trace-dependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-dependency.js","sourceRoot":"","sources":["../../src/dependency/trace-dependency.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAYrC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAU,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAAmB,QAAW,EAAE,OAA+B;IAC5F,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAElD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE1G,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEpB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,OAA+B;IACtE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAA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,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceable-methods.d.ts","sourceRoot":"","sources":["../../src/dependency/traceable-methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBpG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const UNTRACEABLE_CONSTRUCTORS = new Set(['GeneratorFunction', 'AsyncGeneratorFunction']);
|
|
2
|
+
/** Own and inherited methods, without invoking any getter. */
|
|
3
|
+
export function traceableMethods(instance, skipped) {
|
|
4
|
+
const methods = new Map();
|
|
5
|
+
for (const owner of prototypeChain(instance)) {
|
|
6
|
+
for (const name of Object.getOwnPropertyNames(owner)) {
|
|
7
|
+
if (name === 'constructor' || skipped.has(name) || methods.has(name)) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const candidate = methodHeld(owner, name, instance);
|
|
11
|
+
if (isTraceable(candidate)) {
|
|
12
|
+
methods.set(name, candidate);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return methods;
|
|
17
|
+
}
|
|
18
|
+
/** What the instance answers for a name its owner holds a function under, `undefined` for anything else. */
|
|
19
|
+
function methodHeld(owner, name, instance) {
|
|
20
|
+
const descriptor = Object.getOwnPropertyDescriptor(owner, name);
|
|
21
|
+
// A read-only own property cannot be shadowed, neither in place nor through a proxy.
|
|
22
|
+
if (descriptor === undefined || (owner === instance && isReadOnly(descriptor))) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
if (typeof descriptor.value !== 'function') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// Read through the instance: a proxy put in front of it by an aspect answers its own wrapper.
|
|
29
|
+
return Reflect.get(instance, name);
|
|
30
|
+
}
|
|
31
|
+
function prototypeChain(instance) {
|
|
32
|
+
const chain = [];
|
|
33
|
+
for (let owner = instance; owner !== null && owner !== Object.prototype && owner !== Function.prototype; owner = Reflect.getPrototypeOf(owner)) {
|
|
34
|
+
chain.push(owner);
|
|
35
|
+
}
|
|
36
|
+
return chain;
|
|
37
|
+
}
|
|
38
|
+
function isReadOnly(descriptor) {
|
|
39
|
+
return !descriptor.writable && !descriptor.configurable;
|
|
40
|
+
}
|
|
41
|
+
function isTraceable(value) {
|
|
42
|
+
return (typeof value === 'function' &&
|
|
43
|
+
!UNTRACEABLE_CONSTRUCTORS.has(value.constructor.name) &&
|
|
44
|
+
!Function.prototype.toString.call(value).startsWith('class'));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=traceable-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceable-methods.js","sourceRoot":"","sources":["../../src/dependency/traceable-methods.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,wBAAwB,CAAC,CAAC,CAAC;AAE1F,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,OAA4B;IAC7E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,KAAK,MAAM,KAAK,IAAI,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,IAAI,IAAI,KAAK,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrE,S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,YAAY,CAAC;AAC1D,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,CACL,OAAO,KAAK,KAAK,UAAU;QAC3B,CAAC,wBAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;QACrD,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Attributes } from '@opentelemetry/api';
|
|
2
|
+
import type { Method } from './method.js';
|
|
3
|
+
/** The method that runs `original` in a span of the given name, once it is known to be async. */
|
|
4
|
+
export declare function traced(original: Method, spanName: string, attributes: Attributes): Method;
|
|
5
|
+
//# sourceMappingURL=traced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.d.ts","sourceRoot":"","sources":["../../src/dependency/traced.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAK/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,iGAAiG;AACjG,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAoBzF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SpanKind, context, trace } from '@opentelemetry/api';
|
|
2
|
+
import { admitDependencySpan } from '../local-root/admit-dependency-span.js';
|
|
3
|
+
import { isThenable } from '../span/is-thenable.js';
|
|
4
|
+
import { markSpanFailed } from '../span/mark-span-failed.js';
|
|
5
|
+
import { tracer } from '../span/tracer.js';
|
|
6
|
+
// Shared by every instance of a class: one call returning a thenable teaches them all.
|
|
7
|
+
const learnedAsync = new WeakSet();
|
|
8
|
+
/** The method that runs `original` in a span of the given name, once it is known to be async. */
|
|
9
|
+
export function traced(original, spanName, attributes) {
|
|
10
|
+
const declaredAsync = original.constructor.name === 'AsyncFunction';
|
|
11
|
+
const wrapper = function (...args) {
|
|
12
|
+
const call = () => original.apply(this, args);
|
|
13
|
+
if (!declaredAsync && !learnedAsync.has(original)) {
|
|
14
|
+
return learningAsync(original, call);
|
|
15
|
+
}
|
|
16
|
+
if (!admitDependencySpan(spanName)) {
|
|
17
|
+
return call();
|
|
18
|
+
}
|
|
19
|
+
return inSpan(call, spanName, attributes);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(wrapper, 'name', { value: original.name, configurable: true });
|
|
22
|
+
return wrapper;
|
|
23
|
+
}
|
|
24
|
+
function learningAsync(original, call) {
|
|
25
|
+
const result = call();
|
|
26
|
+
if (isThenable(result)) {
|
|
27
|
+
learnedAsync.add(original);
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function inSpan(call, spanName, attributes) {
|
|
32
|
+
const parent = context.active();
|
|
33
|
+
const span = tracer().startSpan(spanName, { kind: SpanKind.INTERNAL, attributes }, parent);
|
|
34
|
+
let result;
|
|
35
|
+
try {
|
|
36
|
+
result = context.with(trace.setSpan(parent, span), call);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
markSpanFailed(span, error);
|
|
40
|
+
span.end();
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
if (!isThenable(result)) {
|
|
44
|
+
span.end();
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
return result.then((value) => {
|
|
48
|
+
span.end();
|
|
49
|
+
return value;
|
|
50
|
+
}, (error) => {
|
|
51
|
+
markSpanFailed(span, error);
|
|
52
|
+
span.end();
|
|
53
|
+
throw error;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=traced.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.js","sourceRoot":"","sources":["../../src/dependency/traced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atcher } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/**
|
|
3
|
+
* Decorates a dispatcher: each event is dispatched in a span `domain-event <name>`, and the
|
|
4
|
+
* handlers it reaches are its children. Never the aggregate id nor anything the event carries.
|
|
5
|
+
*
|
|
6
|
+
* At the end of a unit of work the events are under one span `unit-of-work before-commit`,
|
|
7
|
+
* which follows the saves under the span of the command: the trace shows that the handlers ran
|
|
8
|
+
* after every save and before the commit. What their handlers recorded in turn is under a second
|
|
9
|
+
* such span. Once the unit of work has committed, the events that have an `after-commit` handler
|
|
10
|
+
* are under `unit-of-work after-commit`, in the same trace. Outside of a unit of work the events
|
|
11
|
+
* stay under the save that dispatched them. The spans count against the caps of the local root.
|
|
12
|
+
*/
|
|
13
|
+
export declare function tracedDomainEvents(dispatcher: DomainEventDispatcher): DomainEventDispatcher;
|
|
14
|
+
//# sourceMappingURL=traced-domain-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-domain-events.d.ts","sourceRoot":"","sources":["../../src/domain-events/traced-domain-events.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,oBAAoB,CAAC;AAI5B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,qBAAqB,GAAG,qBAAqB,CAkB3F"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
2
|
+
import { unitOfWorkStage, } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { admitDependencySpan } from '../local-root/admit-dependency-span.js';
|
|
4
|
+
import { inSpan } from '../span/in-span.js';
|
|
5
|
+
/**
|
|
6
|
+
* Decorates a dispatcher: each event is dispatched in a span `domain-event <name>`, and the
|
|
7
|
+
* handlers it reaches are its children. Never the aggregate id nor anything the event carries.
|
|
8
|
+
*
|
|
9
|
+
* At the end of a unit of work the events are under one span `unit-of-work before-commit`,
|
|
10
|
+
* which follows the saves under the span of the command: the trace shows that the handlers ran
|
|
11
|
+
* after every save and before the commit. What their handlers recorded in turn is under a second
|
|
12
|
+
* such span. Once the unit of work has committed, the events that have an `after-commit` handler
|
|
13
|
+
* are under `unit-of-work after-commit`, in the same trace. Outside of a unit of work the events
|
|
14
|
+
* stay under the save that dispatched them. The spans count against the caps of the local root.
|
|
15
|
+
*/
|
|
16
|
+
export function tracedDomainEvents(dispatcher) {
|
|
17
|
+
const handledAfterCommit = new Set();
|
|
18
|
+
return {
|
|
19
|
+
on: (name, handler, subscription) => {
|
|
20
|
+
if (subscription?.phase === 'after-commit') {
|
|
21
|
+
handledAfterCommit.add(name);
|
|
22
|
+
}
|
|
23
|
+
dispatcher.on(name, handler, subscription);
|
|
24
|
+
},
|
|
25
|
+
dispatch(events, phase = 'before-commit') {
|
|
26
|
+
const shown = phase === 'before-commit' ? events : events.filter((event) => handledAfterCommit.has(event.name));
|
|
27
|
+
const each = () => dispatchedEach(events, { dispatcher, phase, shown });
|
|
28
|
+
return shown.length > 0 && unitOfWorkStage() === phase ? underThePhase(phase, each) : each();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function underThePhase(phase, work) {
|
|
33
|
+
const name = `unit-of-work ${phase}`;
|
|
34
|
+
return admitDependencySpan(name) ? inSpan({ name, options: { kind: SpanKind.INTERNAL } }, work) : work();
|
|
35
|
+
}
|
|
36
|
+
async function dispatchedEach(events, dispatch) {
|
|
37
|
+
for (const event of events) {
|
|
38
|
+
await dispatched(event, dispatch);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function dispatched(event, { dispatcher, phase, shown }) {
|
|
42
|
+
const name = `domain-event ${event.name}`;
|
|
43
|
+
if (!shown.includes(event) || !admitDependencySpan(name)) {
|
|
44
|
+
return dispatcher.dispatch([event], phase);
|
|
45
|
+
}
|
|
46
|
+
const options = { kind: SpanKind.INTERNAL, attributes: { 'app.domain_event.name': event.name } };
|
|
47
|
+
return inSpan({ name, options }, () => dispatcher.dispatch([event], phase));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=traced-domain-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced-domain-events.js","sourceRoot":"","sources":["../../src/domain-events/traced-domain-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EACL,eAAe,GAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAiC;IAClE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C,OAAO;QACL,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;YAClC,IAAI,YAAY,EAAE,KAAK,KAAK,cAAc,EAAE,CAAC;gBAC3C,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YAED,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAC7C,CAAC;QACD,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,eAAe;YACtC,MAAM,KAAK,GAAG,KAAK,KAAK,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YAChH,MAAM,IAAI,GAAG,GAAkB,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAEvF,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,EAAE,KA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AAK,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the span of a consumed event relates to the one that published it. `continue`: its
|
|
3
|
+
* child, in the same trace, so one action reads end to end in one place. `link`: the root of
|
|
4
|
+
* a new trace that links to it, for a system whose traces would otherwise never end (fan-out
|
|
5
|
+
* to many consumers, long retry chains).
|
|
6
|
+
*/
|
|
7
|
+
export type ConsumerTrace = 'continue' | 'link';
|
|
8
|
+
//# sourceMappingURL=consumer-trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-trace.d.ts","sourceRoot":"","sources":["../../src/events/consumer-trace.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-trace.js","sourceRoot":"","sources":["../../src/events/consumer-trace.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Attributes } from '@opentelemetry/api';
|
|
2
|
+
import type { IntegrationEvent } from '@ddd-ts-kit/kernel';
|
|
3
|
+
export interface MessagingOperation {
|
|
4
|
+
/** What the kit calls it: `publish`, `append`, `process`. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
/** The operation type of the messaging conventions: `send`, `create`, `process`. */
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly system?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** The payload never becomes an attribute: only the routing key and the event id. */
|
|
11
|
+
export declare function messagingAttributes(operation: MessagingOperation, event: IntegrationEvent): Attributes;
|
|
12
|
+
//# sourceMappingURL=messaging-attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging-attributes.d.ts","sourceRoot":"","sources":["../../src/events/messaging-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,kBAAkB,EAAE,KAAK,EAAE,gBAAgB,GAAG,UAAU,CAQtG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The payload never becomes an attribute: only the routing key and the event id. */
|
|
2
|
+
export function messagingAttributes(operation, event) {
|
|
3
|
+
return {
|
|
4
|
+
...(operation.system === undefined ? {} : { 'messaging.system': operation.system }),
|
|
5
|
+
'messaging.operation.name': operation.name,
|
|
6
|
+
'messaging.operation.type': operation.type,
|
|
7
|
+
'messaging.destination.name': event.type,
|
|
8
|
+
'messaging.message.id': event.id,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=messaging-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messaging-attributes.js","sourceRoot":"","sources":["../../src/events/messaging-attributes.ts"],"names":[],"mappings":"AAWA,qFAAqF;AACrF,MAAM,UAAU,mBAAmB,CAAC,SAA6B,EAAE,KAAuB;IACxF,OAAO;QACL,GAAG,CAAC,SAAS,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;QACnF,0BAA0B,EAAE,SAAS,CAAC,IAAI;QAC1C,0BAA0B,EAAE,SAAS,CAAC,IAAI;QAC1C,4BAA4B,EAAE,KAAK,CAAC,IAAI;QACxC,sBAAsB,EAAE,KAAK,CAAC,EAAE;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IntegrationEventCallback } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { ConsumerTrace } from './consumer-trace.js';
|
|
3
|
+
export interface TracedConsumerOptions {
|
|
4
|
+
/** Stable name of the consumer: the span is `process <consumer>`. Without it, `process <type>`. */
|
|
5
|
+
readonly consumer?: string;
|
|
6
|
+
/** Bounded context of the consumer. */
|
|
7
|
+
readonly context?: string;
|
|
8
|
+
/** Default `continue`. */
|
|
9
|
+
readonly trace?: ConsumerTrace;
|
|
10
|
+
/** The transport, when the provider does not say it with each delivery. */
|
|
11
|
+
readonly system?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const ATTEMPT_ATTRIBUTE = "app.messaging.attempt";
|
|
14
|
+
/**
|
|
15
|
+
* Wraps what a provider calls at each delivery: every attempt runs in its own CONSUMER span,
|
|
16
|
+
* which says which attempt it is, so a redelivery reads as one. A failed attempt is an error
|
|
17
|
+
* with the code of what was thrown; the attempt after which the provider gives the event up
|
|
18
|
+
* says `dead-lettered`. The span starts the unit of work: it carries the correlation id of the
|
|
19
|
+
* event. Never the payload.
|
|
20
|
+
*/
|
|
21
|
+
export declare function tracedConsumer(handler: IntegrationEventCallback, options?: TracedConsumerOptions): IntegrationEventCallback;
|
|
22
|
+
//# sourceMappingURL=traced-consumer.d.ts.map
|