File tree Expand file tree Collapse file tree
instrumentation-anthropic/src
instrumentation-bedrock/src
instrumentation-google-generativeai/src
instrumentation-openai/src
instrumentation-together/src
instrumentation-vertexai/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -530,13 +530,19 @@ export class AnthropicInstrumentation extends InstrumentationBase {
530530 ) ;
531531
532532 // Cache token attributes (v1.40)
533- if ( result . usage . cache_creation_input_tokens != null ) {
533+ if (
534+ result . usage . cache_creation_input_tokens !== null &&
535+ result . usage . cache_creation_input_tokens !== undefined
536+ ) {
534537 span . setAttribute (
535538 ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ,
536539 result . usage . cache_creation_input_tokens ,
537540 ) ;
538541 }
539- if ( result . usage . cache_read_input_tokens != null ) {
542+ if (
543+ result . usage . cache_read_input_tokens !== null &&
544+ result . usage . cache_read_input_tokens !== undefined
545+ ) {
540546 span . setAttribute (
541547 ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
542548 result . usage . cache_read_input_tokens ,
Original file line number Diff line number Diff line change @@ -703,13 +703,15 @@ export class BedrockInstrumentation extends InstrumentationBase {
703703 [ ATTR_GEN_AI_USAGE_OUTPUT_TOKENS ] : usage [ "output_tokens" ] ,
704704 [ SpanAttributes . GEN_AI_USAGE_TOTAL_TOKENS ] :
705705 ( usage [ "input_tokens" ] || 0 ) + ( usage [ "output_tokens" ] || 0 ) ,
706- ...( usage [ "cache_read_input_tokens" ]
706+ ...( usage [ "cache_read_input_tokens" ] !== null &&
707+ usage [ "cache_read_input_tokens" ] !== undefined
707708 ? {
708709 [ ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] :
709710 usage [ "cache_read_input_tokens" ] ,
710711 }
711712 : { } ) ,
712- ...( usage [ "cache_creation_input_tokens" ]
713+ ...( usage [ "cache_creation_input_tokens" ] !== null &&
714+ usage [ "cache_creation_input_tokens" ] !== undefined
713715 ? {
714716 [ ATTR_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ] :
715717 usage [ "cache_creation_input_tokens" ] ,
Original file line number Diff line number Diff line change @@ -495,7 +495,7 @@ export class GenAIInstrumentation extends InstrumentationBase {
495495 SpanAttributes . GEN_AI_USAGE_REASONING_TOKENS ,
496496 reasoningTokens ,
497497 ) ;
498- if ( cachedTokens != null )
498+ if ( cachedTokens !== null && cachedTokens !== undefined )
499499 span . setAttribute (
500500 ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
501501 cachedTokens ,
Original file line number Diff line number Diff line change @@ -970,7 +970,7 @@ export class OpenAIInstrumentation extends InstrumentationBase {
970970 ) ;
971971 }
972972 const cachedTokens = result . usage . input_tokens_details ?. cached_tokens ;
973- if ( cachedTokens ) {
973+ if ( cachedTokens !== null && cachedTokens !== undefined ) {
974974 span . setAttribute (
975975 ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
976976 cachedTokens ,
Original file line number Diff line number Diff line change @@ -525,7 +525,7 @@ export class TogetherInstrumentation extends InstrumentationBase {
525525 const cachedTokens = (
526526 result . usage as unknown as Record < string , unknown >
527527 ) . cached_tokens ;
528- if ( cachedTokens ) {
528+ if ( cachedTokens !== null && cachedTokens !== undefined ) {
529529 span . setAttribute (
530530 ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
531531 cachedTokens as number ,
Original file line number Diff line number Diff line change @@ -253,7 +253,10 @@ export class VertexAIInstrumentation extends InstrumentationBase {
253253 streamResponse . usageMetadata . promptTokenCount ,
254254 ) ;
255255
256- if ( streamResponse . usageMetadata ?. cachedContentTokenCount )
256+ if (
257+ streamResponse . usageMetadata ?. cachedContentTokenCount !== null &&
258+ streamResponse . usageMetadata ?. cachedContentTokenCount !== undefined
259+ )
257260 span . setAttribute (
258261 ATTR_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
259262 streamResponse . usageMetadata . cachedContentTokenCount ,
You can’t perform that action at this time.
0 commit comments