question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SentryAsgiMiddleware doesn't set the "message" field in FastAPI

See original GitHub issue

I don’ know why exactly, but SentryAsgiMiddleware doesn’t set the “message” field in FastAPI. In result, all events have title <no message value> in issues feed. I managed to fix problem through this code:

def before_send(event, hint):
    error_name = event['exception']['values'][0]['type']
    event.update({"message": error_name})
    return event

All parts except this one are working great (so far) and I very appreciate this library, but I don’ think this is expected behavior.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Sep 11, 2020

Right but you have logentry in there, that is supposed to be shown instead. Sentry 10 deprecates message in favor of logentry. If you want the Sentry 10 behavior I suggest copying event['logentry']['message'] into event['message'] (but you can do whatever you want to set the issue title to what you prefer)

We support old SDKs in newer Sentry, but not newer SDKs in older Sentry. To enable support we would have to send the message attribute as well as logentry. I think we could add something to the SDK to enable support for older Sentries, but it would be a kind of option or an integration of some sort and definetly community maintained.

I recommend updating to Sentry 9 at least.

0reactions
kozhushmancommented, Sep 11, 2020

Oh, I see! Thanks for the clarification! I can’t influence the Sentry update, but now i know what is happening 😃 In my case

copying event[‘logentry’][‘message’] into event[‘message’]

won’t work, because it’s just saying "Exception in ASGI application\n" instead of real exception

Read more comments on GitHub >

github_iconTop Results From Across the Web

tiangolo/fastapi - Gitter
Trying to enable the ASGI middleware.. and im not understanding the problem. import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware ...
Read more >
Advanced Middleware - FastAPI
A middleware doesn't have to be made for FastAPI or Starlette to work, as long as it follows the ASGI spec. In general,...
Read more >
Integration for FastAPI · Issue #829 · getsentry/sentry-python
FastAPI is just Starlette which is just ASGI. ... sure that the data you set within a request handler does not persist between...
Read more >
Using FastAPI & Pydantic, how do I define an Optional field ...
class ErrorReportRequest(BaseModel): sender: Optional[str] = Field(None, description="Who sends the error message.
Read more >
ASGI - Sentry Documentation
Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found