Commit 3a07cb4
authored
fix(telemetry): emit OTel-standard gen_ai.usage.cache_read.input_tokens across providers (0xPlaygrounds#1666)
* fix: emit OTel-standard cache_read.input_tokens across providers
Provider spans declared `gen_ai.usage.cached_tokens` (non-OTel) but the
shared telemetry helpers (`SpanCombinator::record_token_usage`,
`openai_chat_completions_compatible::record_usage`) write the OTel-
standard `gen_ai.usage.cache_read.input_tokens`. Because `tracing`
silently drops `.record()` for fields not declared on the span, cached-
token values were being computed and thrown away on every provider whose
span did not declare the OTel name.
Declare `gen_ai.usage.cache_read.input_tokens` on every affected span
across OpenAI, Azure, Cohere, Gemini (incl. interactions_api), Groq,
DeepSeek, HuggingFace, Mistral, OpenRouter, Together, xAI, Copilot,
and llamafile. Emit `cache_read.input_tokens` from the OpenAI chat-
completions compatible helper and the OpenAI Responses API record
sites. Do not emit `cache_creation.input_tokens` on OpenAI-family spans
— those APIs have no cache-creation concept and a hardcoded 0 would be
misleading rather than informative. Anthropic, which does report cache
creation, is unchanged.
Remove the non-OTel `gen_ai.usage.cached_tokens` attribute from every
path this change touches: drop the span declaration and, on paths whose
only recording sites are modified here, drop the record calls too. Only
the OTel-standard attribute is emitted from these paths.
Spans that record cache tokens entirely through their own inline
`span.record("gen_ai.usage.cached_tokens", ...)` calls (e.g. non-
streaming paths of Groq, DeepSeek, Copilot; standalone files like
Galadriel, Hyperbolic, Mira, Moonshot, Ollama, Perplexity, ChatGPT;
non-streaming Together and xAI) are out of scope for this change and
continue to emit only `cached_tokens`.
* fix: emit cache_read.input_tokens on 5 providers missed by prior commit
Galadriel, Hyperbolic, Mira, Moonshot, and Perplexity all route their
streaming paths through `send_compatible_streaming_request`, whose
shared `record_usage` helper was updated in the prior commit to write
the OTel-standard `gen_ai.usage.cache_read.input_tokens`. These five
provider spans still declared `gen_ai.usage.cached_tokens`, so the
newly-recorded value was silently dropped by `tracing` — and since
none of these files inline-records `cached_tokens` either, their
streaming paths were emitting no cache-read metric at all after the
prior commit landed.
Rename the declaration to `gen_ai.usage.cache_read.input_tokens` on
both the non-streaming and streaming span in each file, matching the
pattern the prior commit already applied across the other providers.
The non-streaming rename is a no-op (no recorder targets the field on
that path) but keeps both spans in each file consistent.
* fix: complete cache_read.input_tokens rename across remaining providers
Prior two commits partially renamed gen_ai.usage.cached_tokens to the
canonical OTel GenAI attribute gen_ai.usage.cache_read.input_tokens but
left several providers (and some streaming-vs-non-streaming paths within
a provider) emitting the old name. Finish the rename in chatgpt,
copilot, deepseek (non-streaming), groq (non-streaming), ollama,
together/completion, and xai/completion so every span consistently
emits cache_read.input_tokens.1 parent de43a16 commit 3a07cb4
32 files changed
Lines changed: 66 additions & 65 deletions
File tree
- rig/rig-core/src/providers
- chatgpt
- cohere
- copilot
- gemini
- interactions_api
- huggingface
- internal
- mistral
- openai
- completion
- responses_api
- openrouter
- together
- xai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
712 | | - | |
| 712 | + | |
713 | 713 | | |
714 | 714 | | |
715 | 715 | | |
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
812 | | - | |
| 812 | + | |
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | | - | |
| 496 | + | |
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
513 | | - | |
| 513 | + | |
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
| 578 | + | |
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
| 646 | + | |
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
684 | | - | |
| 684 | + | |
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| |||
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
708 | | - | |
| 708 | + | |
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| |||
762 | 762 | | |
763 | 763 | | |
764 | 764 | | |
765 | | - | |
| 765 | + | |
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
785 | | - | |
| 785 | + | |
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
| |||
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
846 | | - | |
| 846 | + | |
847 | 847 | | |
848 | 848 | | |
849 | 849 | | |
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
| 888 | + | |
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
| |||
1042 | 1042 | | |
1043 | 1043 | | |
1044 | 1044 | | |
1045 | | - | |
| 1045 | + | |
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
563 | | - | |
| 563 | + | |
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| |||
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
603 | | - | |
| 603 | + | |
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
676 | | - | |
| 676 | + | |
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
556 | | - | |
| 556 | + | |
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | | - | |
| 656 | + | |
657 | 657 | | |
658 | 658 | | |
659 | 659 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
0 commit comments