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

Support for Source Context

Open bruno-garcia opened this issue 4 years ago • 2 comments

There are different approaches we can take to add support for source context:

  1. It's possible to embed sources in the pdb. Couldn't find docs but general GitHub issues. Seems the property is <Embed>true</Embed>. With this approach we can document this on docs.sentry.io and suggest users opt-in. And read the source when capturing the SDK (opt-in at first, with the goal of making it opt-out). With the source embedded, we can read it at runtime (see this commit: https://github.com/getsentry/sentry-dotnet/commit/518ab6464418cb1912ae4adad08262c440f4da42) and send it with the event.

  2. Additional approach is to use Source Bundles and corresponding docs. This requires changes on Sentry CLI and the backend.

  3. Yet another way is to support sourcelink on the server by fetching the external VCS repository to get the relevant line numbers. Related: https://github.com/getsentry/sentry-dotnet/issues/400 It also requires changes on the backend but can help us show source context for external, .NET libraries which commonly use sourcelink (.NET itself uses it).

Related:

https://github.com/getsentry/sentry-dart/issues/132

https://github.com/getsentry/sentry-java/issues/633

bruno-garcia avatar Dec 10 '20 18:12 bruno-garcia

We could use mvid to be the identifier of the source bundle. https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/ https://getsentry.github.io/symbolicator/advanced/source-bundles/

@Swatinem said:

what it expects is obviously a stack trace (with a bunch of instruction_addr which might as well be completely bogus), and a debug_meta.images that have a UUID that we use for lookup

bruno-garcia avatar Jun 24 '22 13:06 bruno-garcia

@ashwoods lets make this a proper initiative so we can design this properly. I don’t really want people to "fake" native-looking events just to get source context ;-)

Swatinem avatar Jun 24 '22 14:06 Swatinem

Adding <EmbedAllSources>true</EmbedAllSources> to the project includes sources in the generated PDB. I've uploaded that to sentry & tested with the customized console app sample but there are no sources displayed on the sentry.io event.

  • tested on the branch that supports debug image info #2050
  • full build: console-sample-pdb-with-sources.zip
  • event: https://sentry.io/organizations/sentry-sdks/issues/3744054261/events/9288d1b59752485882da368adc059443/?project=5428537

I guess there's something that need to change on the server @Swatinem ?

vaind avatar Nov 30 '22 16:11 vaind

Well, yes :-)

Sources embedded in the Portable PDB are not implemented at all. We would need to add support for that on the server side.

I don’t think you can create a sentry "source bundle" directly from portable pdb files currently.

Using the source embedded in the Portable PDB might be interesting, then you wouldn’t need a separate file either.

Swatinem avatar Nov 30 '22 16:11 Swatinem

Mind creating an issue in the appropriate repo so that it's tracked and eventually prioritized? I guess you'd be able to best describe what's needed.

vaind avatar Nov 30 '22 16:11 vaind

Here it is: https://github.com/getsentry/symbolic/issues/725 I will defer prioritization to @ashwoods

Swatinem avatar Dec 01 '22 09:12 Swatinem

The second approach, i.e. sentry-cli upload-dif --include-sources is implemented by https://github.com/getsentry/symbolic/pull/729 and will be available once that makes its way to a sentry-cli release.

Tested manually on a local copy & the #2050 branch - works fine: https://sentry.io/organizations/sentry-sdks/issues/3744250864/events/9507e239323340909c12049cc24e7cf3/?project=5428537

image

vaind avatar Dec 06 '22 09:12 vaind

Symbolicator PR: https://github.com/getsentry/symbolicator/pull/996 - deployed to sentry.io on 2023-30-01 Sentry CLI PR: https://github.com/getsentry/sentry-cli/pull/1440 ... released in SentryCLI v2.12

vaind avatar Jan 29 '23 12:01 vaind

Both options work now on sentry.io

  • --include-sources flag to sentry-cli v 2.12.0 (@mattjohnsonpint maybe a follow up would be to provide this option for users of the msbuild built-in sentry-cli?) - https://sentry.io/organizations/sentry-sdks/issues/3744054261/events/e9ec13b402aa4834baea0fe3958a544a/?project=5428537
  • or <EmbedAllSources>true</EmbedAllSources> in the project config - https://sentry.io/organizations/sentry-sdks/issues/3744250864/events/8860bd526ff44a37bca48e2562068c1b/?project=5428537

vaind avatar Jan 30 '23 16:01 vaind