@ai-sdk/otel 1.0.147 → 1.0.149
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 +17 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/open-telemetry.ts +43 -2
- package/src/supplemental-attributes.ts +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/otel
|
|
2
2
|
|
|
3
|
+
## 1.0.149
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e6a568d: Add an `agentSpanName` option to `OpenTelemetry` to name root agent spans using `functionId` or a custom callback. Preserve model-based span names by default.
|
|
8
|
+
- Updated dependencies [1727442]
|
|
9
|
+
- Updated dependencies [0a5d0e7]
|
|
10
|
+
- Updated dependencies [10026d1]
|
|
11
|
+
- ai@7.0.149
|
|
12
|
+
- @ai-sdk/provider@4.0.32
|
|
13
|
+
|
|
14
|
+
## 1.0.148
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- ai@7.0.148
|
|
19
|
+
|
|
3
20
|
## 1.0.147
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,20 @@ type OpenTelemetryOptions = {
|
|
|
14
14
|
* The tracer to use for the telemetry data.
|
|
15
15
|
*/
|
|
16
16
|
tracer?: Tracer;
|
|
17
|
+
/**
|
|
18
|
+
* Controls root agent span names for text and object generation.
|
|
19
|
+
*
|
|
20
|
+
* With `modelId` (the default), names are `invoke_agent {modelId}`.
|
|
21
|
+
* With `functionId`, names are `invoke_agent {functionId}`, falling back to
|
|
22
|
+
* the model ID when no function ID is provided.
|
|
23
|
+
*
|
|
24
|
+
* A callback returns the complete span name. If it returns `undefined` or
|
|
25
|
+
* throws, the default model-based name is used.
|
|
26
|
+
*/
|
|
27
|
+
agentSpanName?: 'modelId' | 'functionId' | ((options: {
|
|
28
|
+
modelId: string;
|
|
29
|
+
functionId: string | undefined;
|
|
30
|
+
}) => string | undefined);
|
|
17
31
|
/**
|
|
18
32
|
* Adds custom attributes to spans when they are created. These attributes are
|
|
19
33
|
* not AI SDK-owned semantics and are intended for observability integrations.
|
|
@@ -66,11 +80,13 @@ interface OtelStepStartEvent$1 extends GenerateTextStepStartEvent<ToolSet> {
|
|
|
66
80
|
export declare class OpenTelemetry implements Telemetry {
|
|
67
81
|
private readonly callStates;
|
|
68
82
|
private readonly tracer;
|
|
83
|
+
private readonly agentSpanName;
|
|
69
84
|
private readonly supplementalAttributes;
|
|
70
85
|
private readonly enrichSpan;
|
|
71
86
|
constructor(options?: OpenTelemetryOptions);
|
|
72
87
|
private getCallState;
|
|
73
88
|
private cleanupCallState;
|
|
89
|
+
private getAgentSpanName;
|
|
74
90
|
private getSpanAttributes;
|
|
75
91
|
executeTool<T>({ callId, toolCallId, execute }: {
|
|
76
92
|
callId: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/supplemental-attributes.ts","../src/open-telemetry.ts","../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.d.cts","../../provider-utils/dist/index.d.ts","../src/legacy-open-telemetry.ts"],"x_google_ignoreList":[2],"mappings":";;;;KAwBY;KASA,cAAc;EACxB,UAAU;EACV;EACA;EACA,gBAAgB;MACZ;KAEM;;;;EAIV,SAAS
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["OtelStepStartEvent","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent","AISDKContext","StreamTranscriptionStartEvent","StreamTranscriptionEndEvent","DecideStartEvent","DecideEndEvent","DecisionModelCallStartEvent","DecisionModelCallEndEvent"],"sources":["../src/supplemental-attributes.ts","../src/open-telemetry.ts","../../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/schemas.d.cts","../../provider-utils/dist/index.d.ts","../src/legacy-open-telemetry.ts"],"x_google_ignoreList":[2],"mappings":";;;;KAwBY;KASA,cAAc;EACxB,UAAU;EACV;EACA;EACA,gBAAgB;MACZ;KAEM;;;;EAIV,SAAS;;;;;;;;;;;EAYT,6CAGM;IACA;IACA;;;;;;EAON,aAAa;;;;EAKb;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;EAGA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;UCrCQA,6BAA2B,2BAA2B;WACrD;;qBA2CE,yBAAyB;mBACnB;mBAEA;mBACA;mBACA;mBACA;EAEL,YAAA,UAAS;UAOb;UAIA;UAIA;UA+BA;EAgCR,YAAY,KACV,QACA,YACA;IAEA;IACA;IACA,eAAe,YAAY;MACzB,YAAY;;;;;EAchB,yBAAyB,KACvB,QACA;IAEA;IACA,eAAe,YAAY;MACzB,YAAY;EAWhB,QACE,OACI,oBAAoB,0BACpB,oBAAoB,4BACpB,oBAAoB,mBACpB,oBAAoB,oBACpB,oBAAoB,4BACpB,oBAAoB;EA4C1B,wCACE,OAAO,oBAAoBC;UAKrB;UA0FA;UA2GA;;EAiHR,kBAAkB,OAAO;;EAuEzB,gBAAgB,OAAO;UAqDf;EA6ER,YAAY,OAAOD;EAwCnB,yBAAyB,OAAO;EAyEhC,uBAAuB,OAAO,0BAA0B;EAqKxD,qBAAqB,OAAO,wBAAwB;EAyCpD,mBAAmB,OAAO,sBAAsB;EAqChD,UAAU,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B;;EAgH1C,aAAa,OAAO,yBAAyB;EAI7C,MACE,OACI,qBAAqB,WACrB,kCACA,gBACA,iBACA,yBACA;EAuCN,sCACE,OAAO,oBAAoBC;UAKrB;UA+CA;UA6EA;UAmCA;EA6BR,aAAa,OAAO;EA8BpB,WAAW,OAAO;UAwBV;UAkDA;EAQR,cAAc,OAAO;EA2BrB,YAAY,OAAO;UAoBX;UA8CA;EAgBR,2BACE,OAAO,oBAAoBC;EAK7B,yBAAyB,OAAOC;EAIhC,sCACE,OAAOC;EAKT,oCAAoC,OAAOC;;EAK3C,6BACE,OAAO,oBAAoBH;;EAM7B,2BAA2B,OAAOC;;EAKlC,wCACE,OAAO,oBAAoBC;;EA8B7B,sCACE,OAAO,oBAAoBC;EAqB7B,QAAQ,OAAO,uBAAuB;EAkCtC,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -683,6 +683,7 @@ var OpenTelemetry = class {
|
|
|
683
683
|
constructor(options = {}) {
|
|
684
684
|
this.callStates = /* @__PURE__ */ new Map();
|
|
685
685
|
this.tracer = options.tracer ?? trace.getTracer("gen_ai");
|
|
686
|
+
this.agentSpanName = options.agentSpanName;
|
|
686
687
|
this.supplementalAttributes = normalizeSupplementalAttributes(options);
|
|
687
688
|
this.enrichSpan = options.enrichSpan;
|
|
688
689
|
}
|
|
@@ -692,6 +693,20 @@ var OpenTelemetry = class {
|
|
|
692
693
|
cleanupCallState(callId) {
|
|
693
694
|
this.callStates.delete(callId);
|
|
694
695
|
}
|
|
696
|
+
getAgentSpanName({ operationName, modelId, functionId }) {
|
|
697
|
+
const defaultName = `${operationName} ${modelId}`;
|
|
698
|
+
if (operationName !== "invoke_agent") return defaultName;
|
|
699
|
+
if (this.agentSpanName === "functionId") return `invoke_agent ${functionId ?? modelId}`;
|
|
700
|
+
if (typeof this.agentSpanName === "function") try {
|
|
701
|
+
return this.agentSpanName({
|
|
702
|
+
modelId,
|
|
703
|
+
functionId
|
|
704
|
+
}) ?? defaultName;
|
|
705
|
+
} catch {
|
|
706
|
+
return defaultName;
|
|
707
|
+
}
|
|
708
|
+
return defaultName;
|
|
709
|
+
}
|
|
695
710
|
getSpanAttributes({ attributes, spanType, operationId, callId, runtimeContext }) {
|
|
696
711
|
let customAttributes;
|
|
697
712
|
try {
|
|
@@ -855,7 +870,11 @@ var OpenTelemetry = class {
|
|
|
855
870
|
})) },
|
|
856
871
|
...baseSupplementalAttributes
|
|
857
872
|
});
|
|
858
|
-
const spanName =
|
|
873
|
+
const spanName = this.getAgentSpanName({
|
|
874
|
+
operationName,
|
|
875
|
+
modelId: event.modelId,
|
|
876
|
+
functionId: telemetry.functionId
|
|
877
|
+
});
|
|
859
878
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
860
879
|
attributes: this.getSpanAttributes({
|
|
861
880
|
attributes,
|
|
@@ -932,7 +951,11 @@ var OpenTelemetry = class {
|
|
|
932
951
|
"ai.settings.output": event.output
|
|
933
952
|
} })
|
|
934
953
|
});
|
|
935
|
-
const spanName =
|
|
954
|
+
const spanName = this.getAgentSpanName({
|
|
955
|
+
operationName,
|
|
956
|
+
modelId: event.modelId,
|
|
957
|
+
functionId: telemetry.functionId
|
|
958
|
+
});
|
|
936
959
|
const rootSpan = this.tracer.startSpan(spanName, {
|
|
937
960
|
attributes: this.getSpanAttributes({
|
|
938
961
|
attributes,
|