@@ -862,11 +862,12 @@ def capture_event(
862
862
863
863
return return_value
864
864
865
- def _capture_experimental_log (self , scope , log ):
865
+ def _capture_experimental_log (self , current_scope , log ):
866
866
# type: (Scope, Log) -> None
867
867
logs_enabled = self .options ["_experiments" ].get ("enable_sentry_logs" , False )
868
868
if not logs_enabled :
869
869
return
870
+ isolation_scope = current_scope .get_isolation_scope ()
870
871
871
872
headers = {
872
873
"sent_at" : format_timestamp (datetime .now (timezone .utc )),
@@ -880,16 +881,16 @@ def _capture_experimental_log(self, scope, log):
880
881
if release is not None and "sentry.release" not in log ["attributes" ]:
881
882
log ["attributes" ]["sentry.release" ] = release
882
883
883
- span = scope .span
884
+ span = current_scope .span
884
885
if span is not None and "sentry.trace.parent_span_id" not in log ["attributes" ]:
885
886
log ["attributes" ]["sentry.trace.parent_span_id" ] = span .span_id
886
887
887
- propagation_context = scope . get_active_propagation_context ()
888
- if propagation_context is not None :
889
- if propagation_context . dynamic_sampling_context is not None :
890
- headers [ "trace" ] = propagation_context . dynamic_sampling_context
891
-
892
- if log [ "trace_id" ] is None :
888
+ if log . get ( "trace_id" ) is None :
889
+ transaction = current_scope . transaction
890
+ propagation_context = isolation_scope . get_active_propagation_context ()
891
+ if transaction is not None :
892
+ log [ "trace_id" ] = transaction . trace_id
893
+ elif propagation_context is not None :
893
894
log ["trace_id" ] = propagation_context .trace_id
894
895
895
896
# If debug is enabled, log the log to the console
0 commit comments