@arizeai/openinference-instrumentation-beeai 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/openinference-instrumentation-beeai",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "gallas.milan@gmail.com",
6
6
  "description": "OpenInference Instrumentation for BeeAI framework",
@@ -3,7 +3,7 @@ import {
3
3
  InstrumentationNodeModuleDefinition,
4
4
  InstrumentationConfig,
5
5
  } from "@opentelemetry/instrumentation";
6
- import { diag } from "@opentelemetry/api";
6
+ import { diag, Tracer, TracerProvider } from "@opentelemetry/api";
7
7
  import { Version } from "beeai-framework";
8
8
  import * as bee from "beeai-framework";
9
9
 
@@ -14,6 +14,8 @@ import { satisfies } from "semver";
14
14
 
15
15
  const MODULE_NAME = "beeai-framework";
16
16
 
17
+ const INSTRUMENTATION_NAME = "@arizeai/openinference-instrumentation-beeai";
18
+
17
19
  const INSTRUMENTS = [">=0.1.9 <0.1.14"];
18
20
 
19
21
  /**
@@ -31,10 +33,13 @@ export function isPatched() {
31
33
 
32
34
  export class BeeAIInstrumentation extends InstrumentationBase {
33
35
  private oiTracer: OITracer;
36
+ private tracerProvider?: TracerProvider;
37
+ private traceConfig?: TraceConfigOptions;
34
38
 
35
39
  constructor({
36
40
  instrumentationConfig,
37
41
  traceConfig,
42
+ tracerProvider,
38
43
  }: {
39
44
  /**
40
45
  * The config for the instrumentation
@@ -46,13 +51,26 @@ export class BeeAIInstrumentation extends InstrumentationBase {
46
51
  * @see {@link TraceConfigOptions}
47
52
  */
48
53
  traceConfig?: TraceConfigOptions;
54
+ /**
55
+ * An optional custom trace provider to be used for tracing. If not provided, a tracer will be created using the global tracer provider.
56
+ * This is useful if you want to use a non-global tracer provider.
57
+ *
58
+ * @see {@link TracerProvider}
59
+ */
60
+ tracerProvider?: TracerProvider;
49
61
  } = {}) {
50
62
  super(
51
- "@arizeai/openinference-instrumentation-beeai",
63
+ INSTRUMENTATION_NAME,
52
64
  Version,
53
65
  Object.assign({}, instrumentationConfig),
54
66
  );
55
- this.oiTracer = new OITracer({ tracer: this.tracer, traceConfig });
67
+ this.tracerProvider = tracerProvider;
68
+ this.traceConfig = traceConfig;
69
+ this.oiTracer = new OITracer({
70
+ tracer:
71
+ this.tracerProvider?.getTracer(INSTRUMENTATION_NAME) ?? this.tracer,
72
+ traceConfig,
73
+ });
56
74
  }
57
75
 
58
76
  protected init() {
@@ -85,6 +103,22 @@ export class BeeAIInstrumentation extends InstrumentationBase {
85
103
  this.patch(module);
86
104
  }
87
105
 
106
+ get tracer(): Tracer {
107
+ if (this.tracerProvider) {
108
+ return this.tracerProvider.getTracer(this.instrumentationName);
109
+ }
110
+ return super.tracer;
111
+ }
112
+
113
+ setTracerProvider(tracerProvider: TracerProvider): void {
114
+ super.setTracerProvider(tracerProvider);
115
+ this.tracerProvider = tracerProvider;
116
+ this.oiTracer = new OITracer({
117
+ tracer: this.tracer,
118
+ traceConfig: this.traceConfig,
119
+ });
120
+ }
121
+
88
122
  private patch(module: typeof bee & { openInferencePatched?: boolean }) {
89
123
  if (!module?.BaseAgent) {
90
124
  diag.warn(