-
Notifications
You must be signed in to change notification settings - Fork 583
I need to have log of each execution #3462
-
Hi,
I use the logging library to log info messages for an application, and I generate a log file for each execution.
However, I want to have visibility of these messages from sentry.io, and be able to visualize them for each execution.
To achieve this, I am currently using the integration between sentry.io and logging, with a configuration of sentry_sdk.init as follows:
integrations=[LoggingIntegration(level=logging.INFO, event_level=logging.ERROR)]
And I manually generate an info event in sentry.io to provide observability at the end of execution, allowing me to see all the breadcrumbs:
sentry_sdk.capture_message("[End] ### End of Execution ###", level="info")
The result is as expected, except that sentry.io considers this level="info" event as an error. For example, when I check the performance option, I see a 100% failure rate due to these messages.
Can I approach this from a different perspective, so that I still have this observability with each execution of the application, but without sentry.io considering it an error?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments 1 reply
-
Hey @RandomBrown !
I tried this now with this example code:
import os import sentry_sdk from sentry_sdk.integrations.logging import LoggingIntegration import logging logging.basicConfig(level=logging.INFO) sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], release="42.42.42", enable_tracing=True, debug=True, integrations=[ LoggingIntegration(level=logging.INFO, event_level=logging.ERROR) ], ) with sentry_sdk.start_transaction(op="function", name="plain-python-example-new"): logging.info("Hello, World! 1") logging.info("Hello, World! 2") logging.info("Hello, World! 3") logging.info("Hello, World! 4") logging.info("Hello, World! 5") sentry_sdk.capture_message("[End] ### End of Execution ###", level="info")
And I get the breadcrumbs in the message (as you described):
Screenshot 2024年09月04日 at 13 23 49
(notice the transaction name is plain-python-example-new.
When I go to the performance section I do not get an error rate of 100%:
Screenshot 2024年09月04日 at 13 26 04
So I guess this should work as you expect. Did I got something wrong?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey @antonpirker !
I can't seem to replicate that behaviour. As I indicated in my reply of Sep 22, it generates failure rate increments. Surely I must be doing something wrong, any ideas?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @antonpirker :
Thanks for your comment and proposed line of work. This is the path I am using in my code.
I set the logger level to "info", and log events using "logger.info".
Finally I force the saving via: sentry_sdk.capture_message("[Fin] ### Fin de Ejecucion ###", level="info")
But the result is that I get a failure rate of 100% in Performance. I attach some screenshots.
Any other ideas, what could I be doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi,
I have created a new project just as indicated @antonpirker , with this code:
And I use a new project in sentry.io for this test.
But I get errors:
And I receive e-mail notification of the error:
How can I solve this?
Thanks!!!
Beta Was this translation helpful? Give feedback.
All reactions
-
Finally, I managed to fix it. I’ll explain how I did it in case it’s of interest to anyone. The mistake I was making was logging informational messages using "capture_message," which always creates an event in Sentry. These events were affecting the performance metrics.
I replaced it with transactions using "start_transaction" instead of "capture_message."
My problem now is that for a specific execution on a certain date and time that didn’t log any errors, I want to see the information I recorded, using the integration between sentry.io and logging. How can I view it?
Beta Was this translation helpful? Give feedback.