@ai-sdk/otel 1.0.0-beta.55 → 1.0.0-beta.58
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 +63 -0
- package/dist/index.d.ts +29 -32
- package/dist/index.js +122 -74
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/index.ts +2 -2
- package/src/{open-telemetry-integration.ts → legacy-open-telemetry.ts} +69 -60
- package/src/{gen-ai-open-telemetry-integration.ts → open-telemetry.ts} +187 -122
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/otel",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.58",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,23 +26,24 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@opentelemetry/api": "1.9.
|
|
30
|
-
"ai": "
|
|
31
|
-
"
|
|
29
|
+
"@opentelemetry/api": "1.9.1",
|
|
30
|
+
"@ai-sdk/provider": "4.0.0-beta.12",
|
|
31
|
+
"ai": "7.0.0-beta.112"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "20.17.24",
|
|
35
35
|
"tsup": "^8",
|
|
36
36
|
"typescript": "5.8.3",
|
|
37
37
|
"zod": "3.25.76",
|
|
38
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
38
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.27",
|
|
39
39
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=18"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
46
47
|
},
|
|
47
48
|
"homepage": "https://ai-sdk.dev/docs",
|
|
48
49
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { OpenTelemetry } from './open-telemetry';
|
|
2
|
+
export { LegacyOpenTelemetry } from './legacy-open-telemetry';
|
|
@@ -11,27 +11,28 @@ import {
|
|
|
11
11
|
Tracer,
|
|
12
12
|
} from '@opentelemetry/api';
|
|
13
13
|
import type {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
EmbedOnStartEvent,
|
|
14
|
+
EmbeddingModelCallEndEvent,
|
|
15
|
+
EmbedEndEvent,
|
|
17
16
|
EmbedStartEvent,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
EmbeddingModelCallStartEvent,
|
|
18
|
+
GenerateObjectEndEvent,
|
|
19
|
+
GenerateObjectStartEvent,
|
|
20
|
+
GenerateObjectStepEndEvent,
|
|
21
|
+
GenerateObjectStepStartEvent,
|
|
22
|
+
StreamTextChunkEvent,
|
|
23
|
+
GenerateTextEndEvent,
|
|
24
|
+
GenerateTextStartEvent,
|
|
25
|
+
GenerateTextStepEndEvent,
|
|
26
|
+
GenerateTextStepStartEvent,
|
|
27
27
|
ToolExecutionEndEvent,
|
|
28
28
|
ToolExecutionStartEvent,
|
|
29
29
|
OutputInterface as Output,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
RerankOnStartEvent,
|
|
30
|
+
RerankingModelCallEndEvent,
|
|
31
|
+
RerankEndEvent,
|
|
33
32
|
RerankStartEvent,
|
|
34
|
-
|
|
33
|
+
RerankingModelCallStartEvent,
|
|
34
|
+
InferTelemetryEvent,
|
|
35
|
+
Telemetry,
|
|
35
36
|
TelemetryOptions,
|
|
36
37
|
ToolSet,
|
|
37
38
|
} from 'ai';
|
|
@@ -112,7 +113,7 @@ interface OtelStepStartEvent<
|
|
|
112
113
|
TOOLS extends ToolSet = ToolSet,
|
|
113
114
|
RUNTIME_CONTEXT extends AISDKContext = AISDKContext,
|
|
114
115
|
OUTPUT extends Output = Output,
|
|
115
|
-
> extends
|
|
116
|
+
> extends GenerateTextStepStartEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT> {
|
|
116
117
|
readonly promptMessages?: LanguageModelV4Prompt;
|
|
117
118
|
readonly stepTools?: ReadonlyArray<Record<string, unknown>>;
|
|
118
119
|
readonly stepToolChoice?: unknown;
|
|
@@ -132,7 +133,7 @@ interface CallState {
|
|
|
132
133
|
settings: Record<string, unknown>;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
export class
|
|
136
|
+
export class LegacyOpenTelemetry implements Telemetry {
|
|
136
137
|
private readonly callStates = new Map<string, CallState>();
|
|
137
138
|
|
|
138
139
|
/**
|
|
@@ -176,23 +177,23 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
176
177
|
|
|
177
178
|
onStart(
|
|
178
179
|
event:
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
180
|
+
| InferTelemetryEvent<GenerateTextStartEvent>
|
|
181
|
+
| InferTelemetryEvent<GenerateObjectStartEvent>
|
|
182
|
+
| InferTelemetryEvent<EmbedStartEvent>
|
|
183
|
+
| InferTelemetryEvent<RerankStartEvent>,
|
|
183
184
|
): void {
|
|
184
|
-
if (event.isEnabled === false) return;
|
|
185
|
-
|
|
186
185
|
if (
|
|
187
186
|
event.operationId === 'ai.embed' ||
|
|
188
187
|
event.operationId === 'ai.embedMany'
|
|
189
188
|
) {
|
|
190
|
-
this.onEmbedOperationStart(event as
|
|
189
|
+
this.onEmbedOperationStart(event as InferTelemetryEvent<EmbedStartEvent>);
|
|
191
190
|
return;
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
if (event.operationId === 'ai.rerank') {
|
|
195
|
-
this.onRerankOperationStart(
|
|
194
|
+
this.onRerankOperationStart(
|
|
195
|
+
event as InferTelemetryEvent<RerankStartEvent>,
|
|
196
|
+
);
|
|
196
197
|
return;
|
|
197
198
|
}
|
|
198
199
|
|
|
@@ -200,16 +201,19 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
200
201
|
event.operationId === 'ai.generateObject' ||
|
|
201
202
|
event.operationId === 'ai.streamObject'
|
|
202
203
|
) {
|
|
203
|
-
this.onObjectOperationStart(
|
|
204
|
+
this.onObjectOperationStart(
|
|
205
|
+
event as InferTelemetryEvent<GenerateObjectStartEvent>,
|
|
206
|
+
);
|
|
204
207
|
return;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
this.onGenerateStart(event as
|
|
210
|
+
this.onGenerateStart(event as InferTelemetryEvent<GenerateTextStartEvent>);
|
|
208
211
|
}
|
|
209
212
|
|
|
210
|
-
private onGenerateStart(
|
|
213
|
+
private onGenerateStart(
|
|
214
|
+
event: InferTelemetryEvent<GenerateTextStartEvent>,
|
|
215
|
+
): void {
|
|
211
216
|
const telemetry: TelemetryOptions = {
|
|
212
|
-
isEnabled: event.isEnabled,
|
|
213
217
|
recordInputs: event.recordInputs,
|
|
214
218
|
recordOutputs: event.recordOutputs,
|
|
215
219
|
functionId: event.functionId,
|
|
@@ -246,7 +250,6 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
246
250
|
input: () =>
|
|
247
251
|
JSON.stringify({
|
|
248
252
|
system: event.system,
|
|
249
|
-
prompt: event.prompt,
|
|
250
253
|
messages: event.messages,
|
|
251
254
|
}),
|
|
252
255
|
},
|
|
@@ -270,9 +273,10 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
270
273
|
});
|
|
271
274
|
}
|
|
272
275
|
|
|
273
|
-
private onObjectOperationStart(
|
|
276
|
+
private onObjectOperationStart(
|
|
277
|
+
event: InferTelemetryEvent<GenerateObjectStartEvent>,
|
|
278
|
+
): void {
|
|
274
279
|
const telemetry: TelemetryOptions = {
|
|
275
|
-
isEnabled: event.isEnabled,
|
|
276
280
|
recordInputs: event.recordInputs,
|
|
277
281
|
recordOutputs: event.recordOutputs,
|
|
278
282
|
functionId: event.functionId,
|
|
@@ -337,7 +341,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
/** @deprecated */
|
|
340
|
-
onObjectStepStart(event:
|
|
344
|
+
onObjectStepStart(event: GenerateObjectStepStartEvent): void {
|
|
341
345
|
const state = this.getCallState(event.callId);
|
|
342
346
|
if (!state?.rootSpan || !state.rootContext) return;
|
|
343
347
|
|
|
@@ -388,7 +392,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
388
392
|
}
|
|
389
393
|
|
|
390
394
|
/** @deprecated */
|
|
391
|
-
onObjectStepFinish(event:
|
|
395
|
+
onObjectStepFinish(event: GenerateObjectStepEndEvent): void {
|
|
392
396
|
const state = this.getCallState(event.callId);
|
|
393
397
|
if (!state?.stepSpan) return;
|
|
394
398
|
|
|
@@ -441,9 +445,10 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
441
445
|
state.stepContext = undefined;
|
|
442
446
|
}
|
|
443
447
|
|
|
444
|
-
private onEmbedOperationStart(
|
|
448
|
+
private onEmbedOperationStart(
|
|
449
|
+
event: InferTelemetryEvent<EmbedStartEvent>,
|
|
450
|
+
): void {
|
|
445
451
|
const telemetry: TelemetryOptions = {
|
|
446
|
-
isEnabled: event.isEnabled,
|
|
447
452
|
recordInputs: event.recordInputs,
|
|
448
453
|
recordOutputs: event.recordOutputs,
|
|
449
454
|
functionId: event.functionId,
|
|
@@ -607,12 +612,13 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
607
612
|
const { span } = toolSpanEntry;
|
|
608
613
|
const { telemetry } = state;
|
|
609
614
|
|
|
610
|
-
|
|
615
|
+
const { toolOutput } = event;
|
|
616
|
+
if (toolOutput.type === 'tool-result') {
|
|
611
617
|
try {
|
|
612
618
|
span.setAttributes(
|
|
613
619
|
selectAttributes(telemetry, {
|
|
614
620
|
'ai.toolCall.result': {
|
|
615
|
-
output: () => JSON.stringify(
|
|
621
|
+
output: () => JSON.stringify(toolOutput.output),
|
|
616
622
|
},
|
|
617
623
|
}),
|
|
618
624
|
);
|
|
@@ -620,14 +626,14 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
620
626
|
// JSON.stringify might fail for non-serializable results
|
|
621
627
|
}
|
|
622
628
|
} else {
|
|
623
|
-
recordSpanError(span,
|
|
629
|
+
recordSpanError(span, toolOutput.error);
|
|
624
630
|
}
|
|
625
631
|
|
|
626
632
|
span.end();
|
|
627
633
|
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
628
634
|
}
|
|
629
635
|
|
|
630
|
-
onStepFinish(event:
|
|
636
|
+
onStepFinish(event: GenerateTextStepEndEvent<ToolSet>): void {
|
|
631
637
|
const state = this.getCallState(event.callId);
|
|
632
638
|
if (!state?.stepSpan) return;
|
|
633
639
|
|
|
@@ -710,10 +716,10 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
710
716
|
|
|
711
717
|
onFinish(
|
|
712
718
|
event:
|
|
713
|
-
|
|
|
714
|
-
|
|
|
715
|
-
|
|
|
716
|
-
|
|
|
719
|
+
| GenerateTextEndEvent<ToolSet>
|
|
720
|
+
| GenerateObjectEndEvent<unknown>
|
|
721
|
+
| EmbedEndEvent
|
|
722
|
+
| RerankEndEvent,
|
|
717
723
|
): void {
|
|
718
724
|
const state = this.getCallState(event.callId);
|
|
719
725
|
if (!state?.rootSpan) return;
|
|
@@ -722,12 +728,12 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
722
728
|
state.operationId === 'ai.embed' ||
|
|
723
729
|
state.operationId === 'ai.embedMany'
|
|
724
730
|
) {
|
|
725
|
-
this.onEmbedOperationFinish(event as
|
|
731
|
+
this.onEmbedOperationFinish(event as EmbedEndEvent);
|
|
726
732
|
return;
|
|
727
733
|
}
|
|
728
734
|
|
|
729
735
|
if (state.operationId === 'ai.rerank') {
|
|
730
|
-
this.onRerankOperationFinish(event as
|
|
736
|
+
this.onRerankOperationFinish(event as RerankEndEvent);
|
|
731
737
|
return;
|
|
732
738
|
}
|
|
733
739
|
|
|
@@ -735,14 +741,14 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
735
741
|
state.operationId === 'ai.generateObject' ||
|
|
736
742
|
state.operationId === 'ai.streamObject'
|
|
737
743
|
) {
|
|
738
|
-
this.onObjectOperationFinish(event as
|
|
744
|
+
this.onObjectOperationFinish(event as GenerateObjectEndEvent<unknown>);
|
|
739
745
|
return;
|
|
740
746
|
}
|
|
741
747
|
|
|
742
|
-
this.onGenerateFinish(event as
|
|
748
|
+
this.onGenerateFinish(event as GenerateTextEndEvent<ToolSet>);
|
|
743
749
|
}
|
|
744
750
|
|
|
745
|
-
private onGenerateFinish(event:
|
|
751
|
+
private onGenerateFinish(event: GenerateTextEndEvent<ToolSet>): void {
|
|
746
752
|
const state = this.getCallState(event.callId);
|
|
747
753
|
if (!state?.rootSpan) return;
|
|
748
754
|
|
|
@@ -813,7 +819,9 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
813
819
|
this.cleanupCallState(event.callId);
|
|
814
820
|
}
|
|
815
821
|
|
|
816
|
-
private onObjectOperationFinish(
|
|
822
|
+
private onObjectOperationFinish(
|
|
823
|
+
event: GenerateObjectEndEvent<unknown>,
|
|
824
|
+
): void {
|
|
817
825
|
const state = this.getCallState(event.callId);
|
|
818
826
|
if (!state?.rootSpan) return;
|
|
819
827
|
|
|
@@ -842,7 +850,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
842
850
|
this.cleanupCallState(event.callId);
|
|
843
851
|
}
|
|
844
852
|
|
|
845
|
-
private onEmbedOperationFinish(event:
|
|
853
|
+
private onEmbedOperationFinish(event: EmbedEndEvent): void {
|
|
846
854
|
const state = this.getCallState(event.callId);
|
|
847
855
|
if (!state?.rootSpan) return;
|
|
848
856
|
|
|
@@ -871,7 +879,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
871
879
|
this.cleanupCallState(event.callId);
|
|
872
880
|
}
|
|
873
881
|
|
|
874
|
-
onEmbedStart(event:
|
|
882
|
+
onEmbedStart(event: EmbeddingModelCallStartEvent): void {
|
|
875
883
|
const state = this.getCallState(event.callId);
|
|
876
884
|
if (!state?.rootSpan || !state.rootContext) return;
|
|
877
885
|
|
|
@@ -901,7 +909,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
901
909
|
});
|
|
902
910
|
}
|
|
903
911
|
|
|
904
|
-
onEmbedFinish(event:
|
|
912
|
+
onEmbedFinish(event: EmbeddingModelCallEndEvent): void {
|
|
905
913
|
const state = this.getCallState(event.callId);
|
|
906
914
|
if (!state) return;
|
|
907
915
|
|
|
@@ -925,9 +933,10 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
925
933
|
state.embedSpans.delete(event.embedCallId);
|
|
926
934
|
}
|
|
927
935
|
|
|
928
|
-
private onRerankOperationStart(
|
|
936
|
+
private onRerankOperationStart(
|
|
937
|
+
event: InferTelemetryEvent<RerankStartEvent>,
|
|
938
|
+
): void {
|
|
929
939
|
const telemetry: TelemetryOptions = {
|
|
930
|
-
isEnabled: event.isEnabled,
|
|
931
940
|
recordInputs: event.recordInputs,
|
|
932
941
|
recordOutputs: event.recordOutputs,
|
|
933
942
|
functionId: event.functionId,
|
|
@@ -973,7 +982,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
973
982
|
});
|
|
974
983
|
}
|
|
975
984
|
|
|
976
|
-
private onRerankOperationFinish(event:
|
|
985
|
+
private onRerankOperationFinish(event: RerankEndEvent): void {
|
|
977
986
|
const state = this.getCallState(event.callId);
|
|
978
987
|
if (!state?.rootSpan) return;
|
|
979
988
|
|
|
@@ -981,7 +990,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
981
990
|
this.cleanupCallState(event.callId);
|
|
982
991
|
}
|
|
983
992
|
|
|
984
|
-
onRerankStart(event:
|
|
993
|
+
onRerankStart(event: RerankingModelCallStartEvent): void {
|
|
985
994
|
const state = this.getCallState(event.callId);
|
|
986
995
|
if (!state?.rootSpan || !state.rootContext) return;
|
|
987
996
|
|
|
@@ -1008,7 +1017,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
1008
1017
|
state.rerankSpan = { span: rerankSpan, context: rerankContext };
|
|
1009
1018
|
}
|
|
1010
1019
|
|
|
1011
|
-
onRerankFinish(event:
|
|
1020
|
+
onRerankFinish(event: RerankingModelCallEndEvent): void {
|
|
1012
1021
|
const state = this.getCallState(event.callId);
|
|
1013
1022
|
if (!state?.rerankSpan) return;
|
|
1014
1023
|
|
|
@@ -1028,7 +1037,7 @@ export class OpenTelemetryIntegration implements TelemetryIntegration {
|
|
|
1028
1037
|
state.rerankSpan = undefined;
|
|
1029
1038
|
}
|
|
1030
1039
|
|
|
1031
|
-
onChunk(event:
|
|
1040
|
+
onChunk(event: StreamTextChunkEvent<ToolSet>): void {
|
|
1032
1041
|
const chunk = event.chunk as {
|
|
1033
1042
|
type: string;
|
|
1034
1043
|
callId?: unknown;
|