File tree Expand file tree Collapse file tree 10 files changed +654
-737
lines changed
packages/openinference-mastra Expand file tree Collapse file tree 10 files changed +654
-737
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ A typical Mastra project will already have OpenTelemetry and related packages in
18
18
19
19
To process your Mastra spans add an ` OpenInferenceOTLPTraceExporter ` to your ` telemetry ` configuration within your ` Mastra ` instance.
20
20
21
+ ``` shell
22
+ # Set the Phoenix collector endpoint and API key in your environment
23
+ export PHOENIX_COLLECTOR_ENDPOINT=" https://localhost:6006/v1/traces"
24
+ export PHOENIX_API_KEY=" your-api-key"
25
+ ```
26
+
21
27
``` typescript
22
28
import { Mastra } from " @mastra/core" ;
23
29
import { OpenInferenceOTLPTraceExporter } from " @arizeai/openinference-mastra" ;
@@ -42,4 +48,4 @@ For general details on Mastra's OpenTelemetry support see the [Mastra Observabil
42
48
43
49
## Examples
44
50
45
- TODO
51
+ TODO: Add examples
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 10
10
"build" : " tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json" ,
11
11
"postbuild" : " echo '{\" type\" : \" module\" }' > ./dist/esm/package.json && rimraf dist/test" ,
12
12
"type:check" : " tsc --noEmit" ,
13
- "test" : " jest "
13
+ "test" : " vitest "
14
14
},
15
15
"exports" : {
16
16
"." : {
43
43
"@arizeai/openinference-semantic-conventions" : " workspace:*" ,
44
44
"@arizeai/openinference-vercel" : " workspace:*" ,
45
45
"@opentelemetry/core" : " ^1.25.1" ,
46
- "@opentelemetry/exporter-trace-otlp-proto" : " ^0.50.0"
46
+ "@opentelemetry/exporter-trace-otlp-proto" : " ^0.50.0" ,
47
+ "@opentelemetry/semantic-conventions" : " ^1.33.0"
47
48
},
48
49
"devDependencies" : {
49
- "@types/jest" : " ^29.5.12" ,
50
- "jest" : " ^29.7.0" ,
50
+ "@opentelemetry/api" : " >=1.0.0 <1.9.0" ,
51
51
"@opentelemetry/sdk-trace-base" : " ^1.19.0" ,
52
- "@opentelemetry/api " : " >=1.0.0 <1.9.0 "
52
+ "vitest " : " ^3.1.3 "
53
53
}
54
54
}
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ 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
+ import {
6
+ addOpenInferenceAttributesToMastraSpan ,
7
+ addOpenInferenceResourceAttributesToMastraSpan ,
8
+ } from "./utils.js" ;
6
9
7
10
type ConstructorArgs = {
8
11
/**
@@ -42,6 +45,7 @@ type ConstructorArgs = {
42
45
43
46
export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
44
47
private readonly spanFilter ?: ( span : ReadableSpan ) => boolean ;
48
+
45
49
constructor ( {
46
50
apiKey,
47
51
collectorEndpoint,
@@ -64,6 +68,8 @@ export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
64
68
resultCallback : ( result : ExportResult ) => void ,
65
69
) {
66
70
let filteredItems = items . map ( ( i ) => {
71
+ // add OpenInference resource attributes to the span based on Mastra span attributes
72
+ addOpenInferenceResourceAttributesToMastraSpan ( i ) ;
67
73
// add OpenInference attributes to the span based on Vercel span attributes
68
74
addOpenInferenceAttributesToSpan ( i ) ;
69
75
// add OpenInference attributes to the span based on Mastra span attributes
Original file line number Diff line number Diff line change 1
1
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions" ;
2
- import { ReadableSpan } from "@opentelemetry/sdk-trace-base" ;
2
+ import type { ReadableSpan } from "@opentelemetry/sdk-trace-base" ;
3
+ import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions" ;
4
+
5
+ export const addOpenInferenceResourceAttributesToMastraSpan = (
6
+ span : ReadableSpan ,
7
+ ) => {
8
+ const attributes = span . resource . attributes ;
9
+ if ( ATTR_SERVICE_NAME in attributes ) {
10
+ attributes [ SEMRESATTRS_PROJECT_NAME ] = attributes [ ATTR_SERVICE_NAME ] ;
11
+ }
12
+ // eslint-disable-next-line no-console
13
+ console . log ( "attributes" , attributes ) ;
14
+ } ;
3
15
4
16
/**
5
17
* Augments a Mastra span with OpenInference attributes.
@@ -8,9 +20,7 @@ import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
8
20
*
9
21
* @param span - The Mastra span to augment.
10
22
*/
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
- } ;
23
+ export const addOpenInferenceAttributesToMastraSpan = (
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
+ span : ReadableSpan ,
26
+ ) => { } ;
You can’t perform that action at this time.
0 commit comments