Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/platform-includes/capture-error/kotlin-multiplatform.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

Sentry.captureException(exception)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

Sentry.captureMessage("Something went wrong")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.dsn = "___PUBLIC_DSN___"
options.release = "[email protected]+1"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Kotlin Multiplatform SDK uses native SDKs to automatically store Sentry events on the device's disk before shutdown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
To add an attachment, either add it to the scope or pass it to any of the `capture` methods.

### Passing Attachments to Capture

You can pass attachments to any of the `capture` methods. For example, when capturing an exception:

```kotlin
import io.sentry.kotlin.multiplatform.Attachment
import io.sentry.kotlin.multiplatform.Sentry

val fileAttachment = Attachment("your/path/file.log")

Sentry.captureException(IllegalStateException()) { scope ->
scope.addAttachment(fileAttachment)
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.attachScreenshot = true
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Note>

Currently only available on iOS and Android.

</Note>

```kotlin
import io.sentry.kotlin.multiplatform.sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.dsn = "___PUBLIC_DSN___"
options.attachViewHierarchy = true
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.Attachment

val attachment = Attachment(bytes, "file.log")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.Attachment

val attachment = Attachment("your/path/file.log")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.maxAttachmentSize = 5 * 1024 * 1024 // 5 MiB
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.Attachment

val fileAttachment = Attachment("your/path/file.log")

// Global Scope
Sentry.configureScope { scope ->
scope.addAttachment(fileAttachment)
}

// Clear all attachments in the global Scope
Sentry.configureScope { scope ->
scope.clearAttachments()
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.beforeBreadcrumb = { breadcrumb ->
if ("a.spammy.Logger" == breadcrumb.category) {
null
} else {
breadcrumb
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.SentryLevel
import io.sentry.kotlin.multiplatform.protocol.Breadcrumb

val breadcrumb = Breadcrumb().apply {
category = "auth"
message = "Authenticated user ${user.email}"
level = SentryLevel.INFO
}
Sentry.addBreadcrumb(breadcrumb)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.protocol.User

Sentry.configureScope { scope ->
scope.setTag("my-tag", "my value")
scope.user = User().apply {
id = "42"
email = "[email protected]"
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.SentryLevel

// will be tagged with my-tag="my value"
Sentry.captureException(Exception("my error")) { scope ->
scope.setTag("my-tag", "my value")
scope.level = SentryLevel.WARNING
}

// will not be tagged with my-tag
Sentry.captureException(Exception("my error"))
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

Sentry.configureScope { scope ->
scope.setContext("name", "Mighty Fighter")
scope.setContext("age", 19)
scope.setContext("attack_type", "melee")
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

Sentry.configureScope { scope ->
scope.setTag("page.locale", "de-at")
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.protocol.User

val user = User().apply {
email = "[email protected]"
}
Sentry.setUser(user)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

Sentry.configureScope { scope ->
scope.user = null
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.protocol.UserFeedback

val sentryId = Sentry.captureMessage("My message")

val userFeedback = UserFeedback(sentryId).apply {
comments = "It broke."
email = "[email protected]"
name = "John Doe"
}
Sentry.captureUserFeedback(userFeedback)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { ->
options.dsn = "___PUBLIC_DSN___"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### Prerequisites (Android)

Android requires disabling auto-init to not clash with the ContentProvider, which auto-initializes the Sentry Android SDK. To do so, add the following to the AndroidManifest.xml file under your androidMain source set:

```xml
<application>
<meta-data android:name="io.sentry.auto-init" android:value="false" />
</application>
```

To install the Kotlin Multiplatform SDK, you need to add the following to your `build.gradle.kts` file in your shared module:

```kotlin {filename:shared/build.gradle.kts}
repositories {
mavenCentral()
}

kotlin {
val commonMain by getting {
dependencies {
api("io.sentry:sentry-kotlin-multiplatform:{{ packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
}
}

// Android target
val androidMain by getting {
dependsOn(commonMain)
}

// Apple targets:
val iosMain by getting {
dependsOn(commonMain)
}

cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
pod("Sentry", "~> {{ packages.version('sentry.cocoa', '8.2.0') }}")

framework {
baseName = "shared"
export("io.sentry:sentry-kotlin-multiplatform:{{ packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Sentry's Kotlin Multiplatform SDK builds on top of multiple Sentry SDKs, allowing developers to use the same codebase and share code between platforms while being able to integrate Sentry's features into their applications.

## Overview of Features

- Native crash reporting for Android and JVM, leveraging our [Android SDK](/platforms/android) and [Java SDK](/platforms/java)
- Native crash reporting for iOS, macOS, tvOS, and watchOS, leveraging our [Cocoa SDK](/platforms/apple)
- Automatic breadcrumbs for app lifecycle and UI events

<Note>

This SDK is currently experimental.

</Note>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

fun captureError() {
try {
throw Exception("This is a test.")
} catch (e: Exception) {
Sentry.captureException(e)
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) {
it.environment = "production"
}
```
8 changes: 8 additions & 0 deletions src/platform-includes/set-level/kotlin-multiplatform.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry
import io.sentry.kotlin.multiplatform.SentryLevel

Sentry.configureScope { scope ->
scope.level = SentryLevel.WARNING
}
```
10 changes: 10 additions & 0 deletions src/platform-includes/set-release/kotlin-multiplatform.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```kotlin
import io.sentry.kotlin.multiplatform.Sentry

// Application context is only needed for Android targets
Sentry.init(context) { options ->
options.release = "[email protected]"
}
```

If no release name is set, the SDK creates a default, depending on the native platform.
3 changes: 2 additions & 1 deletion src/platforms/common/configuration/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ sidebar_order: 60
description: "Learn more about how to configure your SDK to filter events reported to Sentry."
notSupported:
- perl
- kotlin-multiplatform
---

Adding Sentry to your app gives you a great deal of very valuable information about errors and performance you wouldn't otherwise get. And lots of information is good -- as long as it's the right information, at a reasonable volume.
When you add Sentry to your app, you get a lot of valuable information about errors and performance. And lots of information is good -- as long as it's the right information, at a reasonable volume.

The Sentry SDKs have several configuration options to help you filter out events.

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/common/data-management/sensitive-data/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you are using Sentry in your mobile app, read our [frequently asked questions

</Note>

<PlatformSection notSupported={["apple", "javascript", "node", "perl", "native.breakpad", "native.crashpad", "native.minidumps", "native.wasm", "unreal", "go", "ruby", "native", "elixir", "dart", "flutter", "unity"]}>
<PlatformSection notSupported={["apple", "javascript", "node", "perl", "native.breakpad", "native.crashpad", "native.minidumps", "native.wasm", "unreal", "go", "ruby", "native", "elixir", "dart", "flutter", "unity", "kotlin-multiplatform"]}>

## Personally Identifiable Information (PII)

Expand All @@ -45,7 +45,7 @@ If you _do not_ wish to use the default PII behavior, you can also choose to ide

</PlatformSection>

<PlatformSection notSupported={["perl", "unreal", "native.breakpad", "native.crashpad", "native.minidumps", "native.wasm", "unity"]}>
<PlatformSection notSupported={["perl", "unreal", "native.breakpad", "native.crashpad", "native.minidumps", "native.wasm", "unity", "kotlin-multiplatform"]}>

## Scrubbing Data

Expand Down
8 changes: 4 additions & 4 deletions src/platforms/common/enriching-events/attachments/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ supported:
- unreal
- react-native
- python

- kotlin-multiplatform
---

<PlatformSection supported={["apple", "android", "java"]}>
Expand Down Expand Up @@ -58,7 +58,7 @@ To receive symbolicated stack traces, you have to upload debug information to Se

</PlatformSection>

<PlatformSection supported={["android", "apple", "java", "dotnet", "dart", "flutter", "unreal"]}>
<PlatformSection supported={["android", "apple", "java", "dotnet", "dart", "flutter", "unreal", "kotlin-multiplatform"]}>

## Creating Attachments

Expand Down Expand Up @@ -86,7 +86,7 @@ In addition, you can set these parameters:

## Uploading Attachments

<PlatformSection supported={["native", "javascript", "java", "python"]}>
<PlatformSection supported={["native", "javascript", "java", "python", "kotlin-multiplatform"]}>

<PlatformSection supported={["javascript", "node"]}>

Expand All @@ -100,7 +100,7 @@ You'll first need to import the SDK, as usual:

</PlatformSection>

<PlatformSection notSupported={["unity", "android"]} supported={["apple", "java", "dotnet", "dart", "flutter", "unreal"]}>
<PlatformSection notSupported={["unity", "android"]} supported={["apple", "java", "dotnet", "dart", "flutter", "unreal", "kotlin-multiplatform"]}>

Attachments live on the <PlatformLink to="/enriching-events/scopes/">Scope</PlatformLink>. You can either add an attachment on the global scope to be sent with every event or add it on the <PlatformLink to="/enriching-events/scopes/#local-scopes">local Scope</PlatformLink> to just send the attachment with one specific event.

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/enriching-events/breadcrumbs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This hook is passed an already assembled breadcrumb and, in some SDKs, an option

<PlatformContent includePath="enriching-events/breadcrumbs/before-breadcrumb" />

<PlatformSection notSupported={["apple", "dotnet", "unity"]}>
<PlatformSection notSupported={["apple", "dotnet", "unity", "kotlin-multiplatform"]}>

For information about what can be done with the hint, see <PlatformLink to="/configuration/filtering/#using-hints">Filtering Events</PlatformLink>.

Expand Down
Loading