Skip to content

Commit 0367592

Browse files
committed
finish trace id logic
1 parent 392a7da commit 0367592

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sentry_sdk/client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,12 @@ def capture_event(
862862

863863
return return_value
864864

865-
def _capture_experimental_log(self, scope, log):
865+
def _capture_experimental_log(self, current_scope, log):
866866
# type: (Scope, Log) -> None
867867
logs_enabled = self.options["_experiments"].get("enable_sentry_logs", False)
868868
if not logs_enabled:
869869
return
870+
isolation_scope = current_scope.get_isolation_scope()
870871

871872
headers = {
872873
"sent_at": format_timestamp(datetime.now(timezone.utc)),
@@ -880,16 +881,16 @@ def _capture_experimental_log(self, scope, log):
880881
if release is not None and "sentry.release" not in log["attributes"]:
881882
log["attributes"]["sentry.release"] = release
882883

883-
span = scope.span
884+
span = current_scope.span
884885
if span is not None and "sentry.trace.parent_span_id" not in log["attributes"]:
885886
log["attributes"]["sentry.trace.parent_span_id"] = span.span_id
886887

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:
893894
log["trace_id"] = propagation_context.trace_id
894895

895896
# If debug is enabled, log the log to the console

0 commit comments

Comments
 (0)