@telemetry-dev/bedrock 0.1.7 → 0.1.9

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-DzagsZVD.mjs";
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-DzagsZVD.mjs";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemetry-dev/bedrock",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "AWS Bedrock instrumentation for telemetry.dev: Converse, InvokeModel, and Bedrock Agents spans for AWS SDK v3 clients.",
5
5
  "keywords": [
6
6
  "aws",
@@ -49,7 +49,7 @@
49
49
  "@smithy/eventstream-codec": "^4.2.5",
50
50
  "@smithy/protocol-http": "^5.3.10",
51
51
  "@smithy/types": "^4.12.0",
52
- "@telemetry-dev/sdk": "^0.1.6",
52
+ "@telemetry-dev/sdk": "^0.1.7",
53
53
  "@types/node": "^25.5.0",
54
54
  "@typescript/native-preview": "7.0.0-dev.20260328.1",
55
55
  "typescript": "^6.0.2",
@@ -59,7 +59,7 @@
59
59
  "peerDependencies": {
60
60
  "@aws-sdk/client-bedrock-agent-runtime": ">=3.600.0 <4",
61
61
  "@aws-sdk/client-bedrock-runtime": ">=3.600.0 <4",
62
- "@telemetry-dev/sdk": "^0.1.6"
62
+ "@telemetry-dev/sdk": "^0.1.7"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "@aws-sdk/client-bedrock-agent-runtime": {
package/src/internal.ts CHANGED
@@ -145,9 +145,26 @@ 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
+
154
+ const inputTokens =
155
+ usage.inputTokens + (usage.cacheReadInputTokens ?? 0) + (usage.cacheCreationInputTokens ?? 0);
156
+
157
+ const totalTokens =
158
+ usage.totalTokens !== undefined && usage.outputTokens !== undefined
159
+ ? inputTokens + usage.outputTokens
160
+ : usage.totalTokens;
161
+
162
+ return { ...fields, usage: { ...usage, inputTokens, totalTokens } };
163
+ }
164
+
148
165
  export function endSpan(span: SpanHandle, fields?: SpanFields): void {
149
166
  try {
150
- span.end(fields);
167
+ span.end(withCacheInclusiveInput(fields));
151
168
  } catch {
152
169
  // Instrumentation must never throw into caller code.
153
170
  }