Skip to content

Commit e59c534

Browse files
committed
Replace jest with vitest in mastra package
1 parent 4a8dcb4 commit e59c534

File tree

10 files changed

+654
-737
lines changed

10 files changed

+654
-737
lines changed

js/packages/openinference-mastra/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ A typical Mastra project will already have OpenTelemetry and related packages in
1818

1919
To process your Mastra spans add an `OpenInferenceOTLPTraceExporter` to your `telemetry` configuration within your `Mastra` instance.
2020

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+
2127
```typescript
2228
import { Mastra } from "@mastra/core";
2329
import { OpenInferenceOTLPTraceExporter } from "@arizeai/openinference-mastra";
@@ -42,4 +48,4 @@ For general details on Mastra's OpenTelemetry support see the [Mastra Observabil
4248

4349
## Examples
4450

45-
TODO
51+
TODO: Add examples

js/packages/openinference-mastra/jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

js/packages/openinference-mastra/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
1111
"postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test",
1212
"type:check": "tsc --noEmit",
13-
"test": "jest"
13+
"test": "vitest"
1414
},
1515
"exports": {
1616
".": {
@@ -43,12 +43,12 @@
4343
"@arizeai/openinference-semantic-conventions": "workspace:*",
4444
"@arizeai/openinference-vercel": "workspace:*",
4545
"@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"
4748
},
4849
"devDependencies": {
49-
"@types/jest": "^29.5.12",
50-
"jest": "^29.7.0",
50+
"@opentelemetry/api": ">=1.0.0 <1.9.0",
5151
"@opentelemetry/sdk-trace-base": "^1.19.0",
52-
"@opentelemetry/api": ">=1.0.0 <1.9.0"
52+
"vitest": "^3.1.3"
5353
}
5454
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ 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";
5+
import {
6+
addOpenInferenceAttributesToMastraSpan,
7+
addOpenInferenceResourceAttributesToMastraSpan,
8+
} from "./utils.js";
69

710
type ConstructorArgs = {
811
/**
@@ -42,6 +45,7 @@ type ConstructorArgs = {
4245

4346
export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
4447
private readonly spanFilter?: (span: ReadableSpan) => boolean;
48+
4549
constructor({
4650
apiKey,
4751
collectorEndpoint,
@@ -64,6 +68,8 @@ export class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
6468
resultCallback: (result: ExportResult) => void,
6569
) {
6670
let filteredItems = items.map((i) => {
71+
// add OpenInference resource attributes to the span based on Mastra span attributes
72+
addOpenInferenceResourceAttributesToMastraSpan(i);
6773
// add OpenInference attributes to the span based on Vercel span attributes
6874
addOpenInferenceAttributesToSpan(i);
6975
// add OpenInference attributes to the span based on Mastra span attributes
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
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+
};
315

416
/**
517
* Augments a Mastra span with OpenInference attributes.
@@ -8,9 +20,7 @@ import { ReadableSpan } from "@opentelemetry/sdk-trace-base";
820
*
921
* @param span - The Mastra span to augment.
1022
*/
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+
) => {};

0 commit comments

Comments
 (0)