@@ -356,32 +356,43 @@ def _capture_log_from_record(self, client, record):
356
356
record .levelno , SEVERITY_TO_OTEL_SEVERITY
357
357
)
358
358
project_root = client .options ["project_root" ]
359
+
359
360
attrs = self ._extra_from_record (record ) # type: Any
360
361
attrs ["sentry.origin" ] = "auto.logger.log"
361
- if isinstance ( record . msg , str ):
362
- attrs [ "sentry.message.template" ] = record . msg
362
+
363
+ parameters_set = False
363
364
if record .args is not None :
364
365
if isinstance (record .args , tuple ):
366
+ parameters_set = bool (record .args )
365
367
for i , arg in enumerate (record .args ):
366
368
attrs [f"sentry.message.parameter.{ i } " ] = (
367
369
arg
368
370
if isinstance (arg , (str , float , int , bool ))
369
371
else safe_repr (arg )
370
372
)
371
373
elif isinstance (record .args , dict ):
374
+ parameters_set = bool (record .args )
372
375
for key , value in record .args .items ():
373
376
attrs [f"sentry.message.parameter.{ key } " ] = (
374
377
value
375
378
if isinstance (value , (str , float , int , bool ))
376
379
else safe_repr (value )
377
380
)
381
+
382
+ if parameters_set and isinstance (record .msg , str ):
383
+ # only include template if there is at least one
384
+ # sentry.message.parameter.X set
385
+ attrs ["sentry.message.template" ] = record .msg
386
+
378
387
if record .lineno :
379
388
attrs ["code.line.number" ] = record .lineno
389
+
380
390
if record .pathname :
381
391
if project_root is not None and record .pathname .startswith (project_root ):
382
392
attrs ["code.file.path" ] = record .pathname [len (project_root ) + 1 :]
383
393
else :
384
394
attrs ["code.file.path" ] = record .pathname
395
+
385
396
if record .funcName :
386
397
attrs ["code.function.name" ] = record .funcName
387
398
0 commit comments