Skip to content

sentry_sdk.errors DEBUG logs are emitted without debug=True #4266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alex-700 opened this issue Apr 9, 2025 · 2 comments · Fixed by #4286
Closed

sentry_sdk.errors DEBUG logs are emitted without debug=True #4266

alex-700 opened this issue Apr 9, 2025 · 2 comments · Fixed by #4286
Assignees
Labels

Comments

@alex-700
Copy link

alex-700 commented Apr 9, 2025

How do you use Sentry?

Self-hosted/on-premise

Version

2.25.1

Steps to Reproduce

There is simple FastAPI project.

pyproject.toml

[project]
name = "bug"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.13"
dependencies = [
    "fastapi>=0.115.12",
    "pyyaml>=6.0.2",
    "sentry-sdk>=2.25.1",
    "uvicorn>=0.34.0",
]

main.py

import fastapi
import sentry_sdk

sentry_sdk.init()

app = fastapi.FastAPI()


@app.get("/")
def hello():
    print()

log_conf.yaml

version: 1
disable_existing_loggers: False
formatters:
  default:
    # "()": uvicorn.logging.DefaultFormatter
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
  access:
    # "()": uvicorn.logging.AccessFormatter
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
  default:
    formatter: default
    class: logging.StreamHandler
    stream: ext://sys.stderr
  default_stdout:
    formatter: default
    class: logging.StreamHandler
    stream: ext://sys.stdout
  access:
    formatter: access
    class: logging.StreamHandler
    stream: ext://sys.stdout
loggers:
  uvicorn.error:
    level: INFO
    handlers:
      - default
    propagate: no
  uvicorn.access:
    level: INFO
    handlers:
      - access
    propagate: no
root:
  level: DEBUG
  handlers:
    - default_stdout
  propagate: no

When I run it via uvicorn, the _DebugFilter seems to be not added as filter.

Expected Result

uv run uvicorn main:app --log-config log_conf.yaml

no DEBUG logs from sentry_sdk, while I do not use SENTRY_DEBUG (or debug=True).

Actual Result

uv run uvicorn main:app --log-config log_conf.yaml

There are a lot of DEBUG logs from sentry_sdk.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 9, 2025
@antonpirker
Copy link
Member

Hey @alex-700 can you show me how you load your log_conf.yaml and where the sentry_sdk.init() is in relation to the setting up of logging. (my guess right now is that maybe the sdks logging config is overwritten and thus the filter does not take effect)

Or maybe the _client_init_debug ContextVar in the SDK is somehow responsible for this...

@alex-700
Copy link
Author

Hi @antonpirker !

It can be seen from the files from the issue. The main idea is ASGI application (FastAPI from main.py in the example) is running via launcher (uvicorn in the example). The launcher is configuring logging first (which can install some logging handlers), and only after this it imports the package with the ASGI application and call the sentry_sdk.init(...) from the main.py.

But since some logging handlers was installed the condition is blocking configure_logging which includes _DebugFilter setup.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 10, 2025
@szokeasaurusrex szokeasaurusrex marked this as a duplicate of #4268 Apr 14, 2025
szokeasaurusrex added a commit that referenced this issue Apr 14, 2025
This reverts commit 3793084, which made the SDK consider parent loggers when determining if the Sentry SDK should log debug messages.

However, we should not consider parent loggers, since we only want the SDK to log debug messages when configured to do so via `debug=True` (in `sentry_sdk.init`), the `SENTRY_DEBUG` environment variable, or via a specific logger configuration for `sentry_sdk.errors`. With 3793084, a custom root logger configuration would also cause SDK logs to be emitted.

The issue 3793084 was meant to fix (#3944) appears to have been caused by user error, not a bug in the SDK.

Fixes #4266
@szokeasaurusrex szokeasaurusrex self-assigned this Apr 14, 2025
szokeasaurusrex added a commit that referenced this issue Apr 14, 2025
This reverts commit 3793084, which made the SDK consider parent loggers when determining if the Sentry SDK should log debug messages.

However, we should not consider parent loggers, since we only want the SDK to log debug messages when configured to do so via `debug=True` (in `sentry_sdk.init`), the `SENTRY_DEBUG` environment variable, or via a specific logger configuration for `sentry_sdk.errors`. With 3793084, a custom root logger configuration would also cause SDK logs to be emitted.

The issue 3793084 was meant to fix (#3944) appears to have been caused by user error, not a bug in the SDK.

Fixes #4266
@szokeasaurusrex szokeasaurusrex marked this as a duplicate of #4285 Apr 14, 2025
@szokeasaurusrex szokeasaurusrex marked this as a duplicate of #4295 Apr 15, 2025
@stephanie-anderson stephanie-anderson added the Python SDK label Apr 25, 2025 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants