@telemetry-dev/bedrock 0.1.7 → 0.1.8
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/dist/agents.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as createInstrumentedSend, t as AGENT_HANDLERS } from "./internal-handlers-
|
|
1
|
+
import { r as createInstrumentedSend, t as AGENT_HANDLERS } from "./internal-handlers-Byxp14OZ.mjs";
|
|
2
2
|
import { BedrockAgentRuntimeClient } from "@aws-sdk/client-bedrock-agent-runtime";
|
|
3
3
|
//#region src/agents.ts
|
|
4
4
|
const WRAPPED = /* @__PURE__ */ new WeakSet();
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as RUNTIME_HANDLERS, r as createInstrumentedSend } from "./internal-handlers-
|
|
1
|
+
import { n as RUNTIME_HANDLERS, r as createInstrumentedSend } from "./internal-handlers-Byxp14OZ.mjs";
|
|
2
2
|
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
const WRAPPED = /* @__PURE__ */ new WeakSet();
|
|
@@ -89,9 +89,23 @@ function safe(fn) {
|
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
function withCacheInclusiveInput(fields) {
|
|
93
|
+
const usage = fields?.usage;
|
|
94
|
+
if (usage?.inputTokens === void 0) return fields;
|
|
95
|
+
const inputTokens = usage.inputTokens + (usage.cacheReadInputTokens ?? 0) + (usage.cacheCreationInputTokens ?? 0);
|
|
96
|
+
const totalTokens = usage.totalTokens !== void 0 && usage.outputTokens !== void 0 ? inputTokens + usage.outputTokens : usage.totalTokens;
|
|
97
|
+
return {
|
|
98
|
+
...fields,
|
|
99
|
+
usage: {
|
|
100
|
+
...usage,
|
|
101
|
+
inputTokens,
|
|
102
|
+
totalTokens
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
92
106
|
function endSpan(span, fields) {
|
|
93
107
|
try {
|
|
94
|
-
span.end(fields);
|
|
108
|
+
span.end(withCacheInclusiveInput(fields));
|
|
95
109
|
} catch {}
|
|
96
110
|
}
|
|
97
111
|
function updateSpan(span, fields) {
|
package/package.json
CHANGED
package/src/internal.ts
CHANGED
|
@@ -145,9 +145,24 @@ export function safe<T>(fn: () => T): T | undefined {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// Bedrock reports input tokens without cache reads and writes; span input tokens include them.
|
|
149
|
+
function withCacheInclusiveInput(fields: SpanFields | undefined): SpanFields | undefined {
|
|
150
|
+
const usage = fields?.usage;
|
|
151
|
+
|
|
152
|
+
if (usage?.inputTokens === undefined) return fields;
|
|
153
|
+
const inputTokens =
|
|
154
|
+
usage.inputTokens + (usage.cacheReadInputTokens ?? 0) + (usage.cacheCreationInputTokens ?? 0);
|
|
155
|
+
const totalTokens =
|
|
156
|
+
usage.totalTokens !== undefined && usage.outputTokens !== undefined
|
|
157
|
+
? inputTokens + usage.outputTokens
|
|
158
|
+
: usage.totalTokens;
|
|
159
|
+
|
|
160
|
+
return { ...fields, usage: { ...usage, inputTokens, totalTokens } };
|
|
161
|
+
}
|
|
162
|
+
|
|
148
163
|
export function endSpan(span: SpanHandle, fields?: SpanFields): void {
|
|
149
164
|
try {
|
|
150
|
-
span.end(fields);
|
|
165
|
+
span.end(withCacheInclusiveInput(fields));
|
|
151
166
|
} catch {
|
|
152
167
|
// Instrumentation must never throw into caller code.
|
|
153
168
|
}
|