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 +72 -0
- package/README.md +401 -178
- package/package.json +4 -1
- package/src/attributes.js +81 -1
- package/src/config.js +39 -0
- package/src/cost/budget.js +113 -0
- package/src/cost/calculator.js +55 -0
- package/src/cost/extractor.js +189 -0
- package/src/cost/pricing.js +56 -0
- package/src/cost/types.d.ts +85 -0
- package/src/fingerprint/attributes.js +56 -0
- package/src/fingerprint/classify/auth.js +29 -0
- package/src/fingerprint/classify/dependency.js +32 -0
- package/src/fingerprint/classify/index.js +59 -0
- package/src/fingerprint/classify/internal.js +17 -0
- package/src/fingerprint/classify/network.js +35 -0
- package/src/fingerprint/classify/serialization.js +27 -0
- package/src/fingerprint/classify/timeout.js +29 -0
- package/src/fingerprint/classify/validation.js +29 -0
- package/src/fingerprint/compose.js +149 -0
- package/src/fingerprint/hash.js +39 -0
- package/src/fingerprint/normalize/message.js +30 -0
- package/src/fingerprint/normalize/patterns.js +108 -0
- package/src/fingerprint/normalize/stack.js +165 -0
- package/src/fingerprint/types.d.ts +93 -0
- package/src/index.d.ts +44 -0
- package/src/index.js +8 -0
- package/src/instrument.js +145 -7
- package/src/metrics.js +59 -7
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
|