@@ -170,6 +170,7 @@ def log_success_event( # noqa: PLR0915
170
170
verbose_logger .debug ("REACHES BRAINTRUST SUCCESS" )
171
171
try :
172
172
litellm_call_id = kwargs .get ("litellm_call_id" )
173
+ standard_logging_object = kwargs .get ("standard_logging_object" , {})
173
174
prompt = {"messages" : kwargs .get ("messages" )}
174
175
output = None
175
176
choices = []
@@ -193,33 +194,13 @@ def log_success_event( # noqa: PLR0915
193
194
):
194
195
output = response_obj ["data" ]
195
196
196
- litellm_params = kwargs .get ("litellm_params" , {})
197
- metadata = (
198
- litellm_params .get ("metadata" , {}) or {}
199
- ) # if litellm_params['metadata'] == None
200
- metadata = self .add_metadata_from_header (litellm_params , metadata )
201
- clean_metadata = {}
202
- try :
203
- metadata = copy .deepcopy (
204
- metadata
205
- ) # Avoid modifying the original metadata
206
- except Exception :
207
- new_metadata = {}
208
- for key , value in metadata .items ():
209
- if (
210
- isinstance (value , list )
211
- or isinstance (value , dict )
212
- or isinstance (value , str )
213
- or isinstance (value , int )
214
- or isinstance (value , float )
215
- ):
216
- new_metadata [key ] = copy .deepcopy (value )
217
- metadata = new_metadata
197
+ litellm_params = kwargs .get ("litellm_params" , {}) or {}
198
+ dynamic_metadata = litellm_params .get ("dynamic_metadata" , {}) or {}
218
199
219
200
# Get project_id from metadata or create default if needed
220
- project_id = metadata .get ("project_id" )
201
+ project_id = dynamic_metadata .get ("project_id" )
221
202
if project_id is None :
222
- project_name = metadata .get ("project_name" )
203
+ project_name = dynamic_metadata .get ("project_name" )
223
204
project_id = (
224
205
self .get_project_id_sync (project_name ) if project_name else None
225
206
)
@@ -230,8 +211,8 @@ def log_success_event( # noqa: PLR0915
230
211
project_id = self .default_project_id
231
212
232
213
tags = []
233
- if isinstance (metadata , dict ):
234
- for key , value in metadata .items ():
214
+ if isinstance (dynamic_metadata , dict ):
215
+ for key , value in dynamic_metadata .items ():
235
216
# generate langfuse tags - Default Tags sent to Langfuse from LiteLLM Proxy
236
217
if (
237
218
litellm .langfuse_default_tags is not None
@@ -240,25 +221,7 @@ def log_success_event( # noqa: PLR0915
240
221
):
241
222
tags .append (f"{ key } :{ value } " )
242
223
243
- # clean litellm metadata before logging
244
- if key in [
245
- "headers" ,
246
- "endpoint" ,
247
- "caching_groups" ,
248
- "previous_models" ,
249
- ]:
250
- continue
251
- else :
252
- clean_metadata [key ] = value
253
-
254
224
cost = kwargs .get ("response_cost" , None )
255
- if cost is not None :
256
- clean_metadata ["litellm_response_cost" ] = cost
257
-
258
- # metadata.model is required for braintrust to calculate the "Estimated cost" metric
259
- litellm_model = kwargs .get ("model" , None )
260
- if litellm_model is not None :
261
- clean_metadata ["model" ] = litellm_model
262
225
263
226
metrics : Optional [dict ] = None
264
227
usage_obj = getattr (response_obj , "usage" , None )
@@ -276,12 +239,12 @@ def log_success_event( # noqa: PLR0915
276
239
}
277
240
278
241
# Allow metadata override for span name
279
- span_name = metadata .get ("span_name" , "Chat Completion" )
242
+ span_name = dynamic_metadata .get ("span_name" , "Chat Completion" )
280
243
281
244
request_data = {
282
245
"id" : litellm_call_id ,
283
246
"input" : prompt ["messages" ],
284
- "metadata" : clean_metadata ,
247
+ "metadata" : standard_logging_object ,
285
248
"tags" : tags ,
286
249
"span_attributes" : {"name" : span_name , "type" : "llm" },
287
250
}
0 commit comments