@ai-sdk/otel 1.0.0-beta.33 → 1.0.0-beta.35
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 +20 -0
- package/dist/index.js +54 -73
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -97
- package/dist/index.mjs +0 -1911
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/otel
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ff5eba1]
|
|
8
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
9
|
+
- ai@7.0.0-beta.89
|
|
10
|
+
|
|
11
|
+
## 1.0.0-beta.34
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [ef992f8]
|
|
20
|
+
- ai@7.0.0-beta.88
|
|
21
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
22
|
+
|
|
3
23
|
## 1.0.0-beta.33
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
GenAIOpenTelemetryIntegration: () => GenAIOpenTelemetryIntegration,
|
|
24
|
-
OpenTelemetryIntegration: () => OpenTelemetryIntegration
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
1
|
// src/gen-ai-open-telemetry-integration.ts
|
|
29
|
-
|
|
2
|
+
import {
|
|
3
|
+
context,
|
|
4
|
+
SpanKind,
|
|
5
|
+
SpanStatusCode,
|
|
6
|
+
trace
|
|
7
|
+
} from "@opentelemetry/api";
|
|
30
8
|
|
|
31
9
|
// src/gen-ai-format-messages.ts
|
|
32
|
-
|
|
10
|
+
import { convertDataContentToBase64String } from "ai";
|
|
33
11
|
function mapProviderName(provider) {
|
|
34
12
|
const lower = provider.toLowerCase();
|
|
35
13
|
const wellKnownPrefixes = [
|
|
@@ -117,7 +95,7 @@ function convertMessagePartToSemConv(part) {
|
|
|
117
95
|
const data = part.data;
|
|
118
96
|
let content;
|
|
119
97
|
if (data instanceof Uint8Array) {
|
|
120
|
-
content =
|
|
98
|
+
content = convertDataContentToBase64String(data);
|
|
121
99
|
} else if (typeof data === "string") {
|
|
122
100
|
if (data.startsWith("http://") || data.startsWith("https://")) {
|
|
123
101
|
return {
|
|
@@ -242,7 +220,7 @@ function convertModelMessageToSemConv(msg) {
|
|
|
242
220
|
type: "blob",
|
|
243
221
|
modality: "image",
|
|
244
222
|
mime_type: (_d = part.mediaType) != null ? _d : null,
|
|
245
|
-
content:
|
|
223
|
+
content: convertDataContentToBase64String(data)
|
|
246
224
|
};
|
|
247
225
|
}
|
|
248
226
|
case "file": {
|
|
@@ -275,7 +253,7 @@ function convertModelMessageToSemConv(msg) {
|
|
|
275
253
|
type: "blob",
|
|
276
254
|
modality: getModality(part.mediaType),
|
|
277
255
|
mime_type: (_h = part.mediaType) != null ? _h : null,
|
|
278
|
-
content:
|
|
256
|
+
content: convertDataContentToBase64String(data)
|
|
279
257
|
};
|
|
280
258
|
}
|
|
281
259
|
default:
|
|
@@ -441,11 +419,11 @@ function recordSpanError(span, error) {
|
|
|
441
419
|
stack: error.stack
|
|
442
420
|
});
|
|
443
421
|
span.setStatus({
|
|
444
|
-
code:
|
|
422
|
+
code: SpanStatusCode.ERROR,
|
|
445
423
|
message: error.message
|
|
446
424
|
});
|
|
447
425
|
} else {
|
|
448
|
-
span.setStatus({ code:
|
|
426
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
449
427
|
}
|
|
450
428
|
}
|
|
451
429
|
function shouldRecord(telemetry) {
|
|
@@ -478,7 +456,7 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
478
456
|
constructor(options = {}) {
|
|
479
457
|
this.callStates = /* @__PURE__ */ new Map();
|
|
480
458
|
var _a;
|
|
481
|
-
this.tracer = (_a = options.tracer) != null ? _a :
|
|
459
|
+
this.tracer = (_a = options.tracer) != null ? _a : trace.getTracer("gen_ai");
|
|
482
460
|
}
|
|
483
461
|
getCallState(callId) {
|
|
484
462
|
return this.callStates.get(callId);
|
|
@@ -496,7 +474,7 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
496
474
|
if (toolSpanEntry == null) {
|
|
497
475
|
return execute();
|
|
498
476
|
}
|
|
499
|
-
return
|
|
477
|
+
return context.with(toolSpanEntry.context, execute);
|
|
500
478
|
}
|
|
501
479
|
onStart(event) {
|
|
502
480
|
if (event.isEnabled !== true) return;
|
|
@@ -564,9 +542,9 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
564
542
|
const spanName = `${operationName} ${event.modelId}`;
|
|
565
543
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
566
544
|
attributes,
|
|
567
|
-
kind:
|
|
545
|
+
kind: SpanKind.INTERNAL
|
|
568
546
|
});
|
|
569
|
-
const rootContext =
|
|
547
|
+
const rootContext = trace.setSpan(context.active(), rootSpan);
|
|
570
548
|
this.callStates.set(event.callId, {
|
|
571
549
|
operationId: event.operationId,
|
|
572
550
|
telemetry,
|
|
@@ -631,9 +609,9 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
631
609
|
const spanName = `${operationName} ${event.modelId}`;
|
|
632
610
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
633
611
|
attributes,
|
|
634
|
-
kind:
|
|
612
|
+
kind: SpanKind.INTERNAL
|
|
635
613
|
});
|
|
636
|
-
const rootContext =
|
|
614
|
+
const rootContext = trace.setSpan(context.active(), rootSpan);
|
|
637
615
|
this.callStates.set(event.callId, {
|
|
638
616
|
operationId: event.operationId,
|
|
639
617
|
telemetry,
|
|
@@ -674,10 +652,10 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
674
652
|
const spanName = `chat ${event.modelId}`;
|
|
675
653
|
state.stepSpan = this.tracer.startSpan(
|
|
676
654
|
spanName,
|
|
677
|
-
{ attributes, kind:
|
|
655
|
+
{ attributes, kind: SpanKind.CLIENT },
|
|
678
656
|
state.rootContext
|
|
679
657
|
);
|
|
680
|
-
state.stepContext =
|
|
658
|
+
state.stepContext = trace.setSpan(state.rootContext, state.stepSpan);
|
|
681
659
|
}
|
|
682
660
|
/** @deprecated */
|
|
683
661
|
onObjectStepFinish(event) {
|
|
@@ -732,9 +710,9 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
732
710
|
const spanName = `embeddings ${event.modelId}`;
|
|
733
711
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
734
712
|
attributes,
|
|
735
|
-
kind:
|
|
713
|
+
kind: SpanKind.CLIENT
|
|
736
714
|
});
|
|
737
|
-
const rootContext =
|
|
715
|
+
const rootContext = trace.setSpan(context.active(), rootSpan);
|
|
738
716
|
this.callStates.set(event.callId, {
|
|
739
717
|
operationId: event.operationId,
|
|
740
718
|
telemetry,
|
|
@@ -777,10 +755,10 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
777
755
|
const spanName = `chat ${event.modelId}`;
|
|
778
756
|
state.stepSpan = this.tracer.startSpan(
|
|
779
757
|
spanName,
|
|
780
|
-
{ attributes, kind:
|
|
758
|
+
{ attributes, kind: SpanKind.CLIENT },
|
|
781
759
|
state.rootContext
|
|
782
760
|
);
|
|
783
|
-
state.stepContext =
|
|
761
|
+
state.stepContext = trace.setSpan(state.rootContext, state.stepSpan);
|
|
784
762
|
}
|
|
785
763
|
onToolCallStart(event) {
|
|
786
764
|
const state = this.getCallState(event.callId);
|
|
@@ -799,10 +777,10 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
799
777
|
const spanName = `execute_tool ${toolCall.toolName}`;
|
|
800
778
|
const toolSpan = this.tracer.startSpan(
|
|
801
779
|
spanName,
|
|
802
|
-
{ attributes, kind:
|
|
780
|
+
{ attributes, kind: SpanKind.INTERNAL },
|
|
803
781
|
state.stepContext
|
|
804
782
|
);
|
|
805
|
-
const toolContext =
|
|
783
|
+
const toolContext = trace.setSpan(state.stepContext, toolSpan);
|
|
806
784
|
state.toolSpans.set(toolCall.toolCallId, {
|
|
807
785
|
span: toolSpan,
|
|
808
786
|
context: toolContext
|
|
@@ -962,10 +940,10 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
962
940
|
const spanName = `embeddings ${state.modelId}`;
|
|
963
941
|
const embedSpan = this.tracer.startSpan(
|
|
964
942
|
spanName,
|
|
965
|
-
{ attributes, kind:
|
|
943
|
+
{ attributes, kind: SpanKind.CLIENT },
|
|
966
944
|
state.rootContext
|
|
967
945
|
);
|
|
968
|
-
const embedContext =
|
|
946
|
+
const embedContext = trace.setSpan(state.rootContext, embedSpan);
|
|
969
947
|
state.embedSpans.set(event.embedCallId, {
|
|
970
948
|
span: embedSpan,
|
|
971
949
|
context: embedContext
|
|
@@ -1006,9 +984,9 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
1006
984
|
const spanName = `rerank ${event.modelId}`;
|
|
1007
985
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
1008
986
|
attributes,
|
|
1009
|
-
kind:
|
|
987
|
+
kind: SpanKind.CLIENT
|
|
1010
988
|
});
|
|
1011
|
-
const rootContext =
|
|
989
|
+
const rootContext = trace.setSpan(context.active(), rootSpan);
|
|
1012
990
|
this.callStates.set(event.callId, {
|
|
1013
991
|
operationId: event.operationId,
|
|
1014
992
|
telemetry,
|
|
@@ -1043,10 +1021,10 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
1043
1021
|
const spanName = `rerank ${state.modelId}`;
|
|
1044
1022
|
const rerankSpan = this.tracer.startSpan(
|
|
1045
1023
|
spanName,
|
|
1046
|
-
{ attributes, kind:
|
|
1024
|
+
{ attributes, kind: SpanKind.CLIENT },
|
|
1047
1025
|
state.rootContext
|
|
1048
1026
|
);
|
|
1049
|
-
const rerankContext =
|
|
1027
|
+
const rerankContext = trace.setSpan(state.rootContext, rerankSpan);
|
|
1050
1028
|
state.rerankSpan = { span: rerankSpan, context: rerankContext };
|
|
1051
1029
|
}
|
|
1052
1030
|
onRerankFinish(event) {
|
|
@@ -1086,7 +1064,11 @@ var GenAIOpenTelemetryIntegration = class {
|
|
|
1086
1064
|
};
|
|
1087
1065
|
|
|
1088
1066
|
// src/open-telemetry-integration.ts
|
|
1089
|
-
|
|
1067
|
+
import {
|
|
1068
|
+
context as context2,
|
|
1069
|
+
SpanStatusCode as SpanStatusCode2,
|
|
1070
|
+
trace as trace2
|
|
1071
|
+
} from "@opentelemetry/api";
|
|
1090
1072
|
|
|
1091
1073
|
// src/assemble-operation-name.ts
|
|
1092
1074
|
function assembleOperationName({
|
|
@@ -1140,7 +1122,7 @@ function getBaseTelemetryAttributes({
|
|
|
1140
1122
|
}
|
|
1141
1123
|
|
|
1142
1124
|
// src/stringify-for-telemetry.ts
|
|
1143
|
-
|
|
1125
|
+
import { convertDataContentToBase64String as convertDataContentToBase64String2 } from "ai";
|
|
1144
1126
|
function stringifyForTelemetry(prompt) {
|
|
1145
1127
|
return JSON.stringify(
|
|
1146
1128
|
prompt.map((message) => ({
|
|
@@ -1148,7 +1130,7 @@ function stringifyForTelemetry(prompt) {
|
|
|
1148
1130
|
content: typeof message.content === "string" ? message.content : message.content.map(
|
|
1149
1131
|
(part) => part.type === "file" ? {
|
|
1150
1132
|
...part,
|
|
1151
|
-
data: part.data instanceof Uint8Array ? (
|
|
1133
|
+
data: part.data instanceof Uint8Array ? convertDataContentToBase64String2(part.data) : part.data
|
|
1152
1134
|
} : part
|
|
1153
1135
|
)
|
|
1154
1136
|
}))
|
|
@@ -1164,11 +1146,11 @@ function recordSpanError2(span, error) {
|
|
|
1164
1146
|
stack: error.stack
|
|
1165
1147
|
});
|
|
1166
1148
|
span.setStatus({
|
|
1167
|
-
code:
|
|
1149
|
+
code: SpanStatusCode2.ERROR,
|
|
1168
1150
|
message: error.message
|
|
1169
1151
|
});
|
|
1170
1152
|
} else {
|
|
1171
|
-
span.setStatus({ code:
|
|
1153
|
+
span.setStatus({ code: SpanStatusCode2.ERROR });
|
|
1172
1154
|
}
|
|
1173
1155
|
}
|
|
1174
1156
|
function shouldRecord2(telemetry) {
|
|
@@ -1201,7 +1183,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1201
1183
|
constructor(options = {}) {
|
|
1202
1184
|
this.callStates = /* @__PURE__ */ new Map();
|
|
1203
1185
|
var _a;
|
|
1204
|
-
this.tracer = (_a = options.tracer) != null ? _a :
|
|
1186
|
+
this.tracer = (_a = options.tracer) != null ? _a : trace2.getTracer("ai");
|
|
1205
1187
|
}
|
|
1206
1188
|
getCallState(callId) {
|
|
1207
1189
|
return this.callStates.get(callId);
|
|
@@ -1219,7 +1201,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1219
1201
|
if (toolSpanEntry == null) {
|
|
1220
1202
|
return execute();
|
|
1221
1203
|
}
|
|
1222
|
-
return
|
|
1204
|
+
return context2.with(toolSpanEntry.context, execute);
|
|
1223
1205
|
}
|
|
1224
1206
|
onStart(event) {
|
|
1225
1207
|
if (event.isEnabled !== true) return;
|
|
@@ -1279,7 +1261,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1279
1261
|
}
|
|
1280
1262
|
});
|
|
1281
1263
|
const rootSpan = this.tracer.startSpan(event.operationId, { attributes });
|
|
1282
|
-
const rootContext =
|
|
1264
|
+
const rootContext = trace2.setSpan(context2.active(), rootSpan);
|
|
1283
1265
|
this.callStates.set(event.callId, {
|
|
1284
1266
|
operationId: event.operationId,
|
|
1285
1267
|
telemetry,
|
|
@@ -1337,7 +1319,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1337
1319
|
"ai.settings.output": event.output
|
|
1338
1320
|
});
|
|
1339
1321
|
const rootSpan = this.tracer.startSpan(event.operationId, { attributes });
|
|
1340
|
-
const rootContext =
|
|
1322
|
+
const rootContext = trace2.setSpan(context2.active(), rootSpan);
|
|
1341
1323
|
this.callStates.set(event.callId, {
|
|
1342
1324
|
operationId: event.operationId,
|
|
1343
1325
|
telemetry,
|
|
@@ -1382,7 +1364,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1382
1364
|
{ attributes },
|
|
1383
1365
|
state.rootContext
|
|
1384
1366
|
);
|
|
1385
|
-
state.stepContext =
|
|
1367
|
+
state.stepContext = trace2.setSpan(state.rootContext, state.stepSpan);
|
|
1386
1368
|
}
|
|
1387
1369
|
/** @deprecated */
|
|
1388
1370
|
onObjectStepFinish(event) {
|
|
@@ -1465,7 +1447,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1465
1447
|
}
|
|
1466
1448
|
});
|
|
1467
1449
|
const rootSpan = this.tracer.startSpan(event.operationId, { attributes });
|
|
1468
|
-
const rootContext =
|
|
1450
|
+
const rootContext = trace2.setSpan(context2.active(), rootSpan);
|
|
1469
1451
|
this.callStates.set(event.callId, {
|
|
1470
1452
|
operationId: event.operationId,
|
|
1471
1453
|
telemetry,
|
|
@@ -1521,7 +1503,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1521
1503
|
{ attributes },
|
|
1522
1504
|
state.rootContext
|
|
1523
1505
|
);
|
|
1524
|
-
state.stepContext =
|
|
1506
|
+
state.stepContext = trace2.setSpan(state.rootContext, state.stepSpan);
|
|
1525
1507
|
}
|
|
1526
1508
|
onToolCallStart(event) {
|
|
1527
1509
|
const state = this.getCallState(event.callId);
|
|
@@ -1544,7 +1526,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1544
1526
|
{ attributes },
|
|
1545
1527
|
state.stepContext
|
|
1546
1528
|
);
|
|
1547
|
-
const toolContext =
|
|
1529
|
+
const toolContext = trace2.setSpan(state.stepContext, toolSpan);
|
|
1548
1530
|
state.toolSpans.set(toolCall.toolCallId, {
|
|
1549
1531
|
span: toolSpan,
|
|
1550
1532
|
context: toolContext
|
|
@@ -1764,7 +1746,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1764
1746
|
{ attributes },
|
|
1765
1747
|
state.rootContext
|
|
1766
1748
|
);
|
|
1767
|
-
const embedContext =
|
|
1749
|
+
const embedContext = trace2.setSpan(state.rootContext, embedSpan);
|
|
1768
1750
|
state.embedSpans.set(event.embedCallId, {
|
|
1769
1751
|
span: embedSpan,
|
|
1770
1752
|
context: embedContext
|
|
@@ -1816,7 +1798,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1816
1798
|
}
|
|
1817
1799
|
});
|
|
1818
1800
|
const rootSpan = this.tracer.startSpan(event.operationId, { attributes });
|
|
1819
|
-
const rootContext =
|
|
1801
|
+
const rootContext = trace2.setSpan(context2.active(), rootSpan);
|
|
1820
1802
|
this.callStates.set(event.callId, {
|
|
1821
1803
|
operationId: event.operationId,
|
|
1822
1804
|
telemetry,
|
|
@@ -1856,7 +1838,7 @@ var OpenTelemetryIntegration = class {
|
|
|
1856
1838
|
{ attributes },
|
|
1857
1839
|
state.rootContext
|
|
1858
1840
|
);
|
|
1859
|
-
const rerankContext =
|
|
1841
|
+
const rerankContext = trace2.setSpan(state.rootContext, rerankSpan);
|
|
1860
1842
|
state.rerankSpan = { span: rerankSpan, context: rerankContext };
|
|
1861
1843
|
}
|
|
1862
1844
|
onRerankFinish(event) {
|
|
@@ -1922,9 +1904,8 @@ var OpenTelemetryIntegration = class {
|
|
|
1922
1904
|
this.cleanupCallState(event.callId);
|
|
1923
1905
|
}
|
|
1924
1906
|
};
|
|
1925
|
-
|
|
1926
|
-
0 && (module.exports = {
|
|
1907
|
+
export {
|
|
1927
1908
|
GenAIOpenTelemetryIntegration,
|
|
1928
1909
|
OpenTelemetryIntegration
|
|
1929
|
-
}
|
|
1910
|
+
};
|
|
1930
1911
|
//# sourceMappingURL=index.js.map
|