#Sentry.logger import error
1 messages · Page 1 of 1 (latest)
Hi @steel gulch. I'm happy to dig into this for you! I'll check my internal sources for answers to your question! :wave:
The correct way to use Sentry's logger in the Python SDK is to import it from the SDK as follows:
from sentry_sdk import logger as sentry_logger
You should not use import sentry.logger or import sentry_sdk.logger as a module, since logger is not a standalone module but an attribute of the sentry_sdk package. Attempting to import it as a module will result in an import error.
Here's an example of the correct usage:
from sentry_sdk import logger as sentry_logger
sentry_logger.info('Updated global cache')
sentry_logger.error('Failed to process payment. Order: {order_id}. Amount: {amount}', order_id="or_2342", amount=99.99)
Make sure you have initialized the SDK with the experimental logs feature enabled:
import sentry_sdk
sentry_sdk.init(
dsn="<https://[email protected]/0",>
_experiments={
"enable_logs": True,
},
)
If you follow this pattern and are using Sentry Python SDK version 2.28.0 or above, it should work as expected. If you are still seeing errors, please ensure your SDK version is up to date and that you are not trying to import logger as a module. For more details, see the official Sentry documentation on Python logs setup.