File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
js/packages/openinference-mastra/src Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -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
+ import { addOpenInferenceAttributesToMastraSpan } from "./utils.js" ;
5
6
6
7
type ConstructorArgs = {
7
8
/**
@@ -63,7 +64,10 @@ export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
63
64
resultCallback : ( result : ExportResult ) => void ,
64
65
) {
65
66
let filteredItems = items . map ( ( i ) => {
67
+ // add OpenInference attributes to the span based on Vercel span attributes
66
68
addOpenInferenceAttributesToSpan ( i ) ;
69
+ // add OpenInference attributes to the span based on Mastra span attributes
70
+ addOpenInferenceAttributesToMastraSpan ( i ) ;
67
71
return i ;
68
72
} ) ;
69
73
if ( this . spanFilter ) {
Original file line number Diff line number Diff line change
1
+ import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions" ;
2
+ import { ReadableSpan } from "@opentelemetry/sdk-trace-base" ;
3
+
4
+ /**
5
+ * Augments a Mastra span with OpenInference attributes.
6
+ *
7
+ * This function will add additional attributes to the span, based on the Mastra span's attributes.
8
+ *
9
+ * @param span - The Mastra span to augment.
10
+ */
11
+ export const addOpenInferenceAttributesToMastraSpan = ( span : ReadableSpan ) => {
12
+ const attributes = span . attributes ;
13
+ if ( attributes [ "componentName" ] ) {
14
+ span . attributes [ SEMRESATTRS_PROJECT_NAME ] = attributes [ "componentName" ] ;
15
+ }
16
+ } ;
You can’t perform that action at this time.
0 commit comments