Skip to content

Commit 4a8dcb4

Browse files
committed
Extract project name from mastra componentName attr
1 parent 93eebdc commit 4a8dcb4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
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+
import { addOpenInferenceAttributesToMastraSpan } from "./utils.js";
56

67
type ConstructorArgs = {
78
/**
@@ -63,7 +64,10 @@ export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
6364
resultCallback: (result: ExportResult) => void,
6465
) {
6566
let filteredItems = items.map((i) => {
67+
// add OpenInference attributes to the span based on Vercel span attributes
6668
addOpenInferenceAttributesToSpan(i);
69+
// add OpenInference attributes to the span based on Mastra span attributes
70+
addOpenInferenceAttributesToMastraSpan(i);
6771
return i;
6872
});
6973
if (this.spanFilter) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
};

0 commit comments

Comments
 (0)