pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://logfire.pydantic.dev/docs/
MIT License
1.96k stars 59 forks source link

Support all OTEL keys for instrument suppression #197

Closed jlondonobo closed 4 months ago

jlondonobo commented 4 months ago

Add support for all OTEL keys for instrument suppression.

This PR adds support for the following keys:

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:loudspeaker: Thoughts on this report? Let us know!

alexmojaki commented 4 months ago

In https://pydanticlogfire.slack.com/archives/C06EDRBSAH3/p1714658053546979 a user essentially requested the suppress_instrumentation function, so I've made it public here.

This PR fixes https://github.com/pydantic/logfire/issues/135 in the sense that those particular urllib3 logs don't get sent to logfire. They are now logged by the fallback handler of LogfireLoggingHandler which logs to stderr by default. After this, I want to add a snippet like the following to the docs showing how to filter those logs if the noise in the console is still annoying:

import logging
import time
from logging import DEBUG, basicConfig, getLogger

from logfire.integrations.logging import LogfireLoggingHandler

logfire_handler = LogfireLoggingHandler()

# Don't write to stderr the urllib3 debug logs created while exporting traces
urllib3_filter = logging.Filter('urllib3')
logfire_handler.fallback.addFilter(lambda record: not urllib3_filter.filter(record))

basicConfig(handlers=[logfire_handler], level=DEBUG)

logger = getLogger(__name__)

for _ in range(1000):
    logger.info('log')
    time.sleep(0.6)
alexmojaki commented 4 months ago

Thanks @jlondonobo for your help, your changes were pretty much exactly what was needed!