Skip to content

Commit 4fc8c2d

Browse files
committed
Reduce diff
1 parent de627dc commit 4fc8c2d

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging

instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def record_factory(*args, **kwargs):
160160
):
161161
return record
162162

163-
# out of spec attributes are added to the log record only if log correlation is specified
163+
# out of spec attributes are added to the log record only if log correlation is set
164164
if set_logging_format:
165165
record.otelSpanID = "0"
166166
record.otelTraceID = "0"
@@ -182,6 +182,11 @@ def record_factory(*args, **kwargs):
182182
if span != INVALID_SPAN:
183183
ctx = span.get_span_context()
184184
if ctx != INVALID_SPAN_CONTEXT:
185+
if set_logging_format:
186+
record.otelSpanID = format(ctx.span_id, "016x")
187+
record.otelTraceID = format(ctx.trace_id, "032x")
188+
record.otelTraceSampled = ctx.trace_flags.sampled
189+
185190
if callable(LoggingInstrumentor._log_hook):
186191
try:
187192
LoggingInstrumentor._log_hook( # pylint: disable=E1102
@@ -190,11 +195,6 @@ def record_factory(*args, **kwargs):
190195
except Exception: # pylint: disable=W0703
191196
pass
192197

193-
if set_logging_format:
194-
record.otelSpanID = format(ctx.span_id, "016x")
195-
record.otelTraceID = format(ctx.trace_id, "032x")
196-
record.otelTraceSampled = ctx.trace_flags.sampled
197-
198198
return record
199199

200200
logging.setLogRecordFactory(record_factory)

0 commit comments

Comments
 (0)