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

Document Java Source Context #7086

Merged
merged 32 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
20f1613
Document Java Source Context
adinauer Jun 5, 2023
3f93bdc
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
0ac2058
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
d1ab715
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
29f4a42
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
8f9c20c
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
e63ed82
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
5b87a3f
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
7fb27f5
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
1578a29
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
01299b9
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
28d7bc8
style(lint): Auto commit lint changes
getsantry[bot] Jun 5, 2023
f6d5622
Merge branch 'master' into feat/java-source-context
adinauer Jun 5, 2023
fb76e88
Replace link with absolute one
adinauer Jun 5, 2023
fe25d9e
Fix more links
adinauer Jun 5, 2023
b831b93
Replace project with projectName in gradle sentry config block
adinauer Jun 6, 2023
f02689f
Changes according to PR review
adinauer Jun 6, 2023
ef276b1
feat(Android): Integrate source context into Android Gradle overview …
markushi Jun 6, 2023
4bad977
Update src/wizard/android/index.md
adinauer Jun 6, 2023
a3ac5a2
Replace 3.8.1 of SAGP with 3.9.0
adinauer Jun 6, 2023
b4e9885
Update src/docs/product/cli/dif.mdx
adinauer Jun 7, 2023
2d954a3
Update src/docs/product/cli/dif.mdx
adinauer Jun 7, 2023
1a6b888
style(lint): Auto commit lint changes
getsantry[bot] Jun 7, 2023
f202c5c
style(lint): Auto commit lint changes
getsantry[bot] Jun 7, 2023
845c57d
Apply suggestions from code review
adinauer Jun 7, 2023
4abfc83
style(lint): Auto commit lint changes
getsantry[bot] Jun 7, 2023
bcea7ae
Apply suggestions from code review
adinauer Jun 7, 2023
893a78c
Code Review change
adinauer Jun 7, 2023
38eada1
Clarify includeSourceContext plugin option
markushi Jun 7, 2023
6645a44
Only show assemble task note for non android
adinauer Jun 7, 2023
e1d2bd9
Update src/platforms/java/common/gradle.mdx
adinauer Jun 7, 2023
2be1b8e
style(lint): Auto commit lint changes
getsantry[bot] Jun 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/docs/product/cli/dif.mdx
Copy link
Member

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

Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,48 @@ UUIDs into a properties file.
`--require-one`

: Requires at least one file to upload or the command will error.

## JVM Source Bundles

`sentry-cli` can be used to upload source files for any JVM based language like
Java or Kotlin to Sentry; however, in most situations, you would use one of our
build tool plugins to do that ([Android](/platforms/android/source-context/)
[Java](/platforms/java/source-context/)). Nevertheless, there may be situations
where you would upload source bundle files manually.
adinauer marked this conversation as resolved.
Show resolved Hide resolved

<Note>

You need to specify the organization and project you are working with
because source bundle files work on projects. For more information about this refer to
[Working with Projects](/product/cli/configuration/#sentry-cli-working-with-projects).
adinauer marked this conversation as resolved.
Show resolved Hide resolved

</Note>

### Creating a Source Bundle

The `debug-files bundle-jvm` command can be used to create a source bundle for a
source directory.
adinauer marked this conversation as resolved.
Show resolved Hide resolved

```bash
sentry-cli debug-files bundle-jvm \
--output some/dir \
--debug-id A_VALID_UUID \
path/to/source/dir
```

Since the Java/Android SDK needs to send the UUID of the source bundle, you need to
provide it. More details can be found in the [Java SDK docs](/platforms/java/source-context/#manually-uploading-source-context) and [Android SDK Docs](/platforms/android/source-context/#manually-uploading-source-context)
adinauer marked this conversation as resolved.
Show resolved Hide resolved

### Uploading a Source Bundle

The `debug-files upload` command allows you to upload the previously created source
bundle to Sentry.
adinauer marked this conversation as resolved.
Show resolved Hide resolved

```bash
sentry-cli debug-files upload \
--type jvm \
output/path/of/bundle-jvm/command
```

After the upload, Sentry will attach Source Context to future events.
To make sure that it worked, you can check _Project Settings > Debug Files_ and see if the uploaded source bundle files are listed.
adinauer marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
298 changes: 298 additions & 0 deletions src/platform-includes/source-context/java.mdx
Copy link
Member

Choose a reason for hiding this comment

The 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

  • meaning a little less text
  • similar image to show before and after
  • set up sub pages instead of lists of each option for plugin config

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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.8.1') }}"
}

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.8.1') }}"
}

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.8.1') }}"
}

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.8.1') }}"
}

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add a `sentry-debug-meta.properties` to your application resources at build time which will be picked up automatically by the SDK.
Add a `sentry-debug-meta.properties` variable to your application resources at build time, which will be picked up automatically by the SDK:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sentry-debug-meta.properties is a file. Will update differently.


```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");
```
7 changes: 7 additions & 0 deletions src/platforms/android/source-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Source Context
sidebar_order: 110
description: "Learn about showing your source code as part of stack traces."
---

<PlatformContent includePath="source-context" />
Loading