File tree Expand file tree Collapse file tree 4 files changed +21
-0
lines changed
test/llmobs/plugins/anthropic Expand file tree Collapse file tree 4 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ module.exports = {
3838 TOTAL_TOKENS_METRIC_KEY : 'total_tokens' ,
3939 CACHE_READ_INPUT_TOKENS_METRIC_KEY : 'cache_read_input_tokens' ,
4040 CACHE_WRITE_INPUT_TOKENS_METRIC_KEY : 'cache_write_input_tokens' ,
41+ CACHE_WRITE_5M_INPUT_TOKENS_METRIC_KEY : 'ephemeral_5m_input_tokens' ,
42+ CACHE_WRITE_1H_INPUT_TOKENS_METRIC_KEY : 'ephemeral_1h_input_tokens' ,
4143 REASONING_OUTPUT_TOKENS_METRIC_KEY : 'reasoning_output_tokens' ,
4244
4345 DROPPED_IO_COLLECTION_ERROR : 'dropped_io' ,
Original file line number Diff line number Diff line change @@ -253,6 +253,15 @@ class AnthropicLLMObsPlugin extends LLMObsPlugin {
253253 if ( cacheWriteTokens != null ) metrics . cacheWriteTokens = cacheWriteTokens
254254 if ( cacheReadTokens != null ) metrics . cacheReadTokens = cacheReadTokens
255255
256+ const cacheCreation = usage . cache_creation
257+ if ( cacheCreation ) {
258+ metrics . cacheWrite5mTokens = cacheCreation . ephemeral_5m_input_tokens ?? 0
259+ metrics . cacheWrite1hTokens = cacheCreation . ephemeral_1h_input_tokens ?? 0
260+ } else if ( cacheWriteTokens != null ) {
261+ metrics . cacheWrite5mTokens = cacheWriteTokens
262+ metrics . cacheWrite1hTokens = 0
263+ }
264+
256265 this . _tagger . tagMetrics ( span , metrics )
257266 }
258267
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ const {
2222 ROOT_PARENT_ID ,
2323 CACHE_READ_INPUT_TOKENS_METRIC_KEY ,
2424 CACHE_WRITE_INPUT_TOKENS_METRIC_KEY ,
25+ CACHE_WRITE_5M_INPUT_TOKENS_METRIC_KEY ,
26+ CACHE_WRITE_1H_INPUT_TOKENS_METRIC_KEY ,
2527 INPUT_TOKENS_METRIC_KEY ,
2628 OUTPUT_TOKENS_METRIC_KEY ,
2729 TOTAL_TOKENS_METRIC_KEY ,
@@ -185,6 +187,12 @@ class LLMObsTagger {
185187 case 'cacheWriteTokens' :
186188 processedKey = CACHE_WRITE_INPUT_TOKENS_METRIC_KEY
187189 break
190+ case 'cacheWrite5mTokens' :
191+ processedKey = CACHE_WRITE_5M_INPUT_TOKENS_METRIC_KEY
192+ break
193+ case 'cacheWrite1hTokens' :
194+ processedKey = CACHE_WRITE_1H_INPUT_TOKENS_METRIC_KEY
195+ break
188196 case 'reasoningOutputTokens' :
189197 processedKey = REASONING_OUTPUT_TOKENS_METRIC_KEY
190198 break
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ function assertLLMObsSpan (apmSpans, llmobsSpans) {
3232 total_tokens : MOCK_NUMBER ,
3333 cache_write_input_tokens : MOCK_NUMBER ,
3434 cache_read_input_tokens : MOCK_NUMBER ,
35+ ephemeral_5m_input_tokens : MOCK_NUMBER ,
36+ ephemeral_1h_input_tokens : MOCK_NUMBER ,
3537 } ,
3638 tags : { ml_app : 'test' , integration : 'anthropic' } ,
3739 } )
You can’t perform that action at this time.
0 commit comments