Skip to content

Commit 449123f

Browse files
committed
Update readme
1 parent c02d7ab commit 449123f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

js/packages/openinference-mastra/src/OpenInferenceTraceExporter.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
22
import type { ExportResult } from "@opentelemetry/core";
33
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
44
import { addOpenInferenceAttributesToSpan } from "@arizeai/openinference-vercel/utils";
5+
56
import {
67
addOpenInferenceAttributesToMastraSpan,
78
addOpenInferenceResourceAttributesToMastraSpan,
@@ -24,7 +25,7 @@ type ConstructorArgs = {
2425
* @example
2526
* ```ts
2627
* import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
27-
* import { isOpenInferenceSpan, OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-vercel";
28+
* import { isOpenInferenceSpan, OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-mastra";
2829
* const spanFilter = (span: ReadableSpan) => {
2930
* // add more span filtering logic here if desired
3031
* // or just use the default isOpenInferenceSpan filter directly
@@ -43,6 +44,37 @@ type ConstructorArgs = {
4344
"url"
4445
>;
4546

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+
*/
4678
export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
4779
private readonly spanFilter?: (span: ReadableSpan) => boolean;
4880

0 commit comments

Comments
 (0)