Skip to content

Unable to add a breadcrumb from actix-web middleware #624

Closed
@ferologics

Description

@ferologics

Environment

actix-web 4.4.0
actix-web-lab 0.19.1
sentry-tracing 0.31.7
sentry-actix 0.31.6

Steps to Reproduce

  1. intercept incoming request with actix-web-lab middleware
  2. call sentry::add_breadcrumb(incoming_request) before next.call(req).await
  3. server executes logic ... error is thrown
  4. use tracing::error!(...) to capture error message
  5. sentry reported error has no incoming request breadcrumb

Expected Result

Breadcrumb attached with the reported error.

Actual Result

Breadcrumb is missing.

Workaround

pass the incoming_request breadcrumb in actix request extensions and sentry::add_breadcrumb from within the request execution context ([middleware -> [ request ] ])

Notes

I suspect that the middleware uses a different Hub from the request:

Because actix is generally working with non sendable objects and highly concurrent this middleware creates a new hub per request. As a result many of the sentry integrations such as breadcrumbs do not work unless you bind the actix hub
(source)

We tried binding the current Hub inside middleware but it raises an issue with the ServiceRequest which is not Send.

Is there a way to attach this breadcrumb directly from middleware?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions