Skip to content

Commit 04b9f2c

Browse files
committed
Addressed comments
1 parent c93a357 commit 04b9f2c

File tree

1 file changed

+15
-4
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal

1 file changed

+15
-4
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def emit(
763763
)
764764
if is_less_than_min_severity(record, self._min_severity_level):
765765
return
766-
if should_drop_logs_for_trace_based(record, self._trace_based):
766+
if should_drop_logs_for_unsampled_trace(record, self._trace_based):
767767
return
768768

769769
log_data = LogData(record, self._instrumentation_scope)
@@ -952,6 +952,11 @@ def std_to_otel(levelno: int) -> SeverityNumber:
952952
def is_less_than_min_severity(
953953
record: LogRecord, min_severity: SeverityNumber
954954
) -> bool:
955+
"""
956+
Check if the log record's severity number is less than the minimum severity level. If a log record's severity number is
957+
specified (i.e. not `0`) and is less than the configured `minimum_severity`, the log record MUST be dropped by the `Logger`.
958+
Log records with an unspecified severity (i.e. `0`) are not affected by this parameter and therefore bypass minimum severity filtering.
959+
"""
955960
if record.severity_number is not None:
956961
if (
957962
min_severity is not None
@@ -962,10 +967,16 @@ def is_less_than_min_severity(
962967
return False
963968

964969

965-
def should_drop_logs_for_trace_based(
966-
record: LogRecord, trace_state_enabled: bool
970+
def should_drop_logs_for_unsampled_trace(
971+
record: LogRecord, trace_based: bool
967972
) -> bool:
968-
if trace_state_enabled:
973+
"""
974+
Determines whether the logger should only process log records associated with sampled traces.
975+
If not explicitly set, the `trace_based` parameter is defaulted to `false`. If `trace_based` is `true`, log records associated with unsampled traces MUST
976+
be dropped by the `Logger`. A log record is considered associated with an unsampled trace if it has a valid `SpanId` and its `TraceFlags` indicate that the trace is unsampled.
977+
Log records that aren't associated with a trace context are not affected by this parameter and therefore bypass trace-based filtering.
978+
"""
979+
if trace_based:
969980
if record.context is not None:
970981
span = get_current_span(record.context)
971982
span_context = span.get_span_context()

0 commit comments

Comments
 (0)