@mastra/arize 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +14 -0
- package/dist/index.cjs +56 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -90
- package/dist/index.js.map +1 -1
- package/dist/openInferenceOTLPExporter.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/gen-ai.d.ts +0 -20
- package/dist/gen-ai.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @mastra/arize
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated OtelExporters, Bridge, and Arize packages to better implement GenAI v1.38.0 Otel Semantic Conventions. See: ([#10591](https://github.com/mastra-ai/mastra/pull/10591))
|
|
8
|
+
https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/gen-ai/README.md
|
|
9
|
+
|
|
10
|
+
- feat(observability): Add tags support to OtelExporter, OtelBridge, and ArizeExporter ([#10843](https://github.com/mastra-ai/mastra/pull/10843))
|
|
11
|
+
|
|
12
|
+
This change adds support for the `tracingOptions.tags` feature to the OpenTelemetry-based exporters and bridge. Tags are now included as span attributes when present on root spans, following the same pattern as Braintrust and Langfuse exporters.
|
|
13
|
+
|
|
14
|
+
**Changes:**
|
|
15
|
+
- **OtelExporter**: Tags are now included as `mastra.tags` span attribute for root spans
|
|
16
|
+
- **OtelBridge**: Tags flow through the SpanConverter and are included in native OTEL spans as `mastra.tags`
|
|
17
|
+
- **ArizeExporter**: Tags are mapped to the native OpenInference `tag.tags` semantic convention
|
|
18
|
+
|
|
19
|
+
**Implementation Details:**
|
|
20
|
+
- Tags are only included on root spans (by design)
|
|
21
|
+
- Tags are stored as JSON-stringified arrays for maximum backend compatibility (many OTEL backends have limited native array support)
|
|
22
|
+
- Empty or undefined tag arrays are not included in span attributes
|
|
23
|
+
|
|
24
|
+
**Usage:**
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const result = await agent.generate({
|
|
28
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
29
|
+
tracingOptions: {
|
|
30
|
+
tags: ['production', 'experiment-v2'],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Fixes #10771
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [[`3076c67`](https://github.com/mastra-ai/mastra/commit/3076c6778b18988ae7d5c4c5c466366974b2d63f), [`85d7ee1`](https://github.com/mastra-ai/mastra/commit/85d7ee18ff4e14d625a8a30ec6656bb49804989b), [`c6c1092`](https://github.com/mastra-ai/mastra/commit/c6c1092f8fbf76109303f69e000e96fd1960c4ce), [`81dc110`](https://github.com/mastra-ai/mastra/commit/81dc11008d147cf5bdc8996ead1aa61dbdebb6fc), [`7aedb74`](https://github.com/mastra-ai/mastra/commit/7aedb74883adf66af38e270e4068fd42e7a37036), [`8f02d80`](https://github.com/mastra-ai/mastra/commit/8f02d800777397e4b45d7f1ad041988a8b0c6630), [`d7aad50`](https://github.com/mastra-ai/mastra/commit/d7aad501ce61646b76b4b511e558ac4eea9884d0), [`ce0a73a`](https://github.com/mastra-ai/mastra/commit/ce0a73abeaa75b10ca38f9e40a255a645d50ebfb), [`a02e542`](https://github.com/mastra-ai/mastra/commit/a02e542d23179bad250b044b17ff023caa61739f), [`a372c64`](https://github.com/mastra-ai/mastra/commit/a372c640ad1fd12e8f0613cebdc682fc156b4d95), [`db500e8`](https://github.com/mastra-ai/mastra/commit/db500e8b8c5b4df9bd3590a7da6e007c08f94945), [`8846867`](https://github.com/mastra-ai/mastra/commit/8846867ffa9a3746767618e314bebac08eb77d87), [`42a42cf`](https://github.com/mastra-ai/mastra/commit/42a42cf3132b9786feecbb8c13c583dce5b0e198), [`ae08bf0`](https://github.com/mastra-ai/mastra/commit/ae08bf0ebc6a4e4da992b711c4a389c32ba84cf4), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141), [`1d877b8`](https://github.com/mastra-ai/mastra/commit/1d877b8d7b536a251c1a7a18db7ddcf4f68d6f8b)]:
|
|
38
|
+
- @mastra/core@1.0.0-beta.7
|
|
39
|
+
- @mastra/otel-exporter@1.0.0-beta.3
|
|
40
|
+
|
|
41
|
+
## 1.0.0-beta.2
|
|
42
|
+
|
|
43
|
+
### Minor Changes
|
|
44
|
+
|
|
45
|
+
- Adds out of the box support for sessions in Arize AX and Phoenix. Additionally maps user ids and passed through metadata if available. ([#10731](https://github.com/mastra-ai/mastra/pull/10731))
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
|
|
50
|
+
- @mastra/core@1.0.0-beta.6
|
|
51
|
+
- @mastra/otel-exporter@1.0.0-beta.2
|
|
52
|
+
|
|
3
53
|
## 1.0.0-beta.1
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -135,6 +135,20 @@ const mastra = new Mastra({
|
|
|
135
135
|
});
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
### Custom metadata
|
|
139
|
+
|
|
140
|
+
Any custom span attributes that are not part of the standard Mastra/OpenInference fields are serialized into the OpenInference `metadata` payload and shown in Arize/Phoenix. An easy way to add them is through `tracingOptions.metadata`:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
await agent.generate(input, {
|
|
144
|
+
tracingOptions: {
|
|
145
|
+
metadata: {
|
|
146
|
+
companyId: 'acme-co',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
138
152
|
## OpenInference Semantic Conventions
|
|
139
153
|
|
|
140
154
|
This exporter follows the [OpenInference Semantic Conventions](https://github.com/Arize-ai/openinference/tree/main/spec) for generative AI applications.
|
package/dist/index.cjs
CHANGED
|
@@ -5,104 +5,71 @@ var logger = require('@mastra/core/logger');
|
|
|
5
5
|
var otelExporter = require('@mastra/otel-exporter');
|
|
6
6
|
var openinferenceGenai = require('@arizeai/openinference-genai');
|
|
7
7
|
var exporterTraceOtlpProto = require('@opentelemetry/exporter-trace-otlp-proto');
|
|
8
|
+
var incubating = require('@opentelemetry/semantic-conventions/incubating');
|
|
8
9
|
|
|
9
10
|
// src/tracing.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (typeof parsedIO !== "object" || parsedIO == null || !("messages" in parsedIO) && !("text" in parsedIO)) {
|
|
22
|
-
return inputOutputString;
|
|
23
|
-
}
|
|
24
|
-
if ("text" in parsedIO) {
|
|
25
|
-
return JSON.stringify([
|
|
26
|
-
{
|
|
27
|
-
role: "assistant",
|
|
28
|
-
parts: [{ type: "text", content: parsedIO.text }]
|
|
11
|
+
var MASTRA_GENERAL_PREFIX = "mastra.";
|
|
12
|
+
var MASTRA_METADATA_PREFIX = "mastra.metadata.";
|
|
13
|
+
function splitMastraAttributes(attributes) {
|
|
14
|
+
return Object.entries(attributes).reduce(
|
|
15
|
+
(acc, [key, value]) => {
|
|
16
|
+
if (key.startsWith(MASTRA_GENERAL_PREFIX)) {
|
|
17
|
+
if (key.startsWith(MASTRA_METADATA_PREFIX)) {
|
|
18
|
+
const strippedKey = key.slice(MASTRA_METADATA_PREFIX.length);
|
|
19
|
+
acc.mastraMetadata[strippedKey] = value;
|
|
20
|
+
} else {
|
|
21
|
+
acc.mastraOther[key] = value;
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return m;
|
|
37
|
-
}
|
|
38
|
-
const role = m.role;
|
|
39
|
-
let parts = [];
|
|
40
|
-
if (Array.isArray(m.content)) {
|
|
41
|
-
parts = m.content.map((c) => {
|
|
42
|
-
switch (c.type) {
|
|
43
|
-
case "text":
|
|
44
|
-
return {
|
|
45
|
-
type: "text",
|
|
46
|
-
content: c.text
|
|
47
|
-
};
|
|
48
|
-
case "tool-call":
|
|
49
|
-
return {
|
|
50
|
-
type: "tool_call",
|
|
51
|
-
id: c.toolCallId,
|
|
52
|
-
name: c.toolName,
|
|
53
|
-
arguments: JSON.stringify(c.input)
|
|
54
|
-
};
|
|
55
|
-
case "tool-result":
|
|
56
|
-
return {
|
|
57
|
-
type: "tool_call_response",
|
|
58
|
-
id: c.toolCallId,
|
|
59
|
-
name: c.toolName,
|
|
60
|
-
response: JSON.stringify(c.output.value)
|
|
61
|
-
};
|
|
62
|
-
default:
|
|
63
|
-
return c;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
parts = [
|
|
68
|
-
{
|
|
69
|
-
type: "text",
|
|
70
|
-
content: m.content
|
|
71
|
-
}
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
role,
|
|
76
|
-
parts
|
|
77
|
-
};
|
|
78
|
-
})
|
|
79
|
-
);
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
mastraMetadata: {},
|
|
28
|
+
mastraOther: {}
|
|
80
29
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return inputOutputString;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// src/openInferenceOTLPExporter.ts
|
|
30
|
+
);
|
|
31
|
+
}
|
|
88
32
|
var OpenInferenceOTLPTraceExporter = class extends exporterTraceOtlpProto.OTLPTraceExporter {
|
|
89
33
|
export(spans, resultCallback) {
|
|
90
34
|
const processedSpans = spans.map((span) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (span.attributes?.["gen_ai.completion"] && typeof span.attributes["gen_ai.completion"] === "string") {
|
|
97
|
-
span.attributes["gen_ai.output.messages"] = convertMastraMessagesToGenAIMessages(
|
|
98
|
-
span.attributes["gen_ai.completion"]
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
const processedAttributes = openinferenceGenai.convertGenAISpanAttributesToOpenInferenceSpanAttributes(span.attributes);
|
|
35
|
+
const attributes = { ...span.attributes ?? {} };
|
|
36
|
+
const mutableSpan = span;
|
|
37
|
+
const { mastraMetadata, mastraOther } = splitMastraAttributes(attributes);
|
|
38
|
+
const processedAttributes = openinferenceGenai.convertGenAISpanAttributesToOpenInferenceSpanAttributes(attributes);
|
|
102
39
|
if (processedAttributes) {
|
|
103
|
-
|
|
40
|
+
const threadId = mastraMetadata["threadId"];
|
|
41
|
+
if (threadId) {
|
|
42
|
+
delete mastraMetadata["threadId"];
|
|
43
|
+
processedAttributes[openinferenceSemanticConventions.SESSION_ID] = threadId;
|
|
44
|
+
}
|
|
45
|
+
if (mastraOther["mastra.tags"]) {
|
|
46
|
+
processedAttributes[openinferenceSemanticConventions.TAG_TAGS] = mastraOther["mastra.tags"];
|
|
47
|
+
delete mastraOther["mastra.tags"];
|
|
48
|
+
}
|
|
49
|
+
const userId = mastraMetadata["userId"];
|
|
50
|
+
if (userId) {
|
|
51
|
+
delete mastraMetadata["userId"];
|
|
52
|
+
processedAttributes[openinferenceSemanticConventions.USER_ID] = userId;
|
|
53
|
+
}
|
|
54
|
+
if (Object.keys(mastraMetadata).length > 0) {
|
|
55
|
+
try {
|
|
56
|
+
processedAttributes[openinferenceSemanticConventions.METADATA] = JSON.stringify(mastraMetadata);
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const inputMessages = attributes[incubating.ATTR_GEN_AI_INPUT_MESSAGES];
|
|
61
|
+
if (inputMessages) {
|
|
62
|
+
processedAttributes[openinferenceSemanticConventions.INPUT_MIME_TYPE] = "application/json";
|
|
63
|
+
processedAttributes[openinferenceSemanticConventions.INPUT_VALUE] = inputMessages;
|
|
64
|
+
}
|
|
65
|
+
const outputMessages = attributes[incubating.ATTR_GEN_AI_OUTPUT_MESSAGES];
|
|
66
|
+
if (outputMessages) {
|
|
67
|
+
processedAttributes[openinferenceSemanticConventions.OUTPUT_MIME_TYPE] = "application/json";
|
|
68
|
+
processedAttributes[openinferenceSemanticConventions.OUTPUT_VALUE] = outputMessages;
|
|
69
|
+
}
|
|
70
|
+
mutableSpan.attributes = { ...processedAttributes, ...mastraOther };
|
|
104
71
|
}
|
|
105
|
-
return
|
|
72
|
+
return mutableSpan;
|
|
106
73
|
});
|
|
107
74
|
super.export(processedSpans, resultCallback);
|
|
108
75
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gen-ai.ts","../src/openInferenceOTLPExporter.ts","../src/tracing.ts"],"names":["OTLPTraceExporter","convertGenAISpanAttributesToOpenInferenceSpanAttributes","OtelExporter","logger","ConsoleLogger","SEMRESATTRS_PROJECT_NAME"],"mappings":";;;;;;;;;;;AAgDA,IAAM,mBAAA,GAAsB,CAAC,CAAA,KAAuC;AAClE,EAAA,OACE,OAAO,CAAA,KAAM,QAAA,IACb,CAAA,IAAK,IAAA,IACL,UAAU,CAAA,KACT,CAAA,CAAE,IAAA,KAAS,MAAA,IAAU,EAAE,IAAA,KAAS,WAAA,IAAe,CAAA,CAAE,IAAA,KAAS,mBACzD,CAAA,CAAE,IAAA,KAAS,MAAA,IAAU,MAAA,IAAU,KAC9B,CAAA,CA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AIC,oBAAA,CAAc,EAAE,OAAO,MAAA,CAAO,QAAA,IAAY,QAAQ,CAAA;AACrE,IAAA,IAAI,WAA+B,MAAA,CAAO,QAAA;AAC1C,IAAA,MAAM,OAAA,GAAkC;AAAA,MACtC,GAAG,MAAA,CAAO;AAAA,KACZ;AACA,IAAA,IAAI,OAAO,OAAA,EAAS;AAElB,MAAA,OAAA,CAAQ,UAAU,IAAI,MAAA,CAAO,OAAA;AAC7B,MAAA,OAAA,CAAQ,SAAS,CAAA,GAAI,MAAA,CAAO,MAAA,IAAU,EAAA;AACtC,MAAA,QAAA,GAAW,OAAO,QAAA,IAAY,iBAAA;AAAA,IAChC,CAAA,MAAA,IAAW,OAAO,MAAA,EAAQ;AAExB,MAAA,OAAA,CAAQ,eAAe,CAAA,GAAI,CAAA,OAAA,EAAU,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,IACpD;AACA,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAAD,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,UAAU,CAAA,2DAAA,CAA6D,CAAA;AACvF,MAAA;AAAA,IACF;AACA,IAAA,KAAA,CAAM;AAAA,MACJ,QAAA,EAAU,IAAI,8BAAA,CAA+B;AAAA,QAC3C,GAAA,EAAK,QAAA;AAAA,QACL;AAAA,OACD,CAAA;AAAA,MACD,GAAG,MAAA;AAAA,MACH,kBAAA,EAAoB;AAAA,QAClB,CAACE,yDAAwB,GAAG,MAAA,CAAO,WAAA;AAAA,QACnC,GAAG,MAAA,CAAO;AAAA,OACZ;AAAA,MACA,QAAA,EAAU;AAAA,QACR,MAAA,EAAQ;AAAA,UACN,QAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA,EAAU;AAAA;AACZ;AACF,KAC4B,CAAA;AAAA,EAChC;AACF","file":"index.cjs","sourcesContent":["/**\n * Type represenation of a gen_ai chat message part\n */\ntype GenAIMessagePart =\n | {\n type: 'text';\n content: string;\n }\n | {\n type: 'tool_call';\n id: string;\n name: string;\n arguments: string;\n }\n | {\n type: 'tool_call_response';\n id: string;\n name: string;\n response: string;\n };\n\n/**\n * Type representation of a gen_ai chat message\n */\ntype GenAIMessage = {\n role: string;\n parts: GenAIMessagePart[];\n};\n\n/**\n * Assumed type representation of a Mastra message content type\n */\ntype MastraMessagePart =\n | {\n type: 'text';\n text: string;\n }\n | { type: 'tool-call'; toolCallId: string; toolName: string; input: unknown }\n | { type: 'tool-result'; toolCallId: string; toolName: string; output: { value: unknown } };\n\n/**\n * Assumed type representation of a Mastra message\n */\ntype MastraMessage = {\n role: string;\n content: MastraMessagePart[];\n};\n\nconst isMastraMessagePart = (p: unknown): p is MastraMessagePart => {\n return (\n typeof p === 'object' &&\n p != null &&\n 'type' in p &&\n (p.type === 'text' || p.type === 'tool-call' || p.type === 'tool-result') &&\n ((p.type === 'text' && 'text' in p) ||\n (p.type === 'tool-call' && 'toolCallId' in p && 'toolName' in p && 'input' in p) ||\n (p.type === 'tool-result' && 'toolCallId' in p && 'toolName' in p && 'output' in p))\n );\n};\n\nconst isMastraMessage = (m: unknown): m is MastraMessage => {\n return (\n typeof m === 'object' &&\n m != null &&\n 'role' in m &&\n 'content' in m &&\n (typeof m.content === 'string' || (Array.isArray(m.content) && m.content.every(isMastraMessagePart)))\n );\n};\n\n/**\n * Convert an Input/Output string from a MastraSpan into a jsonified string that adheres to\n * OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.\n * If parsing fails at any step, the original inputOutputString is returned unmodified.\n *\n * This conversion is best effort; It assumes a consistent shape for mastra messages, and converts\n * into the gen_ai input and output schemas as of October 20th, 2025.\n *\n * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json\n * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-output-messages\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json\n *\n * @param inputOutputString a jsonified string that contains messages adhering to what appears to be\n * Mastra's message shape.\n * @returns a jsonified string that contains messages adhering to the OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.\n * If parsing fails at any step, the original inputOutputString is returned unmodified.\n */\nexport const convertMastraMessagesToGenAIMessages = (inputOutputString: string): string => {\n try {\n const parsedIO = JSON.parse(inputOutputString) as unknown;\n if (typeof parsedIO !== 'object' || parsedIO == null || (!('messages' in parsedIO) && !('text' in parsedIO))) {\n // inputOutputString fails initial type guard, just return it\n return inputOutputString;\n }\n // if the IO simply contains a text string, return a single text message\n // formatted as a gen_ai assistant message, assuming its an assistant response\n if ('text' in parsedIO) {\n return JSON.stringify([\n {\n role: 'assistant',\n parts: [{ type: 'text', content: parsedIO.text as string }],\n } satisfies GenAIMessage,\n ]);\n }\n // if the IO contains messages, convert them to gen_ai messages\n if (Array.isArray(parsedIO.messages)) {\n return JSON.stringify(\n (parsedIO.messages as unknown[]).map(m => {\n if (!isMastraMessage(m)) {\n return m;\n }\n const role = m.role;\n let parts: GenAIMessagePart[] = [];\n if (Array.isArray(m.content)) {\n parts = m.content.map(c => {\n switch (c.type) {\n case 'text':\n return {\n type: 'text',\n content: c.text,\n };\n case 'tool-call':\n return {\n type: 'tool_call',\n id: c.toolCallId,\n name: c.toolName,\n arguments: JSON.stringify(c.input),\n };\n case 'tool-result':\n return {\n type: 'tool_call_response',\n id: c.toolCallId,\n name: c.toolName,\n response: JSON.stringify(c.output.value),\n };\n default:\n return c;\n }\n });\n } else {\n parts = [\n {\n type: 'text',\n content: m.content,\n },\n ];\n }\n return {\n role,\n parts,\n } satisfies GenAIMessage;\n }),\n );\n }\n // we've failed type-guards, just return original I/O string\n return inputOutputString;\n } catch {\n // silently fallback to original I/O string\n return inputOutputString;\n }\n};\n","import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from '@arizeai/openinference-genai';\nimport type { Mutable } from '@arizeai/openinference-genai/types';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { convertMastraMessagesToGenAIMessages } from './gen-ai';\n\nexport class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) {\n const processedSpans = spans.map(span => {\n // convert Mastra input messages to GenAI messages if present\n if (span.attributes?.['gen_ai.prompt'] && typeof span.attributes['gen_ai.prompt'] === 'string') {\n span.attributes['gen_ai.input.messages'] = convertMastraMessagesToGenAIMessages(\n span.attributes['gen_ai.prompt'],\n );\n }\n // convert Mastra output messages to GenAI messages if present\n if (span.attributes?.['gen_ai.completion'] && typeof span.attributes['gen_ai.completion'] === 'string') {\n span.attributes['gen_ai.output.messages'] = convertMastraMessagesToGenAIMessages(\n span.attributes['gen_ai.completion'],\n );\n }\n const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(span.attributes);\n // only add processed attributes if conversion was successful\n if (processedAttributes) {\n (span as Mutable<ReadableSpan>).attributes = processedAttributes;\n }\n return span;\n });\n\n super.export(processedSpans, resultCallback);\n }\n}\n","import { SEMRESATTRS_PROJECT_NAME } from '@arizeai/openinference-semantic-conventions';\nimport { ConsoleLogger } from '@mastra/core/logger';\nimport { OtelExporter } from '@mastra/otel-exporter';\nimport type { OtelExporterConfig } from '@mastra/otel-exporter';\n\nimport { OpenInferenceOTLPTraceExporter } from './openInferenceOTLPExporter.js';\n\nconst LOG_PREFIX = '[ArizeExporter]';\n\nexport const ARIZE_AX_ENDPOINT = 'https://otlp.arize.com/v1/traces';\n\nexport type ArizeExporterConfig = Omit<OtelExporterConfig, 'provider'> & {\n /**\n * Required if sending traces to Arize AX\n */\n spaceId?: string;\n /**\n * Required if sending traces to Arize AX, or to any other collector that\n * requires an Authorization header\n */\n apiKey?: string;\n /**\n * Collector endpoint destination for trace exports.\n * Required when sending traces to Phoenix, Phoenix Cloud, or other collectors.\n * Optional when sending traces to Arize AX.\n */\n endpoint?: string;\n /**\n * Optional project name to be added as a resource attribute using\n * OpenInference Semantic Conventions\n */\n projectName?: string;\n /**\n * Optional headers to be added to each OTLP request\n */\n headers?: Record<string, string>;\n};\n\nexport class ArizeExporter extends OtelExporter {\n name = 'arize';\n\n constructor(config: ArizeExporterConfig) {\n const logger = new ConsoleLogger({ level: config.logLevel ?? 'warn' });\n let endpoint: string | undefined = config.endpoint;\n const headers: Record<string, string> = {\n ...config.headers,\n };\n if (config.spaceId) {\n // arize ax header configuration\n headers['space_id'] = config.spaceId;\n headers['api_key'] = config.apiKey ?? '';\n endpoint = config.endpoint || ARIZE_AX_ENDPOINT;\n } else if (config.apiKey) {\n // standard otel header configuration\n headers['Authorization'] = `Bearer ${config.apiKey}`;\n }\n if (!endpoint) {\n logger.error(`${LOG_PREFIX} Endpoint is required in configuration. Disabling exporter.`);\n return;\n }\n super({\n exporter: new OpenInferenceOTLPTraceExporter({\n url: endpoint,\n headers,\n }),\n ...config,\n resourceAttributes: {\n [SEMRESATTRS_PROJECT_NAME]: config.projectName,\n ...config.resourceAttributes,\n },\n provider: {\n custom: {\n endpoint,\n headers,\n protocol: 'http/protobuf',\n },\n } satisfies OtelExporterConfig['provider'],\n } satisfies OtelExporterConfig);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/openInferenceOTLPExporter.ts","../src/tracing.ts"],"names":["OTLPTraceExporter","convertGenAISpanAttributesToOpenInferenceSpanAttributes","SESSION_ID","TAG_TAGS","USER_ID","METADATA","ATTR_GEN_AI_INPUT_MESSAGES","INPUT_MIME_TYPE","INPUT_VALUE","ATTR_GEN_AI_OUTPUT_MESSAGES","OUTPUT_MIME_TYPE","OUTPUT_VALUE","OtelExporter","logger","ConsoleLogger","SEMRESATTRS_PROJECT_NAME"],"mappings":";;;;;;;;;;AAoBA,IAAM,qBAAA,GAAwB,SAAA;AAC9B,IAAM,sBAAA,GAAyB,kBAAA;AAS/B,SAAS,sBAAsB,UAAA,EAG7B;AACA,EAA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AAA,UACA,QAAA,EAAU;AAAA;AACZ;AACF,KAC4B,CAAA;AAAA,EAChC;AACF","file":"index.cjs","sourcesContent":["import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from '@arizeai/openinference-genai';\nimport type { Mutable } from '@arizeai/openinference-genai/types';\nimport {\n INPUT_MIME_TYPE,\n INPUT_VALUE,\n METADATA,\n OUTPUT_MIME_TYPE,\n OUTPUT_VALUE,\n SESSION_ID,\n TAG_TAGS,\n USER_ID,\n} from '@arizeai/openinference-semantic-conventions';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport {\n ATTR_GEN_AI_INPUT_MESSAGES,\n ATTR_GEN_AI_OUTPUT_MESSAGES,\n} from '@opentelemetry/semantic-conventions/incubating';\n\nconst MASTRA_GENERAL_PREFIX = 'mastra.';\nconst MASTRA_METADATA_PREFIX = 'mastra.metadata.';\n\n/**\n * Splits Mastra span attributes into two groups:\n * - `metadata`: keys starting with \"mastra.metadata.\" (prefix removed)\n * - `other`: all remaining keys starting with \"mastra.\"\n *\n * Any attributes not starting with \"mastra.\" are ignored entirely.\n */\nfunction splitMastraAttributes(attributes: Record<string, any>): {\n mastraMetadata: Record<string, any>;\n mastraOther: Record<string, any>;\n} {\n return Object.entries(attributes).reduce(\n (acc, [key, value]) => {\n if (key.startsWith(MASTRA_GENERAL_PREFIX)) {\n if (key.startsWith(MASTRA_METADATA_PREFIX)) {\n const strippedKey = key.slice(MASTRA_METADATA_PREFIX.length);\n acc.mastraMetadata[strippedKey] = value;\n } else {\n acc.mastraOther[key] = value;\n }\n }\n return acc;\n },\n {\n mastraMetadata: {} as Record<string, any>,\n mastraOther: {} as Record<string, any>,\n },\n );\n}\n\nexport class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) {\n const processedSpans = spans.map(span => {\n const attributes = { ...(span.attributes ?? {}) };\n const mutableSpan = span as Mutable<ReadableSpan>;\n\n const { mastraMetadata, mastraOther } = splitMastraAttributes(attributes);\n const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(attributes);\n\n // only add processed attributes if conversion was successful\n if (processedAttributes) {\n const threadId = mastraMetadata['threadId'];\n if (threadId) {\n delete mastraMetadata['threadId'];\n processedAttributes[SESSION_ID] = threadId;\n }\n\n // Map mastra.tags to OpenInference native tag.tags convention (tags are only on root spans)\n if (mastraOther['mastra.tags']) {\n processedAttributes[TAG_TAGS] = mastraOther['mastra.tags'];\n delete mastraOther['mastra.tags'];\n }\n\n const userId = mastraMetadata['userId'];\n if (userId) {\n delete mastraMetadata['userId'];\n processedAttributes[USER_ID] = userId;\n }\n\n // Gather custom metadata into OpenInference metadata (flat best-effort)\n if (Object.keys(mastraMetadata).length > 0) {\n try {\n processedAttributes[METADATA] = JSON.stringify(mastraMetadata);\n } catch {\n // best-effort only\n }\n }\n\n const inputMessages = attributes[ATTR_GEN_AI_INPUT_MESSAGES];\n if (inputMessages) {\n processedAttributes[INPUT_MIME_TYPE] = 'application/json';\n processedAttributes[INPUT_VALUE] = inputMessages;\n }\n const outputMessages = attributes[ATTR_GEN_AI_OUTPUT_MESSAGES];\n if (outputMessages) {\n processedAttributes[OUTPUT_MIME_TYPE] = 'application/json';\n processedAttributes[OUTPUT_VALUE] = outputMessages;\n }\n\n mutableSpan.attributes = { ...processedAttributes, ...mastraOther };\n }\n\n return mutableSpan;\n });\n\n super.export(processedSpans, resultCallback);\n }\n}\n","import { SEMRESATTRS_PROJECT_NAME } from '@arizeai/openinference-semantic-conventions';\nimport { ConsoleLogger } from '@mastra/core/logger';\nimport { OtelExporter } from '@mastra/otel-exporter';\nimport type { OtelExporterConfig } from '@mastra/otel-exporter';\n\nimport { OpenInferenceOTLPTraceExporter } from './openInferenceOTLPExporter.js';\n\nconst LOG_PREFIX = '[ArizeExporter]';\n\nexport const ARIZE_AX_ENDPOINT = 'https://otlp.arize.com/v1/traces';\n\nexport type ArizeExporterConfig = Omit<OtelExporterConfig, 'provider'> & {\n /**\n * Required if sending traces to Arize AX\n */\n spaceId?: string;\n /**\n * Required if sending traces to Arize AX, or to any other collector that\n * requires an Authorization header\n */\n apiKey?: string;\n /**\n * Collector endpoint destination for trace exports.\n * Required when sending traces to Phoenix, Phoenix Cloud, or other collectors.\n * Optional when sending traces to Arize AX.\n */\n endpoint?: string;\n /**\n * Optional project name to be added as a resource attribute using\n * OpenInference Semantic Conventions\n */\n projectName?: string;\n /**\n * Optional headers to be added to each OTLP request\n */\n headers?: Record<string, string>;\n};\n\nexport class ArizeExporter extends OtelExporter {\n name = 'arize';\n\n constructor(config: ArizeExporterConfig) {\n const logger = new ConsoleLogger({ level: config.logLevel ?? 'warn' });\n let endpoint: string | undefined = config.endpoint;\n const headers: Record<string, string> = {\n ...config.headers,\n };\n if (config.spaceId) {\n // arize ax header configuration\n headers['space_id'] = config.spaceId;\n headers['api_key'] = config.apiKey ?? '';\n endpoint = config.endpoint || ARIZE_AX_ENDPOINT;\n } else if (config.apiKey) {\n // standard otel header configuration\n headers['Authorization'] = `Bearer ${config.apiKey}`;\n }\n if (!endpoint) {\n logger.error(`${LOG_PREFIX} Endpoint is required in configuration. Disabling exporter.`);\n return;\n }\n super({\n exporter: new OpenInferenceOTLPTraceExporter({\n url: endpoint,\n headers,\n }),\n ...config,\n resourceAttributes: {\n [SEMRESATTRS_PROJECT_NAME]: config.projectName,\n ...config.resourceAttributes,\n },\n provider: {\n custom: {\n endpoint,\n headers,\n protocol: 'http/protobuf',\n },\n } satisfies OtelExporterConfig['provider'],\n } satisfies OtelExporterConfig);\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,73 @@
|
|
|
1
|
-
import { SEMRESATTRS_PROJECT_NAME } from '@arizeai/openinference-semantic-conventions';
|
|
1
|
+
import { SEMRESATTRS_PROJECT_NAME, SESSION_ID, TAG_TAGS, USER_ID, METADATA, INPUT_MIME_TYPE, INPUT_VALUE, OUTPUT_MIME_TYPE, OUTPUT_VALUE } from '@arizeai/openinference-semantic-conventions';
|
|
2
2
|
import { ConsoleLogger } from '@mastra/core/logger';
|
|
3
3
|
import { OtelExporter } from '@mastra/otel-exporter';
|
|
4
4
|
import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from '@arizeai/openinference-genai';
|
|
5
5
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
6
|
+
import { ATTR_GEN_AI_INPUT_MESSAGES, ATTR_GEN_AI_OUTPUT_MESSAGES } from '@opentelemetry/semantic-conventions/incubating';
|
|
6
7
|
|
|
7
8
|
// src/tracing.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof parsedIO !== "object" || parsedIO == null || !("messages" in parsedIO) && !("text" in parsedIO)) {
|
|
20
|
-
return inputOutputString;
|
|
21
|
-
}
|
|
22
|
-
if ("text" in parsedIO) {
|
|
23
|
-
return JSON.stringify([
|
|
24
|
-
{
|
|
25
|
-
role: "assistant",
|
|
26
|
-
parts: [{ type: "text", content: parsedIO.text }]
|
|
9
|
+
var MASTRA_GENERAL_PREFIX = "mastra.";
|
|
10
|
+
var MASTRA_METADATA_PREFIX = "mastra.metadata.";
|
|
11
|
+
function splitMastraAttributes(attributes) {
|
|
12
|
+
return Object.entries(attributes).reduce(
|
|
13
|
+
(acc, [key, value]) => {
|
|
14
|
+
if (key.startsWith(MASTRA_GENERAL_PREFIX)) {
|
|
15
|
+
if (key.startsWith(MASTRA_METADATA_PREFIX)) {
|
|
16
|
+
const strippedKey = key.slice(MASTRA_METADATA_PREFIX.length);
|
|
17
|
+
acc.mastraMetadata[strippedKey] = value;
|
|
18
|
+
} else {
|
|
19
|
+
acc.mastraOther[key] = value;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return m;
|
|
35
|
-
}
|
|
36
|
-
const role = m.role;
|
|
37
|
-
let parts = [];
|
|
38
|
-
if (Array.isArray(m.content)) {
|
|
39
|
-
parts = m.content.map((c) => {
|
|
40
|
-
switch (c.type) {
|
|
41
|
-
case "text":
|
|
42
|
-
return {
|
|
43
|
-
type: "text",
|
|
44
|
-
content: c.text
|
|
45
|
-
};
|
|
46
|
-
case "tool-call":
|
|
47
|
-
return {
|
|
48
|
-
type: "tool_call",
|
|
49
|
-
id: c.toolCallId,
|
|
50
|
-
name: c.toolName,
|
|
51
|
-
arguments: JSON.stringify(c.input)
|
|
52
|
-
};
|
|
53
|
-
case "tool-result":
|
|
54
|
-
return {
|
|
55
|
-
type: "tool_call_response",
|
|
56
|
-
id: c.toolCallId,
|
|
57
|
-
name: c.toolName,
|
|
58
|
-
response: JSON.stringify(c.output.value)
|
|
59
|
-
};
|
|
60
|
-
default:
|
|
61
|
-
return c;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
parts = [
|
|
66
|
-
{
|
|
67
|
-
type: "text",
|
|
68
|
-
content: m.content
|
|
69
|
-
}
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
role,
|
|
74
|
-
parts
|
|
75
|
-
};
|
|
76
|
-
})
|
|
77
|
-
);
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
mastraMetadata: {},
|
|
26
|
+
mastraOther: {}
|
|
78
27
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return inputOutputString;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// src/openInferenceOTLPExporter.ts
|
|
28
|
+
);
|
|
29
|
+
}
|
|
86
30
|
var OpenInferenceOTLPTraceExporter = class extends OTLPTraceExporter {
|
|
87
31
|
export(spans, resultCallback) {
|
|
88
32
|
const processedSpans = spans.map((span) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
if (span.attributes?.["gen_ai.completion"] && typeof span.attributes["gen_ai.completion"] === "string") {
|
|
95
|
-
span.attributes["gen_ai.output.messages"] = convertMastraMessagesToGenAIMessages(
|
|
96
|
-
span.attributes["gen_ai.completion"]
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(span.attributes);
|
|
33
|
+
const attributes = { ...span.attributes ?? {} };
|
|
34
|
+
const mutableSpan = span;
|
|
35
|
+
const { mastraMetadata, mastraOther } = splitMastraAttributes(attributes);
|
|
36
|
+
const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(attributes);
|
|
100
37
|
if (processedAttributes) {
|
|
101
|
-
|
|
38
|
+
const threadId = mastraMetadata["threadId"];
|
|
39
|
+
if (threadId) {
|
|
40
|
+
delete mastraMetadata["threadId"];
|
|
41
|
+
processedAttributes[SESSION_ID] = threadId;
|
|
42
|
+
}
|
|
43
|
+
if (mastraOther["mastra.tags"]) {
|
|
44
|
+
processedAttributes[TAG_TAGS] = mastraOther["mastra.tags"];
|
|
45
|
+
delete mastraOther["mastra.tags"];
|
|
46
|
+
}
|
|
47
|
+
const userId = mastraMetadata["userId"];
|
|
48
|
+
if (userId) {
|
|
49
|
+
delete mastraMetadata["userId"];
|
|
50
|
+
processedAttributes[USER_ID] = userId;
|
|
51
|
+
}
|
|
52
|
+
if (Object.keys(mastraMetadata).length > 0) {
|
|
53
|
+
try {
|
|
54
|
+
processedAttributes[METADATA] = JSON.stringify(mastraMetadata);
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const inputMessages = attributes[ATTR_GEN_AI_INPUT_MESSAGES];
|
|
59
|
+
if (inputMessages) {
|
|
60
|
+
processedAttributes[INPUT_MIME_TYPE] = "application/json";
|
|
61
|
+
processedAttributes[INPUT_VALUE] = inputMessages;
|
|
62
|
+
}
|
|
63
|
+
const outputMessages = attributes[ATTR_GEN_AI_OUTPUT_MESSAGES];
|
|
64
|
+
if (outputMessages) {
|
|
65
|
+
processedAttributes[OUTPUT_MIME_TYPE] = "application/json";
|
|
66
|
+
processedAttributes[OUTPUT_VALUE] = outputMessages;
|
|
67
|
+
}
|
|
68
|
+
mutableSpan.attributes = { ...processedAttributes, ...mastraOther };
|
|
102
69
|
}
|
|
103
|
-
return
|
|
70
|
+
return mutableSpan;
|
|
104
71
|
});
|
|
105
72
|
super.export(processedSpans, resultCallback);
|
|
106
73
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gen-ai.ts","../src/openInferenceOTLPExporter.ts","../src/tracing.ts"],"names":[],"mappings":";;;;;;;;;AAgDA,IAAM,mBAAA,GAAsB,CAAC,CAAA,KAAuC;AAClE,EAAA,OACE,OAAO,CAAA,KAAM,QAAA,IACb,CAAA,IAAK,IAAA,IACL,UAAU,CAAA,KACT,CAAA,CAAE,IAAA,KAAS,MAAA,IAAU,EAAE,IAAA,KAAS,WAAA,IAAe,CAAA,CAAE,IAAA,KAAS,mBACzD,CAAA,CAAE,IAAA,KAAS,MAAA,IAAU,MAAA,IAAU,KAC9B,CAAA,CAAE,IAAA,KAAS,WAAA,IAAe,YAAA,IAAgB,KAAK,UAAA,IAAc,CAAA,IAAK,OAAA,IAAW,CAAA,IAC7E,EAAE,IAAA,KAAS,aAAA,IAAiB,gBAAgB,CAAA,IAAK,UAAA,IAAc,KAAK,QAAA,IAAY,CAAA,CAAA;AAEvF,CAAA;AAEA,IAAM,eAAA,GAAkB,CAAC,CAAA,KAAmC;AAC1D,EAAA,OACE,OAAO,MAAM,QAAA,IACb,CAAA,IAAK,QACL,MAAA,IAAU,CAAA,IACV,aAAa,CAAA,KACZ,O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MAAA,QAAA,GAAW,OAAO,QAAA,IAAY,iBAAA;AAAA,IAChC,CAAA,MAAA,IAAW,OAAO,MAAA,EAAQ;AAExB,MAAA,OAAA,CAAQ,eAAe,CAAA,GAAI,CAAA,OAAA,EAAU,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,IACpD;AACA,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,UAAU,CAAA,2DAAA,CAA6D,CAAA;AACvF,MAAA;AAAA,IACF;AACA,IAAA,KAAA,CAAM;AAAA,MACJ,QAAA,EAAU,IAAI,8BAAA,CAA+B;AAAA,QAC3C,GAAA,EAAK,QAAA;AAAA,QACL;AAAA,OACD,CAAA;AAAA,MACD,GAAG,MAAA;AAAA,MACH,kBAAA,EAAoB;AAAA,QAClB,CAAC,wBAAwB,GAAG,MAAA,CAAO,WAAA;AAAA,QACnC,GAAG,MAAA,CAAO;AAAA,OACZ;AAAA,MACA,QAAA,EAAU;AAAA,QACR,MAAA,EAAQ;AAAA,UACN,QAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA,EAAU;AAAA;AACZ;AACF,KAC4B,CAAA;AAAA,EAChC;AACF","file":"index.js","sourcesContent":["/**\n * Type represenation of a gen_ai chat message part\n */\ntype GenAIMessagePart =\n | {\n type: 'text';\n content: string;\n }\n | {\n type: 'tool_call';\n id: string;\n name: string;\n arguments: string;\n }\n | {\n type: 'tool_call_response';\n id: string;\n name: string;\n response: string;\n };\n\n/**\n * Type representation of a gen_ai chat message\n */\ntype GenAIMessage = {\n role: string;\n parts: GenAIMessagePart[];\n};\n\n/**\n * Assumed type representation of a Mastra message content type\n */\ntype MastraMessagePart =\n | {\n type: 'text';\n text: string;\n }\n | { type: 'tool-call'; toolCallId: string; toolName: string; input: unknown }\n | { type: 'tool-result'; toolCallId: string; toolName: string; output: { value: unknown } };\n\n/**\n * Assumed type representation of a Mastra message\n */\ntype MastraMessage = {\n role: string;\n content: MastraMessagePart[];\n};\n\nconst isMastraMessagePart = (p: unknown): p is MastraMessagePart => {\n return (\n typeof p === 'object' &&\n p != null &&\n 'type' in p &&\n (p.type === 'text' || p.type === 'tool-call' || p.type === 'tool-result') &&\n ((p.type === 'text' && 'text' in p) ||\n (p.type === 'tool-call' && 'toolCallId' in p && 'toolName' in p && 'input' in p) ||\n (p.type === 'tool-result' && 'toolCallId' in p && 'toolName' in p && 'output' in p))\n );\n};\n\nconst isMastraMessage = (m: unknown): m is MastraMessage => {\n return (\n typeof m === 'object' &&\n m != null &&\n 'role' in m &&\n 'content' in m &&\n (typeof m.content === 'string' || (Array.isArray(m.content) && m.content.every(isMastraMessagePart)))\n );\n};\n\n/**\n * Convert an Input/Output string from a MastraSpan into a jsonified string that adheres to\n * OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.\n * If parsing fails at any step, the original inputOutputString is returned unmodified.\n *\n * This conversion is best effort; It assumes a consistent shape for mastra messages, and converts\n * into the gen_ai input and output schemas as of October 20th, 2025.\n *\n * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json\n * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-output-messages\n * @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json\n *\n * @param inputOutputString a jsonified string that contains messages adhering to what appears to be\n * Mastra's message shape.\n * @returns a jsonified string that contains messages adhering to the OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.\n * If parsing fails at any step, the original inputOutputString is returned unmodified.\n */\nexport const convertMastraMessagesToGenAIMessages = (inputOutputString: string): string => {\n try {\n const parsedIO = JSON.parse(inputOutputString) as unknown;\n if (typeof parsedIO !== 'object' || parsedIO == null || (!('messages' in parsedIO) && !('text' in parsedIO))) {\n // inputOutputString fails initial type guard, just return it\n return inputOutputString;\n }\n // if the IO simply contains a text string, return a single text message\n // formatted as a gen_ai assistant message, assuming its an assistant response\n if ('text' in parsedIO) {\n return JSON.stringify([\n {\n role: 'assistant',\n parts: [{ type: 'text', content: parsedIO.text as string }],\n } satisfies GenAIMessage,\n ]);\n }\n // if the IO contains messages, convert them to gen_ai messages\n if (Array.isArray(parsedIO.messages)) {\n return JSON.stringify(\n (parsedIO.messages as unknown[]).map(m => {\n if (!isMastraMessage(m)) {\n return m;\n }\n const role = m.role;\n let parts: GenAIMessagePart[] = [];\n if (Array.isArray(m.content)) {\n parts = m.content.map(c => {\n switch (c.type) {\n case 'text':\n return {\n type: 'text',\n content: c.text,\n };\n case 'tool-call':\n return {\n type: 'tool_call',\n id: c.toolCallId,\n name: c.toolName,\n arguments: JSON.stringify(c.input),\n };\n case 'tool-result':\n return {\n type: 'tool_call_response',\n id: c.toolCallId,\n name: c.toolName,\n response: JSON.stringify(c.output.value),\n };\n default:\n return c;\n }\n });\n } else {\n parts = [\n {\n type: 'text',\n content: m.content,\n },\n ];\n }\n return {\n role,\n parts,\n } satisfies GenAIMessage;\n }),\n );\n }\n // we've failed type-guards, just return original I/O string\n return inputOutputString;\n } catch {\n // silently fallback to original I/O string\n return inputOutputString;\n }\n};\n","import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from '@arizeai/openinference-genai';\nimport type { Mutable } from '@arizeai/openinference-genai/types';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { convertMastraMessagesToGenAIMessages } from './gen-ai';\n\nexport class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) {\n const processedSpans = spans.map(span => {\n // convert Mastra input messages to GenAI messages if present\n if (span.attributes?.['gen_ai.prompt'] && typeof span.attributes['gen_ai.prompt'] === 'string') {\n span.attributes['gen_ai.input.messages'] = convertMastraMessagesToGenAIMessages(\n span.attributes['gen_ai.prompt'],\n );\n }\n // convert Mastra output messages to GenAI messages if present\n if (span.attributes?.['gen_ai.completion'] && typeof span.attributes['gen_ai.completion'] === 'string') {\n span.attributes['gen_ai.output.messages'] = convertMastraMessagesToGenAIMessages(\n span.attributes['gen_ai.completion'],\n );\n }\n const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(span.attributes);\n // only add processed attributes if conversion was successful\n if (processedAttributes) {\n (span as Mutable<ReadableSpan>).attributes = processedAttributes;\n }\n return span;\n });\n\n super.export(processedSpans, resultCallback);\n }\n}\n","import { SEMRESATTRS_PROJECT_NAME } from '@arizeai/openinference-semantic-conventions';\nimport { ConsoleLogger } from '@mastra/core/logger';\nimport { OtelExporter } from '@mastra/otel-exporter';\nimport type { OtelExporterConfig } from '@mastra/otel-exporter';\n\nimport { OpenInferenceOTLPTraceExporter } from './openInferenceOTLPExporter.js';\n\nconst LOG_PREFIX = '[ArizeExporter]';\n\nexport const ARIZE_AX_ENDPOINT = 'https://otlp.arize.com/v1/traces';\n\nexport type ArizeExporterConfig = Omit<OtelExporterConfig, 'provider'> & {\n /**\n * Required if sending traces to Arize AX\n */\n spaceId?: string;\n /**\n * Required if sending traces to Arize AX, or to any other collector that\n * requires an Authorization header\n */\n apiKey?: string;\n /**\n * Collector endpoint destination for trace exports.\n * Required when sending traces to Phoenix, Phoenix Cloud, or other collectors.\n * Optional when sending traces to Arize AX.\n */\n endpoint?: string;\n /**\n * Optional project name to be added as a resource attribute using\n * OpenInference Semantic Conventions\n */\n projectName?: string;\n /**\n * Optional headers to be added to each OTLP request\n */\n headers?: Record<string, string>;\n};\n\nexport class ArizeExporter extends OtelExporter {\n name = 'arize';\n\n constructor(config: ArizeExporterConfig) {\n const logger = new ConsoleLogger({ level: config.logLevel ?? 'warn' });\n let endpoint: string | undefined = config.endpoint;\n const headers: Record<string, string> = {\n ...config.headers,\n };\n if (config.spaceId) {\n // arize ax header configuration\n headers['space_id'] = config.spaceId;\n headers['api_key'] = config.apiKey ?? '';\n endpoint = config.endpoint || ARIZE_AX_ENDPOINT;\n } else if (config.apiKey) {\n // standard otel header configuration\n headers['Authorization'] = `Bearer ${config.apiKey}`;\n }\n if (!endpoint) {\n logger.error(`${LOG_PREFIX} Endpoint is required in configuration. Disabling exporter.`);\n return;\n }\n super({\n exporter: new OpenInferenceOTLPTraceExporter({\n url: endpoint,\n headers,\n }),\n ...config,\n resourceAttributes: {\n [SEMRESATTRS_PROJECT_NAME]: config.projectName,\n ...config.resourceAttributes,\n },\n provider: {\n custom: {\n endpoint,\n headers,\n protocol: 'http/protobuf',\n },\n } satisfies OtelExporterConfig['provider'],\n } satisfies OtelExporterConfig);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/openInferenceOTLPExporter.ts","../src/tracing.ts"],"names":[],"mappings":";;;;;;;;AAoBA,IAAM,qBAAA,GAAwB,SAAA;AAC9B,IAAM,sBAAA,GAAyB,kBAAA;AAS/B,SAAS,sBAAsB,UAAA,EAG7B;AACA,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,CAAE,MAAA;AAAA,IAChC,CAAC,GAAA,EAAK,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM;AACrB,MAAA,IAAI,GAAA,CAAI,UAAA,CAAW,qBAAqB,CAAA,EAAG;AACzC,QAAA,IAAI,GAAA,CAAI,UAAA,CAAW,sBAAsB,CAAA,EAAG;AAC1C,UAAA,MAAM,WAAA,GAAc,GAAA,CAAI,KAAA,CAAM,sBAAA,CAAuB,MAAM,CAAA;AAC3D,UAAA,GAAA,CAAI,cAAA,CAAe,WAAW,CAAA,GAAI,KAAA;AAAA,QACpC,CAAA,MAAO;AACL,UAAA,GAAA,CAAI,WAAA,CAAY,GAAG,CAAA,GAAI,KAAA;AAAA,QACzB;AAAA,MACF;AACA,MAAA,OAAO,GAAA;AAAA,IACT,CAAA;AAAA,IACA;AAAA,MACE,gBAAgB,EAAC;AAAA,MACjB,aAAa;AAAC;AAChB,GACF;AACF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AAExB,MAAA,OAAA,CAAQ,eAAe,CAAA,GAAI,CAAA,OAAA,EAAU,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,IACpD;AACA,IAAA,IAAI,CAAC,QAAA,EAAU;AACb,MAAA,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,UAAU,CAAA,2DAAA,CAA6D,CAAA;AACvF,MAAA;AAAA,IACF;AACA,IAAA,KAAA,CAAM;AAAA,MACJ,QAAA,EAAU,IAAI,8BAAA,CAA+B;AAAA,QAC3C,GAAA,EAAK,QAAA;AAAA,QACL;AAAA,OACD,CAAA;AAAA,MACD,GAAG,MAAA;AAAA,MACH,kBAAA,EAAoB;AAAA,QAClB,CAAC,wBAAwB,GAAG,MAAA,CAAO,WAAA;AAAA,QACnC,GAAG,MAAA,CAAO;AAAA,OACZ;AAAA,MACA,QAAA,EAAU;AAAA,QACR,MAAA,EAAQ;AAAA,UACN,QAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA,EAAU;AAAA;AACZ;AACF,KAC4B,CAAA;AAAA,EAChC;AACF","file":"index.js","sourcesContent":["import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from '@arizeai/openinference-genai';\nimport type { Mutable } from '@arizeai/openinference-genai/types';\nimport {\n INPUT_MIME_TYPE,\n INPUT_VALUE,\n METADATA,\n OUTPUT_MIME_TYPE,\n OUTPUT_VALUE,\n SESSION_ID,\n TAG_TAGS,\n USER_ID,\n} from '@arizeai/openinference-semantic-conventions';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';\nimport type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport {\n ATTR_GEN_AI_INPUT_MESSAGES,\n ATTR_GEN_AI_OUTPUT_MESSAGES,\n} from '@opentelemetry/semantic-conventions/incubating';\n\nconst MASTRA_GENERAL_PREFIX = 'mastra.';\nconst MASTRA_METADATA_PREFIX = 'mastra.metadata.';\n\n/**\n * Splits Mastra span attributes into two groups:\n * - `metadata`: keys starting with \"mastra.metadata.\" (prefix removed)\n * - `other`: all remaining keys starting with \"mastra.\"\n *\n * Any attributes not starting with \"mastra.\" are ignored entirely.\n */\nfunction splitMastraAttributes(attributes: Record<string, any>): {\n mastraMetadata: Record<string, any>;\n mastraOther: Record<string, any>;\n} {\n return Object.entries(attributes).reduce(\n (acc, [key, value]) => {\n if (key.startsWith(MASTRA_GENERAL_PREFIX)) {\n if (key.startsWith(MASTRA_METADATA_PREFIX)) {\n const strippedKey = key.slice(MASTRA_METADATA_PREFIX.length);\n acc.mastraMetadata[strippedKey] = value;\n } else {\n acc.mastraOther[key] = value;\n }\n }\n return acc;\n },\n {\n mastraMetadata: {} as Record<string, any>,\n mastraOther: {} as Record<string, any>,\n },\n );\n}\n\nexport class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {\n export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) {\n const processedSpans = spans.map(span => {\n const attributes = { ...(span.attributes ?? {}) };\n const mutableSpan = span as Mutable<ReadableSpan>;\n\n const { mastraMetadata, mastraOther } = splitMastraAttributes(attributes);\n const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(attributes);\n\n // only add processed attributes if conversion was successful\n if (processedAttributes) {\n const threadId = mastraMetadata['threadId'];\n if (threadId) {\n delete mastraMetadata['threadId'];\n processedAttributes[SESSION_ID] = threadId;\n }\n\n // Map mastra.tags to OpenInference native tag.tags convention (tags are only on root spans)\n if (mastraOther['mastra.tags']) {\n processedAttributes[TAG_TAGS] = mastraOther['mastra.tags'];\n delete mastraOther['mastra.tags'];\n }\n\n const userId = mastraMetadata['userId'];\n if (userId) {\n delete mastraMetadata['userId'];\n processedAttributes[USER_ID] = userId;\n }\n\n // Gather custom metadata into OpenInference metadata (flat best-effort)\n if (Object.keys(mastraMetadata).length > 0) {\n try {\n processedAttributes[METADATA] = JSON.stringify(mastraMetadata);\n } catch {\n // best-effort only\n }\n }\n\n const inputMessages = attributes[ATTR_GEN_AI_INPUT_MESSAGES];\n if (inputMessages) {\n processedAttributes[INPUT_MIME_TYPE] = 'application/json';\n processedAttributes[INPUT_VALUE] = inputMessages;\n }\n const outputMessages = attributes[ATTR_GEN_AI_OUTPUT_MESSAGES];\n if (outputMessages) {\n processedAttributes[OUTPUT_MIME_TYPE] = 'application/json';\n processedAttributes[OUTPUT_VALUE] = outputMessages;\n }\n\n mutableSpan.attributes = { ...processedAttributes, ...mastraOther };\n }\n\n return mutableSpan;\n });\n\n super.export(processedSpans, resultCallback);\n }\n}\n","import { SEMRESATTRS_PROJECT_NAME } from '@arizeai/openinference-semantic-conventions';\nimport { ConsoleLogger } from '@mastra/core/logger';\nimport { OtelExporter } from '@mastra/otel-exporter';\nimport type { OtelExporterConfig } from '@mastra/otel-exporter';\n\nimport { OpenInferenceOTLPTraceExporter } from './openInferenceOTLPExporter.js';\n\nconst LOG_PREFIX = '[ArizeExporter]';\n\nexport const ARIZE_AX_ENDPOINT = 'https://otlp.arize.com/v1/traces';\n\nexport type ArizeExporterConfig = Omit<OtelExporterConfig, 'provider'> & {\n /**\n * Required if sending traces to Arize AX\n */\n spaceId?: string;\n /**\n * Required if sending traces to Arize AX, or to any other collector that\n * requires an Authorization header\n */\n apiKey?: string;\n /**\n * Collector endpoint destination for trace exports.\n * Required when sending traces to Phoenix, Phoenix Cloud, or other collectors.\n * Optional when sending traces to Arize AX.\n */\n endpoint?: string;\n /**\n * Optional project name to be added as a resource attribute using\n * OpenInference Semantic Conventions\n */\n projectName?: string;\n /**\n * Optional headers to be added to each OTLP request\n */\n headers?: Record<string, string>;\n};\n\nexport class ArizeExporter extends OtelExporter {\n name = 'arize';\n\n constructor(config: ArizeExporterConfig) {\n const logger = new ConsoleLogger({ level: config.logLevel ?? 'warn' });\n let endpoint: string | undefined = config.endpoint;\n const headers: Record<string, string> = {\n ...config.headers,\n };\n if (config.spaceId) {\n // arize ax header configuration\n headers['space_id'] = config.spaceId;\n headers['api_key'] = config.apiKey ?? '';\n endpoint = config.endpoint || ARIZE_AX_ENDPOINT;\n } else if (config.apiKey) {\n // standard otel header configuration\n headers['Authorization'] = `Bearer ${config.apiKey}`;\n }\n if (!endpoint) {\n logger.error(`${LOG_PREFIX} Endpoint is required in configuration. Disabling exporter.`);\n return;\n }\n super({\n exporter: new OpenInferenceOTLPTraceExporter({\n url: endpoint,\n headers,\n }),\n ...config,\n resourceAttributes: {\n [SEMRESATTRS_PROJECT_NAME]: config.projectName,\n ...config.resourceAttributes,\n },\n provider: {\n custom: {\n endpoint,\n headers,\n protocol: 'http/protobuf',\n },\n } satisfies OtelExporterConfig['provider'],\n } satisfies OtelExporterConfig);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openInferenceOTLPExporter.d.ts","sourceRoot":"","sources":["../src/openInferenceOTLPExporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openInferenceOTLPExporter.d.ts","sourceRoot":"","sources":["../src/openInferenceOTLPExporter.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAuClE,qBAAa,8BAA+B,SAAQ,iBAAiB;IACnE,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;CAwD7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/arize",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Arize observability provider for Mastra - includes tracing and future observability features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,20 +30,21 @@
|
|
|
30
30
|
"@opentelemetry/exporter-trace-otlp-proto": "^0.205.0",
|
|
31
31
|
"@opentelemetry/resources": "^2.1.0",
|
|
32
32
|
"@opentelemetry/sdk-trace-base": "^2.1.0",
|
|
33
|
-
"@
|
|
33
|
+
"@opentelemetry/semantic-conventions": "1.38.0",
|
|
34
|
+
"@mastra/otel-exporter": "1.0.0-beta.3"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@microsoft/api-extractor": "^7.52.8",
|
|
37
38
|
"@types/node": "22.13.17",
|
|
38
|
-
"@vitest/coverage-v8": "4.0.
|
|
39
|
-
"@vitest/ui": "4.0.
|
|
39
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
40
|
+
"@vitest/ui": "4.0.12",
|
|
40
41
|
"eslint": "^9.36.0",
|
|
41
42
|
"tsup": "^8.5.0",
|
|
42
43
|
"typescript": "^5.8.3",
|
|
43
|
-
"vitest": "
|
|
44
|
+
"vitest": "4.0.12",
|
|
45
|
+
"@internal/types-builder": "0.0.28",
|
|
44
46
|
"@internal/lint": "0.0.53",
|
|
45
|
-
"@mastra/core": "1.0.0-beta.
|
|
46
|
-
"@internal/types-builder": "0.0.28"
|
|
47
|
+
"@mastra/core": "1.0.0-beta.7"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
package/dist/gen-ai.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert an Input/Output string from a MastraSpan into a jsonified string that adheres to
|
|
3
|
-
* OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.
|
|
4
|
-
* If parsing fails at any step, the original inputOutputString is returned unmodified.
|
|
5
|
-
*
|
|
6
|
-
* This conversion is best effort; It assumes a consistent shape for mastra messages, and converts
|
|
7
|
-
* into the gen_ai input and output schemas as of October 20th, 2025.
|
|
8
|
-
*
|
|
9
|
-
* @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages
|
|
10
|
-
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json
|
|
11
|
-
* @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-output-messages
|
|
12
|
-
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json
|
|
13
|
-
*
|
|
14
|
-
* @param inputOutputString a jsonified string that contains messages adhering to what appears to be
|
|
15
|
-
* Mastra's message shape.
|
|
16
|
-
* @returns a jsonified string that contains messages adhering to the OpenTelemetry gen_ai.input.messages and gen_ai.output.messages schema.
|
|
17
|
-
* If parsing fails at any step, the original inputOutputString is returned unmodified.
|
|
18
|
-
*/
|
|
19
|
-
export declare const convertMastraMessagesToGenAIMessages: (inputOutputString: string) => string;
|
|
20
|
-
//# sourceMappingURL=gen-ai.d.ts.map
|
package/dist/gen-ai.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gen-ai.d.ts","sourceRoot":"","sources":["../src/gen-ai.ts"],"names":[],"mappings":"AAsEA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oCAAoC,GAAI,mBAAmB,MAAM,KAAG,MAyEhF,CAAC"}
|