@@ -78,75 +78,68 @@ export default {
7878}
7979
8080function toLakeEvent ( time : string , data : Record < string , unknown > ) {
81- const tokensInput = integer ( data , "tokens.input" )
82- const tokensOutput = integer ( data , "tokens.output" )
83- const tokensReasoning = integer ( data , "tokens.reasoning" )
84- const tokensCacheRead = integer ( data , "tokens.cache_read" )
85- const tokensCacheWrite5m = integer ( data , "tokens.cache_write_5m" )
86- const tokensCacheWrite1h = integer ( data , "tokens.cache_write_1h" )
87- const timestampFirstByte = integer ( data , "timestamp.first_byte" )
88- const timestampLastByte = integer ( data , "timestamp.last_byte" )
89- const source = string ( data , "source" )
90-
9181 return {
9282 _datalake_key : "inference.event" ,
9383 event_timestamp : time ,
9484 event_date : time . slice ( 0 , 10 ) ,
9585 event_type : string ( data , "event_type" ) ,
9686 dataset : "zen" ,
87+ cf_continent : string ( data , "cf.continent" ) ,
88+ cf_country : string ( data , "cf.country" ) ,
89+ cf_city : string ( data , "cf.city" ) ,
90+ cf_region : string ( data , "cf.region" ) ,
91+ cf_latitude : number ( data , "cf.latitude" ) ,
92+ cf_longitude : number ( data , "cf.longitude" ) ,
93+ cf_timezone : string ( data , "cf.timezone" ) ,
94+ duration : number ( data , "duration" ) ,
95+ request_length : integer ( data , "request_length" ) ,
96+ status : integer ( data , "status" ) ,
97+ ip : string ( data , "ip" ) ,
98+ is_stream : boolean ( data , "is_stream" ) ,
99+ session : string ( data , "session" ) ,
100+ request : string ( data , "request" ) ,
97101 client : string ( data , "client" ) ,
98- source,
99- tier : source ,
102+ user_agent : string ( data , "user_agent" ) ,
103+ model_variant : string ( data , "model.variant" ) ,
104+ source : string ( data , "source" ) ,
100105 provider : string ( data , "provider" ) ,
101106 provider_model : string ( data , "provider.model" ) ,
102107 model : string ( data , "model" ) ,
103- session : string ( data , "session" ) ,
104- request : string ( data , "request" ) ,
105- user_agent : string ( data , "user_agent" ) ,
106- ip : string ( data , "ip" ) ,
107- status : integer ( data , "status" ) ,
108- is_stream : boolean ( data , "is_stream" ) ,
109- duration_ms : integer ( data , "duration" ) ,
110- ttfb_ms : integer ( data , "time_to_first_byte" ) ,
111- request_length : integer ( data , "request_length" ) ,
108+ llm_error_code : integer ( data , "llm.error.code" ) ,
109+ llm_error_message : string ( data , "llm.error.message" ) ,
110+ error_response : string ( data , "error.response" ) ,
111+ error_type : string ( data , "error.type" ) ,
112+ error_message : string ( data , "error.message" ) ,
113+ error_cause : string ( data , "error.cause" ) ,
114+ error_cause2 : string ( data , "error.cause2" ) ,
115+ api_key : string ( data , "api_key" ) ,
116+ workspace : string ( data , "workspace" ) ,
117+ is_subscription : boolean ( data , "isSubscription" ) ,
118+ subscription : string ( data , "subscription" ) ,
112119 response_length : integer ( data , "response_length" ) ,
113- timestamp_first_byte : timestampFirstByte ,
114- timestamp_last_byte : timestampLastByte ,
115- tokens_input : tokensInput ,
116- tokens_output : tokensOutput ,
117- tokens_reasoning : tokensReasoning ,
118- tokens_cache_read : tokensCacheRead ,
119- tokens_cache_write_5m : tokensCacheWrite5m ,
120- tokens_cache_write_1h : tokensCacheWrite1h ,
121- tokens_total :
122- integer ( data , "tokens" ) ??
123- ( tokensInput ?? 0 ) +
124- ( tokensOutput ?? 0 ) +
125- ( tokensReasoning ?? 0 ) +
126- ( tokensCacheRead ?? 0 ) +
127- ( tokensCacheWrite5m ?? 0 ) +
128- ( tokensCacheWrite1h ?? 0 ) ,
120+ time_to_first_byte : integer ( data , "time_to_first_byte" ) ,
121+ timestamp_first_byte : integer ( data , "timestamp.first_byte" ) ,
122+ timestamp_last_byte : integer ( data , "timestamp.last_byte" ) ,
123+ tokens_input : integer ( data , "tokens.input" ) ,
124+ tokens_output : integer ( data , "tokens.output" ) ,
125+ tokens_reasoning : integer ( data , "tokens.reasoning" ) ,
126+ tokens_cache_read : integer ( data , "tokens.cache_read" ) ,
127+ tokens_cache_write_5m : integer ( data , "tokens.cache_write_5m" ) ,
128+ tokens_cache_write_1h : integer ( data , "tokens.cache_write_1h" ) ,
129129 cost_input_microcents : integer ( data , "cost.input.microcents" ) ,
130130 cost_output_microcents : integer ( data , "cost.output.microcents" ) ,
131131 cost_cache_read_microcents : integer ( data , "cost.cache_read.microcents" ) ,
132132 cost_cache_write_microcents : integer ( data , "cost.cache_write.microcents" ) ,
133133 cost_total_microcents : integer ( data , "cost.total.microcents" ) ,
134- output_tps : number ( data , "tps.output" ) ?? outputTps ( tokensOutput , timestampFirstByte , timestampLastByte ) ,
135- cf_continent : string ( data , "cf.continent" ) ,
136- cf_country : string ( data , "cf.country" ) ,
137- cf_city : string ( data , "cf.city" ) ,
138- cf_region : string ( data , "cf.region" ) ,
139- cf_latitude : number ( data , "cf.latitude" ) ,
140- cf_longitude : number ( data , "cf.longitude" ) ,
141- cf_timezone : string ( data , "cf.timezone" ) ,
134+ cost_input : integer ( data , "cost.input" ) ,
135+ cost_output : integer ( data , "cost.output" ) ,
136+ cost_cache_read : integer ( data , "cost.cache_read" ) ,
137+ cost_cache_write_5m : integer ( data , "cost.cache_write_5m" ) ,
138+ cost_cache_write_1h : integer ( data , "cost.cache_write_1h" ) ,
139+ cost_total : integer ( data , "cost.total" ) ,
142140 }
143141}
144142
145- function outputTps ( tokens : number | undefined , firstByte : number | undefined , lastByte : number | undefined ) {
146- if ( ! tokens || ! firstByte || ! lastByte || lastByte <= firstByte ) return undefined
147- return Number ( ( ( tokens / ( lastByte - firstByte ) ) * 1000 ) . toFixed ( 6 ) )
148- }
149-
150143function string ( data : Record < string , unknown > , key : string ) {
151144 const value = data [ key ]
152145 if ( typeof value === "string" ) return value
0 commit comments