Skip to content

Commit 6451bd9

Browse files
authored
Remove context from Sentry.init in KMP (#8477)
1 parent 8fc8c1c commit 6451bd9

File tree

9 files changed

+20
-37
lines changed

9 files changed

+20
-37
lines changed

src/platform-includes/configuration/config-intro/kotlin-multiplatform.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
```kotlin
44
import io.sentry.kotlin.multiplatform.Sentry
55

6-
// Application context is only needed for Android targets
7-
Sentry.init(context) { options ->
6+
Sentry.init { options ->
87
options.dsn = "___PUBLIC_DSN___"
98
options.release = "[email protected]+1"
109
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```kotlin
22
import io.sentry.kotlin.multiplatform.Sentry
33

4-
// Application context is only needed for Android targets
5-
Sentry.init(context) { options ->
4+
Sentry.init { options ->
65
options.attachScreenshot = true
76
}
87
```

src/platform-includes/enriching-events/attach-viewhierarchy/kotlin-multiplatform.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Currently only available on iOS and Android.
99
```kotlin
1010
import io.sentry.kotlin.multiplatform.sentry
1111

12-
// Application context is only needed for Android targets
13-
Sentry.init(context) { options ->
12+
Sentry.init { options ->
1413
options.dsn = "___PUBLIC_DSN___"
1514
options.attachViewHierarchy = true
1615
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```kotlin
22
import io.sentry.kotlin.multiplatform.Sentry
33

4-
// Application context is only needed for Android targets
5-
Sentry.init(context) { options ->
4+
Sentry.init { options ->
65
options.maxAttachmentSize = 5 * 1024 * 1024 // 5 MiB
76
}
87
```

src/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/kotlin-multiplatform.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```kotlin
22
import io.sentry.kotlin.multiplatform.Sentry
33

4-
// Application context is only needed for Android targets
5-
Sentry.init(context) { options ->
4+
Sentry.init { options ->
65
options.beforeBreadcrumb = { breadcrumb ->
76
if ("a.spammy.Logger" == breadcrumb.category) {
87
null

src/platform-includes/getting-started-config/kotlin-multiplatform.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
```kotlin
44
import io.sentry.kotlin.multiplatform.Sentry
55

6-
// Application context is only needed for Android targets
7-
Sentry.init(context) { ->
6+
Sentry.init { ->
87
options.dsn = "___PUBLIC_DSN___"
98
}
109
```
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```kotlin
22
import io.sentry.kotlin.multiplatform.Sentry
33

4-
// Application context is only needed for Android targets
5-
Sentry.init(context) {
4+
Sentry.init {
65
it.environment = "production"
76
}
87
```

src/platform-includes/set-release/kotlin-multiplatform.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```kotlin
22
import io.sentry.kotlin.multiplatform.Sentry
33

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

src/platforms/kotlin-multiplatform/initialization-strategies.mdx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,15 @@ To initialize the SDK, create a Kotlin file in your `commonMain` e.g. `AppSetup.
2121
<SignInNote />
2222

2323
```kotlin {filename:AppSetup.kt}
24-
import io.sentry.kotlin.multiplatform.Context
2524
import io.sentry.kotlin.multiplatform.Sentry
2625

2726
// Application context is only needed for Android targets
28-
fun initializeSentry(context: Context?) {
27+
fun initializeSentry() {
2928
val configuration: (SentryOptions) -> Unit = {
3029
it.dsn = "___PUBLIC_DSN___"
3130
// Add common configuration here
3231
}
33-
if (context != null) {
34-
Sentry.init(context, configuration)
35-
} else {
36-
Sentry.init(configuration)
37-
}
32+
Sentry.init(configuration)
3833
}
3934
```
4035

@@ -48,8 +43,7 @@ import your.kmp.app.initializeSentry
4843
class YourApplication : Application() {
4944
override fun onCreate() {
5045
super.onCreate()
51-
// Make sure to add the context!
52-
initializeSentry(this)
46+
initializeSentry()
5347
}
5448
}
5549
```
@@ -63,7 +57,7 @@ func application(
6357
_ application: UIApplication,
6458
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
6559
) -> Bool {
66-
AppSetupKt.initializeSentry(context = nil)
60+
AppSetupKt.initializeSentry()
6761
return true
6862
}
6963
```
@@ -79,7 +73,7 @@ This approach gives you the flexibility to fine-tune the SDK's behavior to meet
7973
```kotlin {filename:commonMain/AppSetup.kt}
8074
import io.sentry.kotlin.multiplatform.Context
8175

82-
expect fun initializeSentry(context: Context? = null)
76+
expect fun initializeSentry()
8377
```
8478

8579
### androidMain
@@ -90,12 +84,10 @@ expect fun initializeSentry(context: Context? = null)
9084
import io.sentry.kotlin.multiplatform.Sentry
9185
import io.sentry.kotlin.multiplatform.Context
9286

93-
actual fun initializeSentry(context: Context?) {
94-
if (context != null) {
95-
Sentry.init(context) {
96-
it.dsn = "___PUBLIC_DSN___"
97-
// Add Android-specific configuration here
98-
}
87+
actual fun initializeSentry() {
88+
Sentry.init {
89+
it.dsn = "___PUBLIC_DSN___"
90+
// Add Android-specific configuration here
9991
}
10092
}
10193
```
@@ -108,7 +100,7 @@ actual fun initializeSentry(context: Context?) {
108100
import io.sentry.kotlin.multiplatform.Sentry
109101
import io.sentry.kotlin.multiplatform.Context
110102

111-
actual fun initializeSentry(context: Context?) {
103+
actual fun initializeSentry() {
112104
Sentry.init {
113105
it.dsn = "___PUBLIC_DSN___"
114106
// Add iOS-specific configuration here
@@ -126,8 +118,7 @@ import your.kmp.app.initializeSentry
126118
class YourApplication : Application() {
127119
override fun onCreate() {
128120
super.onCreate()
129-
// Make sure to add the context!
130-
initializeSentry(this)
121+
initializeSentry()
131122
}
132123
}
133124
```
@@ -141,7 +132,7 @@ func application(
141132
_ application: UIApplication,
142133
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
143134
) -> Bool {
144-
AppSetupKt.initializeSentry(context = nil)
135+
AppSetupKt.initializeSentry()
145136
return true
146137
}
147138
```

0 commit comments

Comments
 (0)