opentel-mcp 0.3.0 → 0.5.0

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 CHANGED
@@ -1,5 +1,77 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Added — Cost & Token Attribution
6
+
7
+ - Span attributes, added on any tool call whose result carries recognizable
8
+ usage data: `mcp.tool.tokens.input`, `mcp.tool.tokens.output`,
9
+ `mcp.tool.tokens.total`, `mcp.tool.model`, `gen_ai.response.model`
10
+ (co-emitted alongside `mcp.tool.model` for GenAI-dashboard compatibility —
11
+ see README's "Cost & Token Attribution" section and the
12
+ `ATTR_GEN_AI_RESPONSE_MODEL` docblock in `src/attributes.js` for why this
13
+ is a pragmatic compatibility choice, not a spec-pure emission),
14
+ `mcp.tool.cost.usd`, and `mcp.tool.cost.currency`. All added by
15
+ `applyCostAttribution()` in `src/instrument.js`, wrapped in its own
16
+ try/catch — cost tracking can never break a span.
17
+ - Two new metric instruments, via the same `@opentelemetry/api`-only
18
+ pattern as the four existing `mcp.tool.*` metrics: `mcp.tool.tokens.total`
19
+ (counter, unit `tokens`) and `mcp.tool.cost.total` (counter, unit `USD`),
20
+ both attributed by `gen_ai.tool.name` + `mcp.tool.model` (model only
21
+ added when detected, same optional-attribute pattern
22
+ `mcp.failure.category` already uses).
23
+ - Per-session and per-tool budget guardrails (`costTracking.budget`,
24
+ `src/cost/budget.js`): in-memory cumulative-cost tracking, flags
25
+ `mcp.tool.cost.budget_exceeded` / `mcp.tool.cost.budget_scope`
26
+ (`"session"` | `"tool"`, session wins if both trip on the same call) on
27
+ the span once a configured `perSessionUsd`/`perToolUsd` limit is
28
+ crossed. **Observability only — never blocks or throws.** Calls with no
29
+ MCP session id (e.g. stdio transport) are skipped for session tracking
30
+ rather than lumped under a fallback key.
31
+ - `DEFAULT_PRICING` (`src/cost/pricing.js`): a default pricing table
32
+ covering 15+ models across five providers — Anthropic, OpenAI, Google,
33
+ AWS Bedrock, and DeepSeek. **Last verified 2026-07-29 — provider pricing
34
+ changes frequently and this table is not guaranteed to stay current;
35
+ override `costTracking.pricingTable` for production accuracy.**
36
+ - `defaultExtractor` (`src/cost/extractor.js`): recognizes Anthropic
37
+ (`usage.input_tokens`/`usage.output_tokens`), OpenAI
38
+ (`usage.prompt_tokens`/`usage.completion_tokens`), and Bedrock
39
+ (`usage.inputTokens`/`usage.outputTokens`) usage shapes, the MCP
40
+ `_meta.usage` extension point, and JSON-in-text inside
41
+ `content[0].text`. Never throws — unrecognized shapes resolve to `null`.
42
+ Pluggable via `costTracking.extractor` (type `UsageExtractor`) for
43
+ custom tool result formats.
44
+ - `calculateCost()` (`src/cost/calculator.js`): normalizes a model name
45
+ (lowercase, strips a `provider/` prefix) and prices it against a
46
+ `PricingTable`. Returns `null` — never throws — for an unrecognized
47
+ model or invalid token counts.
48
+ - `costTracking` option on `instrumentMcpServer()` (see `src/config.js`):
49
+ `{ enabled?: boolean; pricingTable?: PricingTable; extractor?:
50
+ UsageExtractor; budget?: { perSessionUsd?: number; perToolUsd?: number
51
+ } }`. Defaults to enabled, `DEFAULT_PRICING`, `defaultExtractor`, budget
52
+ tracking off. Any field can be overridden independently.
53
+
54
+ ### Public API additions
55
+
56
+ Re-exported from the package root (`src/index.js` / `src/index.d.ts`):
57
+ `DEFAULT_PRICING`, `defaultExtractor`, `calculateCost` (values), and
58
+ `ModelPricing`, `PricingTable`, `UsageExtractor`, `TokenUsage`,
59
+ `CostTrackingOptions` (types, from the new `src/cost/types.d.ts` —
60
+ mirrors the `src/fingerprint/types.d.ts` pattern).
61
+
62
+ ### Docs
63
+
64
+ - `gen_ai.tool.name`'s comment in `src/attributes.js` now explicitly notes
65
+ it's sourced from the OTel GenAI semantic conventions, not a custom
66
+ addition — the file already documented this at the module/section level,
67
+ but not on the constant itself, which read ambiguously next to the
68
+ custom attributes below it that do say so explicitly.
69
+ - README: new "Cost & Token Attribution (v0.5.0)" section (motivation,
70
+ zero-config quick-start, advanced config example, span-attribute and
71
+ metric tables, pricing-accuracy note, extension points); intro tagline
72
+ and "Configuration"/"Semantic conventions"/"Roadmap"/"Compatibility"
73
+ sections updated to match.
74
+
3
75
  ## 0.3.0
4
76
 
5
77
  ### Added