sentry-go icon indicating copy to clipboard operation
sentry-go copied to clipboard

Server-side source context

Open rhcarvalho opened this issue 5 years ago • 6 comments

Add support for serve-side source context using source bundles. https://docs.sentry.io/workflow/debug-files/#source-context

Overview

At the moment, the Contextify Frames Integration in the SDK automatically grabs context lines when those are available nearby a running binary.

We document how this can be used when deploying to a serverless platform.

While that integration can be used in certain contexts, it won't help when you (have to) distribute binaries without source code available.

The solution is to add source context on the Sentry server, and that is done by uploading source bundles after building a program.


Development notes

Creating source bundles

Use sentry-cli to generate a zip archive with source files and a manifest:

  1. ~~Bump symbolic dependency in Cargo.toml to at least https://github.com/getsentry/symbolic/commit/8f9a01756e48dcbba2e42917a064f495d74058b7~~ (edit: not needed anymore, bumped upstream).

  2. Run

    cargo run -- difutil bundle-sources /path/to/binary...
    
  3. Inspect manifest.json in source archive

    unzip -p /path/to/file.src.zip manifest.json | jq -C | less
    

    code_id is the gnu.build-id. debug_id is a transformation from code_id if it exists, or otherwise a hash of the text section.

    See https://github.com/getsentry/symbolic/blob/@{2020.03.03}/debuginfo/src/elf.rs#L92.


References:

  • https://docs.sentry.io/development/sdk-dev/event-payloads/debugmeta/
  • https://github.com/getsentry/symbolic/blob/@{2020.03.03}/debuginfo/src/elf.rs#L92
  • https://github.com/gimli-rs/findshlibs

TODO

On the SDK, we need:

  • [ ] Send debug_id in the event payload along with other required files in the images attribute. See https://docs.sentry.io/development/sdk-dev/event-payloads/debugmeta/.
    • [ ] Linux support
    • [ ] Windows support
    • [ ] macOS support

rhcarvalho avatar Mar 04 '20 13:03 rhcarvalho

This feature would be extremely helpful, especially if /go/pk/mod was supported. 🚀

iagomls avatar Mar 30 '20 05:03 iagomls

Is this work scheduled / is there going to be some other way to get the source context in stacktraces without shipping the source alongside built binaries? We love Sentry and love that feature, but we don't want to start shipping source code in our containers that hold our golang web servers just to get slightly more usable stacktraces. I know that "Stack trace linking" via Github integration is now in beta, and that for Javascript there's a way to upload source maps as part of releases, and when I squint that looks like the same thing that we'd want to do here, but whatever the implementation method I'd really like to see the surrounding code inside stacktraces on error pages.

peterldowns avatar Jan 21 '21 22:01 peterldowns

Sharing here that another viable way to get source code context in stack traces is to use Sentry's GitHub/Gitlab integrations:

https://docs.sentry.io/product/integrations/github/#stack-trace-linking https://docs.sentry.io/product/integrations/gitlab/#stack-trace-linking

rhcarvalho avatar Apr 07 '21 13:04 rhcarvalho

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Dec 07 '22 09:12 github-actions[bot]

Hey folks, is #44525 something you could take on as part of this initiative? I'm happy to guide

armenzg avatar Feb 16 '23 14:02 armenzg

@armenzg I assume we could do something with our GitHub integration.

Sample error from our profiling ingestion service https://sentry.sentry.io/issues/3908326163/ (internal link). All paths are preserved in the stack trace, so we could fetch the source context with that from a repo.

cleptric avatar Feb 16 '23 14:02 cleptric