Skip to content

Commit 3fc82ac

Browse files
committed
Addressed comments
1 parent 75fb724 commit 3fc82ac

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
@@ -750,7 +750,7 @@ def emit(
750750
)
751751
if is_less_than_min_severity(record, self._min_severity_level):
752752
return
753-
if should_drop_logs_for_trace_based(record, self._trace_based):
753+
if should_drop_logs_for_unsampled_trace(record, self._trace_based):
754754
return
755755

756756
log_data = LogData(record, self._instrumentation_scope)
@@ -939,6 +939,11 @@ def std_to_otel(levelno: int) -> SeverityNumber:
939939
def is_less_than_min_severity(
940940
record: LogRecord, min_severity: SeverityNumber
941941
) -> bool:
942+
"""
943+
Check if the log record's severity number is less than the minimum severity level. If a log record's severity number is
944+
specified (i.e. not `0`) and is less than the configured `minimum_severity`, the log record MUST be dropped by the `Logger`.
945+
Log records with an unspecified severity (i.e. `0`) are not affected by this parameter and therefore bypass minimum severity filtering.
946+
"""
942947
if record.severity_number is not None:
943948
if (
944949
min_severity is not None
@@ -949,10 +954,16 @@ def is_less_than_min_severity(
949954
return False
950955

951956

952-
def should_drop_logs_for_trace_based(
953-
record: LogRecord, trace_state_enabled: bool
957+
def should_drop_logs_for_unsampled_trace(
958+
record: LogRecord, trace_based: bool
954959
) -> bool:
955-
if trace_state_enabled:
960+
"""
961+
Determines whether the logger should only process log records associated with sampled traces.
962+
If not explicitly set, the `trace_based` parameter is defaulted to `false`. If `trace_based` is `true`, log records associated with unsampled traces MUST
963+
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.
964+
Log records that aren't associated with a trace context are not affected by this parameter and therefore bypass trace-based filtering.
965+
"""
966+
if trace_based:
956967
if record.context is not None:
957968
span = get_current_span(record.context)
958969
span_context = span.get_span_context()

0 commit comments

Comments
 (0)