@ai-sdk/otel 1.0.131 → 1.0.133
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 +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -29
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/legacy-open-telemetry.ts +6 -3
- package/src/open-telemetry.ts +3 -2
- package/src/stringify-for-telemetry.ts +36 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/otel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.133",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ai-sdk/provider": "4.0.
|
|
29
|
+
"@ai-sdk/provider": "4.0.25",
|
|
30
30
|
"@opentelemetry/api": "1.9.1",
|
|
31
|
-
"ai": "7.0.
|
|
31
|
+
"ai": "7.0.133"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.57",
|
|
35
35
|
"@opentelemetry/sdk-trace-base": "2.7.1",
|
|
36
36
|
"@types/node": "22.19.19",
|
|
37
37
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
@@ -50,7 +50,10 @@ import { assembleOperationName } from './assemble-operation-name';
|
|
|
50
50
|
import { getBaseTelemetryAttributes } from './get-base-telemetry-attributes';
|
|
51
51
|
import { getProviderUsageAttributes } from './provider-usage-attributes';
|
|
52
52
|
import { sanitizeAttributeValue } from './sanitize-attribute-value';
|
|
53
|
-
import {
|
|
53
|
+
import {
|
|
54
|
+
stringifyForTelemetry,
|
|
55
|
+
stringifyDecisionStateForTelemetry,
|
|
56
|
+
} from './stringify-for-telemetry';
|
|
54
57
|
|
|
55
58
|
function recordSpanError(span: Span, error: unknown): void {
|
|
56
59
|
if (error instanceof Error) {
|
|
@@ -1302,7 +1305,7 @@ export class LegacyOpenTelemetry implements Telemetry {
|
|
|
1302
1305
|
...assembleOperationName({ operationId: event.operationId, telemetry }),
|
|
1303
1306
|
...baseTelemetryAttributes,
|
|
1304
1307
|
'ai.decision.state': {
|
|
1305
|
-
input: () =>
|
|
1308
|
+
input: () => stringifyDecisionStateForTelemetry(event.state),
|
|
1306
1309
|
},
|
|
1307
1310
|
'ai.decision.questions': {
|
|
1308
1311
|
input: () => JSON.stringify(event.questions),
|
|
@@ -1389,7 +1392,7 @@ export class LegacyOpenTelemetry implements Telemetry {
|
|
|
1389
1392
|
}),
|
|
1390
1393
|
...state.baseTelemetryAttributes,
|
|
1391
1394
|
'ai.decision.state': {
|
|
1392
|
-
input: () =>
|
|
1395
|
+
input: () => stringifyDecisionStateForTelemetry(event.state),
|
|
1393
1396
|
},
|
|
1394
1397
|
'ai.decision.questions': {
|
|
1395
1398
|
input: () => JSON.stringify(event.questions),
|
package/src/open-telemetry.ts
CHANGED
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
mapOperationName,
|
|
55
55
|
mapProviderName,
|
|
56
56
|
} from './gen-ai-format-messages';
|
|
57
|
+
import { stringifyDecisionStateForTelemetry } from './stringify-for-telemetry';
|
|
57
58
|
import { recordErrorOnSpan } from './record-span';
|
|
58
59
|
import { getProviderUsageAttributes } from './provider-usage-attributes';
|
|
59
60
|
import { sanitizeAttributes } from './sanitize-attribute-value';
|
|
@@ -1665,7 +1666,7 @@ export class OpenTelemetry implements Telemetry {
|
|
|
1665
1666
|
...selectSupplementalAttributes(telemetry, this.supplementalAttributes, {
|
|
1666
1667
|
experimental_decision: {
|
|
1667
1668
|
'ai.decision.state': {
|
|
1668
|
-
input: () =>
|
|
1669
|
+
input: () => stringifyDecisionStateForTelemetry(event.state),
|
|
1669
1670
|
},
|
|
1670
1671
|
'ai.decision.questions': {
|
|
1671
1672
|
input: () => JSON.stringify(event.questions),
|
|
@@ -1778,7 +1779,7 @@ export class OpenTelemetry implements Telemetry {
|
|
|
1778
1779
|
{
|
|
1779
1780
|
experimental_decision: {
|
|
1780
1781
|
'ai.decision.state': {
|
|
1781
|
-
input: () =>
|
|
1782
|
+
input: () => stringifyDecisionStateForTelemetry(event.state),
|
|
1782
1783
|
},
|
|
1783
1784
|
'ai.decision.questions': {
|
|
1784
1785
|
input: () => JSON.stringify(event.questions),
|
|
@@ -2,7 +2,12 @@ import type {
|
|
|
2
2
|
LanguageModelV4Message,
|
|
3
3
|
LanguageModelV4Prompt,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
convertDataContentToBase64String,
|
|
7
|
+
type Experimental_DecisionState as DecisionState,
|
|
8
|
+
type Experimental_DecisionStatePart as DecisionStatePart,
|
|
9
|
+
type FilePart,
|
|
10
|
+
} from 'ai';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Helper utility to serialize prompt content for OpenTelemetry tracing.
|
|
@@ -29,23 +34,43 @@ export function stringifyForTelemetry(prompt: LanguageModelV4Prompt): string {
|
|
|
29
34
|
);
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
function isDecisionStateParts(
|
|
38
|
+
state: DecisionState,
|
|
39
|
+
): state is readonly DecisionStatePart[] {
|
|
40
|
+
return Array.isArray(state);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Serialize decision files using the same representation as prompt files. */
|
|
44
|
+
export function stringifyDecisionStateForTelemetry(
|
|
45
|
+
state: DecisionState,
|
|
46
|
+
): string {
|
|
47
|
+
return JSON.stringify(
|
|
48
|
+
isDecisionStateParts(state)
|
|
49
|
+
? state.map(part =>
|
|
50
|
+
part.type === 'file'
|
|
51
|
+
? { ...part, data: serializeFileData(part.data) }
|
|
52
|
+
: part,
|
|
53
|
+
)
|
|
54
|
+
: state,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function serializeFileData(data: FilePart['data']): unknown {
|
|
59
|
+
if (typeof data === 'string') return data;
|
|
60
|
+
if (data instanceof URL) return data.toString();
|
|
61
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
62
|
+
return convertDataContentToBase64String(data);
|
|
63
|
+
}
|
|
39
64
|
switch (data.type) {
|
|
40
65
|
case 'data':
|
|
41
|
-
return data.data
|
|
42
|
-
? convertDataContentToBase64String(data.data)
|
|
43
|
-
: data.data;
|
|
66
|
+
return convertDataContentToBase64String(data.data);
|
|
44
67
|
case 'url':
|
|
45
68
|
return data.url.toString();
|
|
46
69
|
case 'reference':
|
|
47
70
|
return data.reference;
|
|
48
71
|
case 'text':
|
|
49
72
|
return data.text;
|
|
73
|
+
default:
|
|
74
|
+
return data;
|
|
50
75
|
}
|
|
51
76
|
}
|