@@ -2,6 +2,7 @@ import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
2
2
import type { ExportResult } from "@opentelemetry/core" ;
3
3
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto" ;
4
4
import { addOpenInferenceAttributesToSpan } from "@arizeai/openinference-vercel/utils" ;
5
+
5
6
import {
6
7
addOpenInferenceAttributesToMastraSpan ,
7
8
addOpenInferenceResourceAttributesToMastraSpan ,
@@ -24,7 +25,7 @@ type ConstructorArgs = {
24
25
* @example
25
26
* ```ts
26
27
* import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
27
- * import { isOpenInferenceSpan, OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-vercel ";
28
+ * import { isOpenInferenceSpan, OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-mastra ";
28
29
* const spanFilter = (span: ReadableSpan) => {
29
30
* // add more span filtering logic here if desired
30
31
* // or just use the default isOpenInferenceSpan filter directly
@@ -43,6 +44,37 @@ type ConstructorArgs = {
43
44
"url"
44
45
> ;
45
46
47
+ /**
48
+ * A custom OpenTelemetry trace exporter that exports annotated traces to an OpenInference compliant OTEL API.
49
+ *
50
+ * This class extends the `OTLPTraceExporter` and adds additional logic to the `export` method to augment the spans with OpenInference attributes.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { Mastra } from "@mastra/core/mastra";
55
+ * import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
56
+ * import { isOpenInferenceSpan, OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-mastra";
57
+ * const spanFilter = (span: ReadableSpan) => {
58
+ * // add more span filtering logic here if desired
59
+ * // or just use the default isOpenInferenceSpan filter directly
60
+ * return isOpenInferenceSpan(span);
61
+ * };
62
+ * const exporter = new OpenInferenceOTLPTraceExporter({
63
+ * apiKey: "api-key",
64
+ * collectorEndpoint: "http://localhost:6006/v1/traces",
65
+ * spanFilter,
66
+ * });
67
+ * const mastra = new Mastra({
68
+ * // ... other config
69
+ * telemetry: {
70
+ * export: {
71
+ * type: "custom",
72
+ * exporter,
73
+ * },
74
+ * },
75
+ * })
76
+ * ```
77
+ */
46
78
export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
47
79
private readonly spanFilter ?: ( span : ReadableSpan ) => boolean ;
48
80
0 commit comments