Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

I need to have log of each execution #3462

Unanswered
RandomBrown asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 4 comments 1 reply

Comment options

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?

You must be logged in to vote
1 reply
Comment options

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?

Comment options

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.

msedge_4M7SdedVhz

msedge_b7rnjObbSj

msedge_9HJ2ca4UWe

Any other ideas, what could I be doing wrong?

You must be logged in to vote
0 replies
Comment options

Hi,

I have created a new project just as indicated @antonpirker , with this code:

image

And I use a new project in sentry.io for this test.

But I get errors:

image

image

And I receive e-mail notification of the error:

image

How can I solve this?

Thanks!!!

You must be logged in to vote
0 replies
Comment options

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?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /