Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a processor to support stack_info #87

Open
PeterJCLaw opened this issue Sep 15, 2022 · 2 comments · May be fixed by #158
Open

Provide a processor to support stack_info #87

PeterJCLaw opened this issue Sep 15, 2022 · 2 comments · May be fixed by #158

Comments

@PeterJCLaw
Copy link

PeterJCLaw commented Sep 15, 2022

The standard library supports passing stack_info as a kwarg to log lines which aren't exceptions but you still want a stack trace, which can be useful for logging usages of a function. (The docs are part of Logger.debug's docs)

structlog also supports this through its StackInfoRenderer, however that renders to a string which then doesn't work well in Sentry.

It would be great if this library contained a similar processor which emitted the data in the format which Sentry expects.
sentry_sdk.utlis.current_stacktrace looks like it might be useful for this, though I'm not sure how you'd get the data into the right place on the event object to ensure it shows up as a full stack (rather than as data) in the UI.

Broadly what I'm trying to achieve here is like Sentry's attach_stacktrace client option, but available on a per-log basis rather than a setting on the client as a whole.

@PeterJCLaw
Copy link
Author

Cross linking in case this ends up just being supported in Sentry's SDK: getsentry/sentry-python#1204 is for a similar feature on their side.

@devonwarren
Copy link

devonwarren commented Jul 2, 2024

I spent a bunch of time on this but was able to get stack traces set via changing the event_from_exception function call in the _get_event_and_hint function to the following:

event, hint = {}, {}
with capture_internal_exceptions():
    event["threads"] = {
        "values": [
            {
                "stacktrace": current_stacktrace(
                    include_local_variables=options["include_local_variables"],
                    max_value_length=options["max_value_length"],
                ),
                "crashed": False,
                "current": True,
            }
        ]
    }

It seems the issue is sentry trying to work around some oddity in celery so now this has to work around that - https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/logging.py#L198

It's still odd that you can't specifically tell the the event_from_exception to include the stack info in the sentry-sdk library. Definitely seems like a deficiency there but assuming we have a better chance of merging here to work around it

I'm thinking this should be an option in the SentryProcessor init or detected automatically if stack_info is set to true in the event_dict. Any thoughts on that? I can try to get a PR out for that if interested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants