@composed-di/instrumentation-otel 0.7.0-alpha → 0.8.0-alpha

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/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './otelInstrumentation';
1
+ export * from './otelServiceInstrumentation';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA"}
package/dist/index.js CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./otelInstrumentation"), exports);
17
+ __exportStar(require("./otelServiceInstrumentation"), exports);
18
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C"}
@@ -0,0 +1,31 @@
1
+ import { Tracer } from '@opentelemetry/api';
2
+ import { DisposeContext, OperationSpan, InitializeContext, MethodCallContext, ServiceInstrumentation } from '@composed-di/instrumentation-core';
3
+ export interface OTELInstrumentationOptions {
4
+ /**
5
+ * The tracer used to create spans. Defaults to a tracer obtained from
6
+ * the global tracer provider — the one `NodeSDK` (and therefore
7
+ * `@opentelemetry/auto-instrumentations-node`) registers on startup —
8
+ * so most setups can omit it. The global lookup is lazy: it also works
9
+ * when the instrumentation is constructed before the SDK starts.
10
+ */
11
+ tracer?: Tracer;
12
+ }
13
+ /**
14
+ * A ServiceInstrumentation that records service events as OTEL spans.
15
+ *
16
+ * Arguments and results are recorded (as the
17
+ * `composed_di.service.function.arguments` / `.result` attributes,
18
+ * serialized to JSON) exactly when `instrument()` (inherited from
19
+ * ServiceInstrumentation) delivers them — capture and redaction policy
20
+ * live in the InstrumentOptions, not here.
21
+ */
22
+ export declare class OTELServiceInstrumentation extends ServiceInstrumentation {
23
+ private readonly tracer;
24
+ constructor(options?: OTELInstrumentationOptions);
25
+ onInitialize(context: InitializeContext): OperationSpan;
26
+ onDispose(context: DisposeContext): OperationSpan;
27
+ onMethodCall(context: MethodCallContext): OperationSpan;
28
+ private buildSpan;
29
+ private buildAttributes;
30
+ }
31
+ //# sourceMappingURL=otelServiceInstrumentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otelServiceInstrumentation.d.ts","sourceRoot":"","sources":["../src/otelServiceInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EACP,MAAM,oBAAoB,CAAA;AAM3B,OAAO,EACL,cAAc,EAEd,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,WAAW,0BAA0B;IACzC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;GAQG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAEnB,OAAO,GAAE,0BAA+B;IAMpD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;IAWvD,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa;IAWjD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;IAYvD,OAAO,CAAC,SAAS;IAkCjB,OAAO,CAAC,eAAe;CAuBxB"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OTELServiceInstrumentation = void 0;
4
+ const api_1 = require("@opentelemetry/api");
5
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
6
+ const instrumentation_core_1 = require("@composed-di/instrumentation-core");
7
+ /**
8
+ * A ServiceInstrumentation that records service events as OTEL spans.
9
+ *
10
+ * Arguments and results are recorded (as the
11
+ * `composed_di.service.function.arguments` / `.result` attributes,
12
+ * serialized to JSON) exactly when `instrument()` (inherited from
13
+ * ServiceInstrumentation) delivers them — capture and redaction policy
14
+ * live in the InstrumentOptions, not here.
15
+ */
16
+ class OTELServiceInstrumentation extends instrumentation_core_1.ServiceInstrumentation {
17
+ constructor(options = {}) {
18
+ var _a;
19
+ super();
20
+ this.tracer =
21
+ (_a = options.tracer) !== null && _a !== void 0 ? _a : api_1.trace.getTracer('@composed-di/instrumentation-otel');
22
+ }
23
+ onInitialize(context) {
24
+ const attributes = this.buildAttributes({
25
+ key: context.key,
26
+ event: 'initialize',
27
+ className: 'ServiceFactory',
28
+ methodName: 'initialize',
29
+ });
30
+ const spanName = `ServiceFactory[${context.key.name}].initialize`;
31
+ return this.buildSpan(spanName, attributes);
32
+ }
33
+ onDispose(context) {
34
+ const attributes = this.buildAttributes({
35
+ key: context.key,
36
+ event: 'dispose',
37
+ className: 'ServiceFactory',
38
+ methodName: 'dispose',
39
+ });
40
+ const spanName = `ServiceFactory[${context.key.name}].dispose`;
41
+ return this.buildSpan(spanName, attributes);
42
+ }
43
+ onMethodCall(context) {
44
+ const attributes = this.buildAttributes({
45
+ key: context.key,
46
+ event: 'call',
47
+ className: context.className,
48
+ methodName: context.methodName,
49
+ args: context.args,
50
+ });
51
+ const spanName = attributes[semantic_conventions_1.ATTR_CODE_FUNCTION_NAME];
52
+ return this.buildSpan(spanName, attributes);
53
+ }
54
+ buildSpan(spanName, attributes) {
55
+ const parentContext = api_1.context.active();
56
+ const span = this.tracer.startSpan(spanName, { attributes }, parentContext);
57
+ const spanContext = api_1.trace.setSpan(parentContext, span);
58
+ return {
59
+ run: (fn) => api_1.context.with(spanContext, fn),
60
+ end: (outcome) => {
61
+ if (outcome.type === 'failure') {
62
+ const error = outcome.error;
63
+ span.recordException(error instanceof Error ? error : String(error));
64
+ span.setAttribute(semantic_conventions_1.ATTR_ERROR_TYPE, error instanceof Error
65
+ ? error.name || semantic_conventions_1.ERROR_TYPE_VALUE_OTHER
66
+ : semantic_conventions_1.ERROR_TYPE_VALUE_OTHER);
67
+ span.setStatus({
68
+ code: api_1.SpanStatusCode.ERROR,
69
+ message: error instanceof Error ? error.message : String(error),
70
+ });
71
+ }
72
+ else if ('value' in outcome) {
73
+ // Present exactly when result capture is enabled in the
74
+ // InstrumentOptions; the value arrives already redacted.
75
+ span.setAttribute('composed_di.service.function.result', serialize(outcome.value));
76
+ }
77
+ span.end();
78
+ },
79
+ };
80
+ }
81
+ buildAttributes(params) {
82
+ var _a;
83
+ const attributes = {
84
+ [semantic_conventions_1.ATTR_CODE_FUNCTION_NAME]: `${(_a = params.className) !== null && _a !== void 0 ? _a : params.key.name}.${params.methodName}`,
85
+ 'composed_di.service.key': params.key.name,
86
+ 'composed_di.service.event': params.event,
87
+ };
88
+ // Present exactly when argument capture is enabled in the
89
+ // InstrumentOptions; the args arrive already redacted.
90
+ if (params.args) {
91
+ attributes['composed_di.service.function.arguments'] = serialize(params.args);
92
+ }
93
+ return attributes;
94
+ }
95
+ }
96
+ exports.OTELServiceInstrumentation = OTELServiceInstrumentation;
97
+ function serialize(value) {
98
+ var _a;
99
+ let text;
100
+ try {
101
+ text = (_a = JSON.stringify(value)) !== null && _a !== void 0 ? _a : String(value);
102
+ }
103
+ catch (_b) {
104
+ text = '[unserializable]';
105
+ }
106
+ return text;
107
+ }
108
+ //# sourceMappingURL=otelServiceInstrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otelServiceInstrumentation.js","sourceRoot":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BACJ,CAAC;qBAAM,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;oBAC9B,wDAAwD;oBACxD,yDAAyD;oBACzD,IAAI,CAAC,YAAY,CACf,qCAAqC,EACrC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CACzB,CAAA;gBACH,CAAC;gBACD,IAAI,CAAC,GAAG,EAAE,CAAA;YACZ,CAAC;SACF,CAAA;IACH,CAAC;IAEO,eAAe,CAAC,MAMvB;;QACC,MAAM,UAAU,GAA8B;YAC5C,CAAC,8CAAuB,CAAC,EAAE,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,UAAU,EAAE;YACxF,yBAAyB,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI;YAC1C,2BAA2B,EAAE,MAAM,CAAC,KAAK;SAC1C,CAAA;QAED,0DAA0D;QAC1D,uDAAuD;QACvD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAChB,UAAU,CAAC,wCAAwC,CAAC,GAAG,SAAS,CAC9D,MAAM,CAAC,IAAI,CACZ,CAAA;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AApGD,gEAoGC;AAED,SAAS,SAAS,CAAC,KAAc;;IAC/B,IAAI,IAAY,CAAA;IAChB,IAAI,CAAC;QACH,IAAI,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,mCAAI,MAAM,CAAC,KAAK,CAAC,CAAA;IAC/C,CAAC;IAAC,WAAM,CAAC;QACP,IAAI,GAAG,kBAAkB,CAAA;IAC3B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composed-di/instrumentation-otel",
3
- "version": "0.7.0-alpha",
3
+ "version": "0.8.0-alpha",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "dependency injection",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@opentelemetry/semantic-conventions": "^1.30.0",
40
- "@composed-di/core": "^0.7.0-alpha",
41
- "@composed-di/instrumentation-core": "^0.7.0-alpha"
40
+ "@composed-di/core": "^0.8.0-alpha",
41
+ "@composed-di/instrumentation-core": "^0.8.0-alpha"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@opentelemetry/api": "1.9.1",
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from './otelInstrumentation'
1
+ export * from './otelServiceInstrumentation'
@@ -40,7 +40,7 @@ export interface OTELInstrumentationOptions {
40
40
  * ServiceInstrumentation) delivers them — capture and redaction policy
41
41
  * live in the InstrumentOptions, not here.
42
42
  */
43
- export class OTELInstrumentation extends ServiceInstrumentation {
43
+ export class OTELServiceInstrumentation extends ServiceInstrumentation {
44
44
  private readonly tracer: Tracer
45
45
 
46
46
  constructor(options: OTELInstrumentationOptions = {}) {