Python: the log controls apply to the Logfire SDK's logs

Merged
ST
1mo ago
+172-36

Fixes a gap found in the Fleet end-to-end run: for an app on the Logfire SDK, pausing logs, log_levels and log_rate_limit did nothing, yet the policy came back APPLIED.

The Logfire SDK's logs (logfire.info(), and Python logging through LogfireLoggingHandler) are spans marked logfire.span_type = "log", so they went through the trace gate and never reached the log controls.

What changes

  • Controls.spans(to, log_spans=True), used only by configure_logfire's exporters to Logfire, sends Logfire log spans through the log controls:
    • the logs export (send_logs);
    • log_levels, by logfire.level_num (already an OpenTelemetry SeverityNumber). For scopes, the Python logger's name (logfire.logger_name), else the span's scope (logfire, logfire.<suffix>);
    • log_rate_limit.
  • The trace pause (send_traces) leaves Logfire logs alone, and their counts go to the logs' export counts. Other spans are gated as before.
  • The OpenTelemetry SDK path (configure(), opentelemetry-instrument) is unchanged: there, every span is a span.
  • docs/python-otel.md now describes this, replacing "the trace controls apply to them".

Spec

No OpAMP change. This is how the SDK carries out the send_logs* settings it already declares, so the APPLIED status is now true. Treating Logfire's log spans as logs, and the logger name as their scope, is our choice where the settings leave it open.

Tests

  • test_the_logfire_sdks_logs_go_through_the_log_controls_not_the_trace_ones (gate unit test) and test_the_log_controls_apply_to_the_logfire_sdks_logs (a real configure_logfire child using logfire.info/warn and the logging handler). Both fail without the change.
  • python/otel suite: 571 passed.

Generated by Claude Code