Commit da85d7b
committed
review (stas): extract llm metrics to core/observability + add request counter
Two follow-up changes from the PR review:
1. Move the LLM metric instruments from _StreamingMetrics in
temporal_streaming_model.py to a new module:
agentex.lib.core.observability.llm_metrics
Public API: get_llm_metrics() returns a singleton LLMMetrics with
the same six instruments (ttft, tps, input_tokens, output_tokens,
cached_input_tokens, reasoning_tokens) plus a new requests counter.
This makes the temporal+openai_agents plugin one of several future
call sites — the sync ACP path and the Claude SDK plugin can
record to the same instruments without redefining names, units,
or descriptions. Keeps cross-provider naming consistent.
2. Add agentex.llm.requests counter with a status label so 429s,
5xxs, timeouts, and other failures are observable on the SDK
side without scraping logs. classify_status() maps exception
types to a small fixed set (success / rate_limit / server_error
/ client_error / timeout / network_error / other_error) by class
name, so it works across OpenAI, Anthropic, and other provider
SDKs that use similar exception naming.
Recorded in two places: success path (alongside token counters)
and the existing get_response except handler (so terminal
failures emit a counter event before re-raising).
Cardinality remains bounded — model + status (7 values) on the
counter; all other metrics keep just `model`.1 parent 6209b20 commit da85d7b
3 files changed
Lines changed: 128 additions & 61 deletions
File tree
- src/agentex/lib/core
- observability
- temporal/plugins/openai_agents/models
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
Lines changed: 16 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
138 | 86 | | |
139 | 87 | | |
140 | 88 | | |
| |||
1070 | 1018 | | |
1071 | 1019 | | |
1072 | 1020 | | |
1073 | | - | |
| 1021 | + | |
1074 | 1022 | | |
| 1023 | + | |
1075 | 1024 | | |
1076 | 1025 | | |
1077 | 1026 | | |
1078 | 1027 | | |
1079 | 1028 | | |
1080 | 1029 | | |
1081 | 1030 | | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
1086 | 1035 | | |
1087 | 1036 | | |
1088 | 1037 | | |
| |||
1107 | 1056 | | |
1108 | 1057 | | |
1109 | 1058 | | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1110 | 1065 | | |
1111 | 1066 | | |
1112 | 1067 | | |
| |||
0 commit comments