-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Document Java Source Context #7086
Changes from 20 commits
20f1613
3f93bdc
0ac2058
d1ab715
29f4a42
8f9c20c
e63ed82
5b87a3f
7fb27f5
1578a29
01299b9
28d7bc8
f6d5622
fb76e88
fe25d9e
b831b93
f02689f
ef276b1
4bad977
a3ac5a2
b4e9885
2d954a3
1a6b888
f202c5c
845c57d
4abfc83
bcea7ae
893a78c
38eada1
6645a44
e1d2bd9
2be1b8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd like to proceed with approving and merging these changes, but I'd like us to consider updating these pages to work like the JS source maps pages today
Ideally this should make the page easier to consume and things like UUIDs for debug files should be hidden away I will take a crack at it later if I get time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be awesome if we can split up the source code context in a product's page (explaining the feature but platform agnostic) so that platforms can just link to when they offer support. This is tracked here https://www.notion.so/sentry/x-Source-Context-adoption-83a34f599c9745498aa20849ac44fdc8?pvs=4#43bdef3f5b2142e59b180fafae6e3bf8 Then the source code context could add includes (with code snippets) on how to install per platform, this makes the content/feature more discoverable and easy to add support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that restructuring would help these docs a lot! I really like the idea of splitting the source code context into a product page. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,298 @@ | ||||||
If you want to see your source code as part of stack traces in Sentry, you can enable the Source Context feature by adding | ||||||
one of our build tool plugins to your project. You may also manually upload source bundle by using [sentry-cli](/product/cli/dif/#jvm-source-bundles). | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
It works the same either way. A (random) UUID will be or has to be generated and placed into the `sentry-debug-meta.properties`. The same UUID has to be used to upload the source bundle file. Whenever an error is sent to Sentry, this UUID will be sent along, allowing | ||||||
the Sentry server to look up source code in the source bundle with matching ID. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
![Java Source Context](java-source-context.png) | ||||||
|
||||||
All of the following methods require `org`, `project` and an `authToken`. | ||||||
|
||||||
You can create an auth token by visiting the | ||||||
[auth token user settings page](https://sentry.io/settings/account/api/auth-tokens/). | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
The auth token requires either a `project:releases` or `project:write` Scope. | ||||||
|
||||||
<PlatformSection supported={["android"]}> | ||||||
|
||||||
Source Context also works with [ProGuard](/platforms/android/proguard/). | ||||||
|
||||||
</PlatformSection> | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## Known Limitations | ||||||
|
||||||
- Multiple files with same name but different extension will lead to undefined behaviour | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- e.g. MainActivity.java and MainActivity.kt will both be renamed to MainActivity.jvm | ||||||
- Package declaration and file tree must match for source lookup to work | ||||||
- e.g. a class io.sentry.sample.MainActivity.java has to be stored in io/sentry/sample | ||||||
|
||||||
<PlatformSection supported={["android"]}> | ||||||
|
||||||
- Kotlin files may contain multiple classes but this feature may be broken by code obfuscation tools like ProGuard or R8 | ||||||
- For AGP < 7.4 we don't add generated sources yet | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
</PlatformSection> | ||||||
|
||||||
## Gradle Plugin | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
You can add the plugin to your project by adding the following lines and making sure the `assemble` task is executed: | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
<PlatformSection supported={["android"]}> | ||||||
|
||||||
```groovy | ||||||
buildscript { | ||||||
repositories { | ||||||
mavenCentral() | ||||||
} | ||||||
} | ||||||
|
||||||
plugins { | ||||||
id "io.sentry.android.gradle" version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.9.0') }}" | ||||||
} | ||||||
|
||||||
sentry { | ||||||
// Enables more detailed log output, e.g. for sentry-cli. | ||||||
// | ||||||
// Default is false. | ||||||
debug = true | ||||||
|
||||||
// Generates a source bundle and uploads your source code to Sentry. | ||||||
// This enables source context, allowing you to see your source | ||||||
// code as part of your stack traces in Sentry. | ||||||
// | ||||||
// Default is disabled. | ||||||
includeSourceContext = true | ||||||
|
||||||
// Includes additional source directories into the source bundle. | ||||||
// These directories are resolved relative to the project directory. | ||||||
additionalSourceDirsForSourceContext = ["mysrc/java", "other-source-dir/main/kotlin"] | ||||||
|
||||||
org = "___ORG_SLUG___" | ||||||
projectName = "___PROJECT_SLUG___" | ||||||
authToken = "your-sentry-auth-token" | ||||||
} | ||||||
``` | ||||||
|
||||||
```kotlin | ||||||
buildscript { | ||||||
repositories { | ||||||
mavenCentral() | ||||||
} | ||||||
} | ||||||
|
||||||
plugins { | ||||||
id("io.sentry.android.gradle") version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.9.0') }}" | ||||||
} | ||||||
|
||||||
sentry { | ||||||
// Enables more detailed log output, e.g. for sentry-cli. | ||||||
// | ||||||
// Default is false. | ||||||
debug.set(true) | ||||||
|
||||||
// Generates a source bundle and uploads your source code to Sentry. | ||||||
// This enables source context, allowing you to see your source | ||||||
// code as part of your stack traces in Sentry. | ||||||
// | ||||||
// Default is disabled. | ||||||
includeSourceContext.set(true) | ||||||
|
||||||
// Includes additional source directories into the source bundle. | ||||||
// These directories are resolved relative to the project directory. | ||||||
additionalSourceDirsForSourceContext.set(setOf("mysrc/java", "other-source-dir/main/kotlin")) | ||||||
|
||||||
org.set("___ORG_SLUG___") | ||||||
projectName.set("___PROJECT_SLUG___") | ||||||
authToken.set("your-sentry-auth-token") | ||||||
} | ||||||
``` | ||||||
|
||||||
</PlatformSection> | ||||||
|
||||||
<PlatformSection notSupported={["android"]}> | ||||||
|
||||||
```groovy | ||||||
buildscript { | ||||||
repositories { | ||||||
mavenCentral() | ||||||
} | ||||||
} | ||||||
|
||||||
plugins { | ||||||
id "io.sentry.jvm.gradle" version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.9.0') }}" | ||||||
} | ||||||
|
||||||
sentry { | ||||||
// Enables more detailed log output, e.g. for sentry-cli. | ||||||
// | ||||||
// Default is false. | ||||||
debug = true | ||||||
|
||||||
// Generates a source bundle and uploads your source code to Sentry. | ||||||
// This enables source context, allowing you to see your source | ||||||
// code as part of your stack traces in Sentry. | ||||||
// | ||||||
// Default is disabled. | ||||||
includeSourceContext = true | ||||||
|
||||||
// Includes additional source directories into the source bundle. | ||||||
// These directories are resolved relative to the project directory. | ||||||
additionalSourceDirsForSourceContext = ["mysrc/java", "other-source-dir/main/kotlin"] | ||||||
|
||||||
org = "___ORG_SLUG___" | ||||||
projectName = "___PROJECT_SLUG___" | ||||||
authToken = "your-sentry-auth-token" | ||||||
} | ||||||
``` | ||||||
|
||||||
```kotlin | ||||||
buildscript { | ||||||
repositories { | ||||||
mavenCentral() | ||||||
} | ||||||
} | ||||||
|
||||||
plugins { | ||||||
id("io.sentry.jvm.gradle") version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.9.0') }}" | ||||||
} | ||||||
|
||||||
sentry { | ||||||
// Enables more detailed log output, e.g. for sentry-cli. | ||||||
// | ||||||
// Default is false. | ||||||
debug.set(true) | ||||||
|
||||||
// Generates a source bundle and uploads your source code to Sentry. | ||||||
// This enables source context, allowing you to see your source | ||||||
// code as part of your stack traces in Sentry. | ||||||
// | ||||||
// Default is disabled. | ||||||
includeSourceContext.set(true) | ||||||
|
||||||
// Includes additional source directories into the source bundle. | ||||||
// These directories are resolved relative to the project directory. | ||||||
additionalSourceDirsForSourceContext.set(setOf("mysrc/java", "other-source-dir/main/kotlin")) | ||||||
|
||||||
org.set("___ORG_SLUG___") | ||||||
projectName.set("___PROJECT_SLUG___") | ||||||
authToken.set("your-sentry-auth-token") | ||||||
} | ||||||
``` | ||||||
|
||||||
</PlatformSection> | ||||||
|
||||||
<PlatformSection notSupported={["android"]}> | ||||||
|
||||||
## Maven Plugin | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
We also offer a [Sentry Maven Plugin](https://github.com/getsentry/sentry-maven-plugin). | ||||||
|
||||||
You can add the plugin to your `pom.xml` by adding the following lines: | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
```xml | ||||||
<build> | ||||||
<plugins> | ||||||
<plugin> | ||||||
<groupId>io.sentry</groupId> | ||||||
<artifactId>sentry-maven-plugin</artifactId> | ||||||
<version>{{@inject packages.version('sentry.java.mavenplugin', '0.0.2') }}</version> | ||||||
<configuration> | ||||||
<!-- for showing output of sentry-cli --> | ||||||
<debugSentryCli>true</debugSentryCli> | ||||||
|
||||||
<!-- download the latest sentry-cli and provide path to it here --> | ||||||
<!-- download it here: https://github.com/getsentry/sentry-cli/releases --> | ||||||
<!-- minimum required version is 2.17.3 --> | ||||||
<sentryCliExecutablePath>/path/to/sentry-cli</sentryCliExecutablePath> | ||||||
|
||||||
<org>___ORG_SLUG___</org> | ||||||
|
||||||
<project>___PROJECT_SLUG___</project> | ||||||
|
||||||
<!-- in case you're self hosting, provide the URL here --> | ||||||
<!--<url>http://localhost:8000/</url>--> | ||||||
|
||||||
<!-- provide your auth token via SENTRY_AUTH_TOKEN environment variable --> | ||||||
<!-- you can find it in Sentry UI: Settings > Account > API > Auth Tokens --> | ||||||
<authToken>${env.SENTRY_AUTH_TOKEN}</authToken> | ||||||
</configuration> | ||||||
<executions> | ||||||
<execution> | ||||||
<phase>install</phase> | ||||||
<goals> | ||||||
<goal>uploadSourceBundle</goal> | ||||||
</goals> | ||||||
</execution> | ||||||
</executions> | ||||||
</plugin> | ||||||
</plugins> | ||||||
... | ||||||
</build> | ||||||
``` | ||||||
|
||||||
For now you have to manually download `sentry-cli` for your required architecture and point | ||||||
the Maven Plugin to it using `sentryCliExecutablePath`. | ||||||
You can get the latest release from the following URL: | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
``` | ||||||
https://github.com/getsentry/sentry-cli/releases/tag/{{@inject apps.version('sentry-cli', '2.17.3') }} | ||||||
``` | ||||||
|
||||||
</PlatformSection> | ||||||
|
||||||
## Manually Uploading Source Context | ||||||
|
||||||
If your build tool of choice isn't supported yet or there are other reasonsfor not | ||||||
using our Gradle or Maven plugins, you can manually create and upload source bundles. | ||||||
|
||||||
The `sentry-cli` commands allow you to supply `--org` and `--project` as well as providing the auth token by setting the `SENTRY_AUTH_TOKEN` environment variable. | ||||||
Another option is to use `.sentryclirc` or a `.properties` file which you can link using the `SENTRY_PROPERTIES` environment variable. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
### Creating the Source Bundle | ||||||
|
||||||
First you have to create the source bundle containing your source files. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
``` | ||||||
sentry-cli debug-files bundle-jvm --output path/to/store/bundle --debug-id A_VALID_UUID path/to/source-code | ||||||
``` | ||||||
|
||||||
### Uploading the Source Bundle | ||||||
|
||||||
Next you can upload that source bundle to Sentry. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
``` | ||||||
sentry-cli debug-files upload --type jvm path/to/bundle | ||||||
``` | ||||||
|
||||||
### Configuring the SDK | ||||||
|
||||||
You have to tell the SDK which source bundle it should use for providing Source Context via one of the following options. | ||||||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
#### `sentry-debug-meta.properties` | ||||||
|
||||||
Add a `sentry-debug-meta.properties` to your application resources at build time which will be picked up automatically by the SDK. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
||||||
```properties | ||||||
io.sentry.bundle-ids=A_VALID_UUID | ||||||
``` | ||||||
|
||||||
#### `sentry.properties` | ||||||
|
||||||
```properties | ||||||
bundle-ids=A_VALID_UUID | ||||||
``` | ||||||
|
||||||
<PlatformSection supported={["java.spring"]}> | ||||||
|
||||||
#### `application.properties` | ||||||
|
||||||
```properties | ||||||
sentry.bundle-ids=A_VALID_UUID` | ||||||
``` | ||||||
|
||||||
</PlatformSection> | ||||||
|
||||||
#### `SentryOptions` | ||||||
|
||||||
```Java | ||||||
options.addBundleId("A_VALID_UUID"); | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if this should live in one place in java docs and from product docs we could link there, or it could be an include that we add instead
again I think this could be in a restructuring PR to not delay this