Skip to content

Conversation

@alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Jan 14, 2026

  • Always set the log level to warning on server spans when the HTTP status code is 4xx. Previously this was only done specifically for a starlette/fastapi HTTPException. This affects for example 404 spans where there's no matching route.
  • Similarly set the log level to error based on HTTP status code in other cases (see docs diff), but this usually will already be set so known cases aren't affected
  • If an exception is handled by FastAPI (particularly by a custom handler), and the handler returns a 5xx status code, a fingerprint will be set on the span, meaning an alert issue will be created. Previously this only happened for HTTPException.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 14, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 32d5c56
Status: ✅  Deploy successful!
Preview URL: https://06666e15.logfire-docs.pages.dev
Branch Preview URL: https://alex-http-status-log-level.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki requested a review from Copilot January 14, 2026 14:44
@alexmojaki alexmojaki changed the title Set log level based on http status code Set log level based on HTTP status code, create issues for handled exceptions in FastAPI when the status code is 5xx Jan 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors how log levels are set for HTTP spans, moving from Starlette HTTPException-specific handling to a generic approach based on HTTP status codes and span kinds.

Changes:

  • Replaced HTTPException-specific log level handling with generic HTTP status code-based logic
  • Updated exception fingerprint handling for FastAPI to conditionally place fingerprints in events vs spans
  • Reordered span processor operations to ensure log levels are set before FastAPI-specific tweaks

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_logfire.py Added comprehensive test for HTTP status code-based log level setting across different span kinds
tests/otel_integrations/test_fastapi.py Updated test expectations to include new log level attributes and exception fingerprints
tests/otel_integrations/test_django.py Updated test expectations to include log level for 404 responses
tests/conftest.py Added ANTHROPIC_BASE_URL to environment cleanup (minor unrelated cleanup)
logfire/types.py Simplified create_issue logic by removing FastAPI-specific exception handling
logfire/_internal/tracer.py Removed HTTPException-specific handling and updated fingerprint logic for FastAPI exceptions
logfire/_internal/exporters/test.py Added normalization of exception fingerprints in test output for consistent assertions
logfire/_internal/exporters/processor_wrapper.py Added generic HTTP status code-based log level setting and reordered processor operations
docs/reference/sql.md Updated documentation to describe the new HTTP status code-based log level behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alexmojaki alexmojaki merged commit 2ec0a54 into main Jan 14, 2026
20 checks passed
@alexmojaki alexmojaki deleted the alex/http-status-log-level branch January 14, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants