@composed-di/instrumentation-otel 0.6.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"}
@@ -1,5 +1,5 @@
1
1
  import { Tracer } from '@opentelemetry/api';
2
- import { DisposeContext, EventSpan, InitializeContext, MethodCallContext, ServiceInstrumentation } from '@composed-di/instrumentation-core';
2
+ import { DisposeContext, OperationSpan, InitializeContext, MethodCallContext, ServiceInstrumentation } from '@composed-di/instrumentation-core';
3
3
  export interface OTELInstrumentationOptions {
4
4
  /**
5
5
  * The tracer used to create spans. Defaults to a tracer obtained from
@@ -15,15 +15,16 @@ export interface OTELInstrumentationOptions {
15
15
  *
16
16
  * Arguments and results are recorded (as the
17
17
  * `composed_di.service.function.arguments` / `.result` attributes,
18
- * serialized to JSON) exactly when `instrument()` delivers them — capture
19
- * and redaction policy live in the InstrumentOptions, not here.
18
+ * serialized to JSON) exactly when `instrument()` (inherited from
19
+ * ServiceInstrumentation) delivers them capture and redaction policy
20
+ * live in the InstrumentOptions, not here.
20
21
  */
21
- export declare class OTELInstrumentation implements ServiceInstrumentation {
22
+ export declare class OTELInstrumentation extends ServiceInstrumentation {
22
23
  private readonly tracer;
23
24
  constructor(options?: OTELInstrumentationOptions);
24
- onInitialize(context: InitializeContext): EventSpan;
25
- onDispose(context: DisposeContext): EventSpan;
26
- onMethodCall(context: MethodCallContext): EventSpan;
25
+ onInitialize(context: InitializeContext): OperationSpan;
26
+ onDispose(context: DisposeContext): OperationSpan;
27
+ onMethodCall(context: MethodCallContext): OperationSpan;
27
28
  private buildSpan;
28
29
  private buildAttributes;
29
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"otelInstrumentation.d.ts","sourceRoot":"","sources":["../src/otelInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EACP,MAAM,oBAAoB,CAAA;AAM3B,OAAO,EACL,cAAc,EAEd,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAG1C,MAAM,WAAW,0BAA0B;IACzC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,mBAAoB,YAAW,sBAAsB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAEnB,OAAO,GAAE,0BAA+B;IAKpD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS;IAWnD,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS;IAW7C,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS;IAYnD,OAAO,CAAC,SAAS;IAkCjB,OAAO,CAAC,eAAe;CAuBxB"}
1
+ {"version":3,"file":"otelInstrumentation.d.ts","sourceRoot":"","sources":["../src/otelInstrumentation.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,mBAAoB,SAAQ,sBAAsB;IAC7D,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"}
@@ -3,17 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OTELInstrumentation = void 0;
4
4
  const api_1 = require("@opentelemetry/api");
5
5
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
6
+ const instrumentation_core_1 = require("@composed-di/instrumentation-core");
6
7
  /**
7
8
  * A ServiceInstrumentation that records service events as OTEL spans.
8
9
  *
9
10
  * Arguments and results are recorded (as the
10
11
  * `composed_di.service.function.arguments` / `.result` attributes,
11
- * serialized to JSON) exactly when `instrument()` delivers them — capture
12
- * and redaction policy live in the InstrumentOptions, not here.
12
+ * serialized to JSON) exactly when `instrument()` (inherited from
13
+ * ServiceInstrumentation) delivers them capture and redaction policy
14
+ * live in the InstrumentOptions, not here.
13
15
  */
14
- class OTELInstrumentation {
16
+ class OTELInstrumentation extends instrumentation_core_1.ServiceInstrumentation {
15
17
  constructor(options = {}) {
16
18
  var _a;
19
+ super();
17
20
  this.tracer =
18
21
  (_a = options.tracer) !== null && _a !== void 0 ? _a : api_1.trace.getTracer('@composed-di/instrumentation-otel');
19
22
  }
@@ -22,7 +25,7 @@ class OTELInstrumentation {
22
25
  key: context.key,
23
26
  event: 'initialize',
24
27
  className: 'ServiceFactory',
25
- functionName: 'initialize',
28
+ methodName: 'initialize',
26
29
  });
27
30
  const spanName = `ServiceFactory[${context.key.name}].initialize`;
28
31
  return this.buildSpan(spanName, attributes);
@@ -32,7 +35,7 @@ class OTELInstrumentation {
32
35
  key: context.key,
33
36
  event: 'dispose',
34
37
  className: 'ServiceFactory',
35
- functionName: 'dispose',
38
+ methodName: 'dispose',
36
39
  });
37
40
  const spanName = `ServiceFactory[${context.key.name}].dispose`;
38
41
  return this.buildSpan(spanName, attributes);
@@ -42,7 +45,7 @@ class OTELInstrumentation {
42
45
  key: context.key,
43
46
  event: 'call',
44
47
  className: context.className,
45
- functionName: context.functionName,
48
+ methodName: context.methodName,
46
49
  args: context.args,
47
50
  });
48
51
  const spanName = attributes[semantic_conventions_1.ATTR_CODE_FUNCTION_NAME];
@@ -78,7 +81,7 @@ class OTELInstrumentation {
78
81
  buildAttributes(params) {
79
82
  var _a;
80
83
  const attributes = {
81
- [semantic_conventions_1.ATTR_CODE_FUNCTION_NAME]: `${(_a = params.className) !== null && _a !== void 0 ? _a : params.key.name}.${params.functionName}`,
84
+ [semantic_conventions_1.ATTR_CODE_FUNCTION_NAME]: `${(_a = params.className) !== null && _a !== void 0 ? _a : params.key.name}.${params.methodName}`,
82
85
  'composed_di.service.key': params.key.name,
83
86
  'composed_di.service.event': params.event,
84
87
  };
@@ -1 +1 @@
1
- {"version":3,"file":"otelInstrumentation.js","sourceRoot":"","sources":["../src/otelInstrumentation.ts"],"names":[],"mappings":";;;AAAA,4CAM2B;AAC3B,8EAI4C;AAsB5C;;;;;;;GAOG;AACH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AU,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,kDAoGC;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"}
@@ -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":"","sources":["../src/otelServiceInstrumentation.ts"],"names":[],"mappings":";;;AAAA,4CAM2B;AAC3B,8EAI4C;AAC5C,4EAO0C;AAc1C;;;;;;;;GAQG;AACH,MAAa,0BAA2B,SAAQ,6CAAsB;IAGpE,YAAY,UAAsC,EAAE;;QAClD,KAAK,EAAE,CAAA;QAC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I,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.6.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.6.0-alpha",
41
- "@composed-di/instrumentation-core": "^0.6.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'
@@ -12,8 +12,8 @@ import {
12
12
  } from '@opentelemetry/semantic-conventions'
13
13
  import {
14
14
  DisposeContext,
15
- EventOutcome,
16
- EventSpan,
15
+ OperationOutcome,
16
+ OperationSpan,
17
17
  InitializeContext,
18
18
  MethodCallContext,
19
19
  ServiceInstrumentation,
@@ -36,59 +36,61 @@ export interface OTELInstrumentationOptions {
36
36
  *
37
37
  * Arguments and results are recorded (as the
38
38
  * `composed_di.service.function.arguments` / `.result` attributes,
39
- * serialized to JSON) exactly when `instrument()` delivers them — capture
40
- * and redaction policy live in the InstrumentOptions, not here.
39
+ * serialized to JSON) exactly when `instrument()` (inherited from
40
+ * ServiceInstrumentation) delivers them capture and redaction policy
41
+ * live in the InstrumentOptions, not here.
41
42
  */
42
- export class OTELInstrumentation implements ServiceInstrumentation {
43
+ export class OTELServiceInstrumentation extends ServiceInstrumentation {
43
44
  private readonly tracer: Tracer
44
45
 
45
46
  constructor(options: OTELInstrumentationOptions = {}) {
47
+ super()
46
48
  this.tracer =
47
49
  options.tracer ?? trace.getTracer('@composed-di/instrumentation-otel')
48
50
  }
49
51
 
50
- onInitialize(context: InitializeContext): EventSpan {
52
+ onInitialize(context: InitializeContext): OperationSpan {
51
53
  const attributes = this.buildAttributes({
52
54
  key: context.key,
53
55
  event: 'initialize',
54
56
  className: 'ServiceFactory',
55
- functionName: 'initialize',
57
+ methodName: 'initialize',
56
58
  })
57
59
  const spanName = `ServiceFactory[${context.key.name}].initialize`
58
60
  return this.buildSpan(spanName, attributes)
59
61
  }
60
62
 
61
- onDispose(context: DisposeContext): EventSpan {
63
+ onDispose(context: DisposeContext): OperationSpan {
62
64
  const attributes = this.buildAttributes({
63
65
  key: context.key,
64
66
  event: 'dispose',
65
67
  className: 'ServiceFactory',
66
- functionName: 'dispose',
68
+ methodName: 'dispose',
67
69
  })
68
70
  const spanName = `ServiceFactory[${context.key.name}].dispose`
69
71
  return this.buildSpan(spanName, attributes)
70
72
  }
71
73
 
72
- onMethodCall(context: MethodCallContext): EventSpan {
74
+ onMethodCall(context: MethodCallContext): OperationSpan {
73
75
  const attributes = this.buildAttributes({
74
76
  key: context.key,
75
77
  event: 'call',
76
78
  className: context.className,
77
- functionName: context.functionName,
79
+ methodName: context.methodName,
78
80
  args: context.args,
79
81
  })
80
82
  const spanName = attributes[ATTR_CODE_FUNCTION_NAME]
81
83
  return this.buildSpan(spanName, attributes)
82
84
  }
83
85
 
84
- private buildSpan(spanName: string, attributes: Attributes): EventSpan {
86
+ private buildSpan(spanName: string, attributes: Attributes): OperationSpan {
85
87
  const parentContext = otelContext.active()
86
88
  const span = this.tracer.startSpan(spanName, { attributes }, parentContext)
87
89
  const spanContext = trace.setSpan(parentContext, span)
88
90
 
89
91
  return {
90
92
  run: (fn) => otelContext.with(spanContext, fn),
91
- end: (outcome: EventOutcome) => {
93
+ end: (outcome: OperationOutcome) => {
92
94
  if (outcome.type === 'failure') {
93
95
  const error = outcome.error
94
96
  span.recordException(error instanceof Error ? error : String(error))
@@ -119,11 +121,11 @@ export class OTELInstrumentation implements ServiceInstrumentation {
119
121
  key: ServiceKey<unknown>
120
122
  event: 'initialize' | 'dispose' | 'call'
121
123
  className?: string
122
- functionName: string
124
+ methodName: string
123
125
  args?: readonly unknown[]
124
126
  }) {
125
127
  const attributes: { [key: string]: string } = {
126
- [ATTR_CODE_FUNCTION_NAME]: `${params.className ?? params.key.name}.${params.functionName}`,
128
+ [ATTR_CODE_FUNCTION_NAME]: `${params.className ?? params.key.name}.${params.methodName}`,
127
129
  'composed_di.service.key': params.key.name,
128
130
  'composed_di.service.event': params.event,
129
131
  }