Giter Club home page Giter Club logo

sentry-kotlin-multiplatform's Introduction

Shows a black logo in light color mode and a white one in dark color mode.

Sentry SDK for Kotlin Multiplatform

Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoying technology. If you want to join us Check out our open positions

This SDK is a wrapper around different platforms such as JVM, Android, iOS, macOS, watchOS, tvOS that can be used on Kotlin Multiplatform.

Kotlin KDoc link

Packages Maven Central
sentry-kotlin-multiplatform Maven Central

Supported Platforms

Target Platform Target preset
Android
  • android
Kotlin/JVM
  • jvm
iOS
  • iosArm64
  • iosX64
  • iosSimulatorArm64
macOS
  • macosArm64
  • macosX64
watchOS
  • watchosArm32
  • watchosArm64
  • watchosX64
  • watchosSimulatorArm64
tvOS
  • tvosArm64
  • tvosX64
  • tvosSimulatorArm64

Usage

For detailed usage, check out the Kotlin Multiplatform Documentation.

Samples

For detailed information on how to build and run the samples, check out our README.md in the sentry-samples folder.

Apple Privacy Manifest

Starting with May 1st 2024, apps submitted to the Apple App Store are required to declare approved reasons to access certain privacy-relevant APIs. This also includes usages of these APIs via third-party SDKs. To ensure compliance, update your Sentry Cocoa SDK to 8.21.0. For more information, refer to our Apple Privacy Manifest Guide.

Contribution

Please see the contribution guide before contributing

Resources

  • Kotlin Multiplatform Documentation
  • Discussions
  • Discord Chat
  • Stack Overflow
  • Code of Conduct
  • Twitter Follow

sentry-kotlin-multiplatform's People

Contributors

bruno-garcia avatar buenaflor avatar getsentry-bot avatar github-actions[bot] avatar mattjohnsonpint avatar philipphofmann avatar romtsn avatar swolfand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sentry-kotlin-multiplatform's Issues

Not published to maven central

This is more of a tracking issue. I'd like to remove our interop from Kermit and just use this library, but the target isn't yet deployed to maven central. I assume it will be soon, as it says maven central in the readme. It looks like the readme changed recently.

Any update on when the first version will be deployed would be great, thanks!

Build issue for Github runner v2.296.1

Since Github updated their runner from v2.296.0 to v2.296.1 builds are now failing do to unknown compilations error in the Apple modules. The line of code that apparently is failing has not been changed in 3 weeks.

Problem is that even older jobs that were successful are now failing as well when you rerun them.

Example: https://github.com/getsentry/sentry-kotlin-multiplatform/actions/runs/2971237681

This blocks a release as it cannot generate and upload artifacts needed by Craft.

Update: This is still prevalent as of v2.297.0

iOS stacktraces are not symbolicate

Platform

Apple

Installed

Swift Package Manager

Version

0.2.1

Steps to Reproduce

Zrzut ekranu 2023-10-20 o 13 51 49 Zrzut ekranu 2023-10-20 o 10 24 53

Expected Result

I would like to see readable stacktrace

Actual Result

Zrzut ekranu 2023-10-20 o 11 50 46 Zrzut ekranu 2023-10-20 o 11 58 44 Zrzut ekranu 2023-10-20 o 11 59 11

Breadcrumbs Don't Seem to Work Right on iOS

Environment

iOS

0.2.0 for the shared kmm code
and 8.4.0 for the iOS library using SPM

Steps to Reproduce

I wrote a custom log writer that adds bread crumbs to my sentry log every time something is globally logged in my app.
This works great on Android and will add all the breadcrumbs to my error / crash log, but on iOS the only way I can seem to get a breadcrumb to log with my error / exception is to write it in the capture exception scope like this:

Sentry.captureException(throwable) {
    it.addBreadcrumb(Breadcrumb.debug("TEST"))
}

Expected Result

Expected that the last 100 breadcrumb before the exception will be reported since 100 is the default config value. Obviously assuming I logged that many things before the error / exception was logged.

Actual Result

I only see my "TEST" breadcrumb because that one is recorded in the scope. Again this is only a weird behavior on iOS. It works fine on Android.

Here's my logger code that is written in my common kotlin module and works fine for Android, but not for iOS:

class SentryLogWriter(
    private val minSeverity: Severity,
    private val minCrashSeverity: Severity,
) : LogWriter() {
    init {
        check(minSeverity <= minCrashSeverity) {
            "minSeverity ($minSeverity) cannot be greater than minCrashSeverity ($minCrashSeverity)"
        }
    }

    override fun isLoggable(severity: Severity): Boolean = severity >= minSeverity

    override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
        if (throwable == null) {
            Sentry.addBreadcrumb(
                Breadcrumb(
                    severity.toSentryLevel(),
                    message = message,
                    category = tag
                )
            )
        }
        if (throwable != null && severity >= minCrashSeverity) {
            Sentry.captureException(throwable) {
                it.addBreadcrumb(Breadcrumb.debug("TEST this is a Test"))
            }
        }
    }
}

fun Severity.toSentryLevel(): SentryLevel {
    return when (this) {
        Severity.Debug -> SentryLevel.DEBUG
        Severity.Info -> SentryLevel.INFO
        Severity.Warn -> SentryLevel.WARNING
        Severity.Error -> SentryLevel.ERROR
        Severity.Assert -> SentryLevel.FATAL
        else -> throw IllegalArgumentException("Unsupported severity level")
    }
}

Any advice would be greatly appreciated. I spent the better part of a day playing with this and couldn't get it working right. But I'm super excited this KMM library exists now.

Issue When Archiving Build for Apple App Store Release

Description

I'm pretty sure this has to do with the Sentry KMM addition. I've been successfully archiving my app until today. I recently included the KMM Sentry module into my shared code. Wondering what could be causing this and if there's maybe a workaround?

What's interesting is it builds just fine for the simulator.

Here's the error I'm getting:

PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/alexblack/Library/Developer/Xcode/DerivedData/DownpourSwiftUI-ekhhapuimgkiynculezcbgexbcpq/Build/Intermediates.noindex/ArchiveIntermediates/Blackstone\ Unlimited/IntermediateBuildFilesPath/DownpourSwiftUI.build/Release-iphoneos/BlackstoneUnlimited.build/Script-797174D0E3936128D44473F8.sh (in target 'BlackstoneUnlimited' from project 'DownpourSwiftUI')
    cd /Users/alexblack/Projects/Work/AndroidProjects/Downpour-MonoRepo/ios
    /bin/sh -c /Users/alexblack/Library/Developer/Xcode/DerivedData/DownpourSwiftUI-ekhhapuimgkiynculezcbgexbcpq/Build/Intermediates.noindex/ArchiveIntermediates/Blackstone\\\ Unlimited/IntermediateBuildFilesPath/DownpourSwiftUI.build/Release-iphoneos/BlackstoneUnlimited.build/Script-797174D0E3936128D44473F8.sh

mkdir -p /Users/alexblack/Library/Developer/Xcode/DerivedData/DownpourSwiftUI-ekhhapuimgkiynculezcbgexbcpq/Build/Intermediates.noindex/ArchiveIntermediates/Blackstone Unlimited/BuildProductsPath/Release-iphoneos/BlackstoneUnlimited.app/Frameworks
Symlinked...
rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Sentry.framework" "/Users/alexblack/Library/Developer/Xcode/DerivedData/DownpourSwiftUI-ekhhapuimgkiynculezcbgexbcpq/Build/Intermediates.noindex/ArchiveIntermediates/Blackstone Unlimited/InstallationBuildProductsLocation/Applications/BlackstoneUnlimited.app/Frameworks"
building file list ... rsync: link_stat "/Users/alexblack/Projects/Work/AndroidProjects/Downpour-MonoRepo/ios/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Sentry.framework" failed: No such file or directory (2)
done

sent 29 bytes  received 20 bytes  98.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/c2cb9645-dafc-11ed-aa26-6ec1e3b3f7b3/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9]
Command PhaseScriptExecution failed with a nonzero exit code

Fail task linkPodDebugFrameworkIosX64

All my attempts to connect Sentry KMM to my project end in errors. What can I do wrong?

w: Interop library /Users/pikselnsk/.gradle/caches/modules-2/files-2.1/io.sentry/sentry-kotlin-multiplatform-iosx64/0.0.1/41a5fe46ac76e87affbd64a4a9ff1750e312ccb2/sentry-kotlin-multiplatform-cinterop-Sentry can't be exported with -Xexport-library
w: Interop library /Users/pikselnsk/.gradle/caches/modules-2/files-2.1/io.sentry/sentry-kotlin-multiplatform-iosx64/0.0.1/b391b9ac2720a6ffa4315b2e903a070c209a2db4/sentry-kotlin-multiplatform-cinterop-Sentry.NSException can't be exported with -Xexport-library
w: Interop library /Users/pikselnsk/.gradle/caches/modules-2/files-2.1/io.sentry/sentry-kotlin-multiplatform-iosx64/0.0.1/97366cb0d055b6e32c55bd529bb9e554b2ce2e73/sentry-kotlin-multiplatform-cinterop-Sentry.Scope can't be exported with -Xexport-library

my cocoapods settings

 cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        ios.deploymentTarget = "15.0"
        podfile = project.file("../iosApp/Podfile")
        pod("Sentry", "~> 7.21.0")

        framework {
            baseName = "shared"
            isStatic = false
            export("io.sentry:sentry-kotlin-multiplatform:0.0.1")
        }
    }

Info is missing for iOS breadcrumbs

Problem

Some info is missing from breadcrumbs on iOS.

Reproduction

The tested iOS apps operate on identical code bases using SwiftUI. One is an independent iOS App using the Sentry Cocoa SDK, the other is an iOS App with Kotlin Multiplatform using the Sentry KMP SDK. The events are the same thrown exceptions

Expected Result

on standalone iOS App using the Sentry Cocoa SDK directly

image

Actual Result

on KMP iOS App using the Sentry KMP SDK

image

Cocoa crash handling doesn't accomodate sdkInfo removal

Problem

Crash handling on iOS devices (or Cocoa in general) doesn't work as intended. It crashes during the creation of SentryEnvelopeHeader because sdkInfo has been deprecated. In essence the actual crash is replaced with an internal SentryEnvelopeHeader crash

sdkInfo deprecated: getsentry/sentry-cocoa#1960

image

Solution

Remove sdkInfo from the interop bridge

Regular framework support (use without CocoaPods)

Problem Statement

I don't like CocoaPods. They're complicated and not a great solution at all.

Solution Brainstorm

Could a Gradle script be utilized to facilitate the copying or updating of the XCFramework to its designated location?

Alternatively, a more streamlined approach could involve developing a completely Kotlin-based version of the SDK, thereby replacing the existing iteration with an XCFramework generated through Kotlin/Native.

Missing Configuration - DSN is required. Use empty string to disable SDK.

Environment

Trying to prepare the setup of Sentry with Kotlin Multiplatform.
I was following the guide, made a mavenLocal() build etc.
Now I wanted to add this to the project.
However, when starting my (Android) project, even before starting the onCreate of the Application I get a crash stating:

Unable to get provider io.sentry.android.core.SentryInitProvider: 
java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.

So to be clear this happens already when adding api("io.sentry:sentry-kotlin-multiplatform:0.0.1") to the dependencies.

Steps to Reproduce

  1. configure shared build.gradle.kts and add
 val commonMain by getting {
            dependencies {
                api("io.sentry:sentry-kotlin-multiplatform:0.0.1")
  1. Add the sample configuration

So I added:

fun initializeSentry(context: Context) {
    Sentry.init(context) { sentryOptions -> .. } 
}

and in the Android Application:

        initializeSentry(this)

But when running the app I don't even get there.

Expected Result

The configuration should be reached and the initializeSentry(this) block executed. (I can accept if it fails there but I don't even get that far.)

Actual Result

The app fails stating

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: xyz, PID: 23056
    java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
        ...

even before anything else.
So the mere adding to the gradle file causes the crash already (even if the other code is commented out).

-------- Full Stack trace-------

java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

     Caused by: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at io.sentry.Sentry.initConfigurations(Sentry.java:201)
        at io.sentry.Sentry.init(Sentry.java:170)
        at io.sentry.Sentry.init(Sentry.java:118)
        at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:87)
        at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:56)
        at io.sentry.android.core.SentryInitProvider.onCreate(SentryInitProvider.java:27)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
        at io.sentry.android.core.SentryInitProvider.attachInfo(SentryInitProvider.java:44)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7462)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)ย 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)ย 
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)ย 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)ย 
        at android.os.Handler.dispatchMessage(Handler.java:106)ย 
        at android.os.Looper.loopOnce(Looper.java:201)ย 
        at android.os.Looper.loop(Looper.java:288)ย 
        at android.app.ActivityThread.main(ActivityThread.java:7872)ย 
        at java.lang.reflect.Method.invoke(Native Method)ย 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)ย 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)ย 

Streamline and align the "Getting Started" docs to fit in the new structure

Problem Statement

  • The "Getting Started" documentation for sentry-kotlin-multiplatform platforms may not conform to the newly defined format, which includes the steps "Install", "Configure", "Verify", and the optional "Next Steps".
    • The "Verify" step is not always available and it is a very important step that helps the user to verify that the installation and configuration were done correctly.
  • New users onboarding with Sentry may find the existing documentation extensive and unclear. The "Getting Started" guide should cover the basics, while more advanced configurations shall live on the sentry-docs website.
  • Some copies and code snippets in the documentation may be outdated.

Solution Brainstorm

The task goals are as follows:

  • Thoroughly review all sentry-kotlin-multiplatform platform documentation, including less commonly used sections, and reorganize their content into structured headings: 'Install,' 'Configure,' 'Verify,' and the optional 'Next Steps.'
  • The onboarding documentation should strictly focus on the basics to help users get started. Advanced configurations should be available in the complete documentation on the sentry-docs website.
  • Essential information for new users should be included under the new 'Notes' section in the onboarding documentation.
  • Update code snippets and copies as necessary.
  • If a "Verify" step is missing, include it in the documentation.

Please refer to the "Frontendend Handbook" guide in our "Sentry" main repository for assistance in adding and updating the getting started docs: Frontendend Handbook.

Project: getsentry/team-sdks#23

Support configuration of beforeSend hook

The sentry SDK for android and ios have both the beforeSend filter which allows to filter and manipulate events before they are send. Currently it is not possible to set the beforeSend filter in kotlin multiplatform.

Set up repo and project

Tasks

Provide Hint in beforeSend hook

Currently it is very difficult to filter exceptions in common kotlin code, because we don't have access to the original exception object which causes the event. We need to compare the type name and package name of the exceptions as strings. What normally is a simple hint is MyException is turned into

inline fun <reified T> SentryException.isOfType(): Boolean {
    val qualifiedName = T::class.qualifiedName ?: error("Cannot get qualified name of ${T::class}")
    val module = qualifiedName.substringBeforeLast(".")
    val type = qualifiedName.substringAfterLast(".")
    return module == this.module && type == this.type
}

But this does not work for exception subtypes, so if there is an exception which is a subtype of MyException it is impossible to filter this with the current beforeSend because one had to know all subtypes to handle them all individually.

Performance monitoring support in Ktor Client

Problem Statement

This issue is a follow up on #25.

As Ktor Client is currently a very popular (probably even the most popular) solution for network clients on KMP, it might be good to add support for instrumenting performance monitoring on Ktor client.

Currently blocked by #83

Solution Brainstorm

OpenTelemetry already has an example: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/0f87eaf3d6a769a7ef3e3c5c2bf7457eaf0e3e9d/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt#L6

Avoid needing the Android Context in Sentry.init(..) common code

Problem

Sentry Android init needs the Android context: SentryAndroid.init(context) { } which is not easily replicated in the common code.

Our current solution involves a hacky workaround that declares an expect class in commonCode which typealiases to Android context on Android but does nothing on iOS.

common: expect abstract class Context
android: actual typealias Context
iOS: actual abstract class Context

Avoiding context would also mean the user doesn't need to specifically create another init function just for the context which removes some of the burden on them.

Solution

A user pointed to an article/blog with a possible solution for this in discussions: #112

The article: https://proandroiddev.com/how-to-avoid-asking-for-android-context-in-kotlin-multiplatform-libraries-api-d280a4adebd2

Essentially what we would be going to use is the androidx.startup:startup-runtime package which handles the initialization before the library code - repo

Update:
This can be implemented using a simple internal ContentProvider on KMP Android. The incorporation of the startup library is still something that is being discussed.

Update Sentry SDK version

On sentry.io we get a notification to update the sentry SDK, but there is no newer version of this library with the latest SDK version. Can you please update the sentry SDK version.

feat: support singular initialization on compose multiplatform

Currently it's only possible to initialize in platform specific code since every platform is independent from one another in KMP but in Jetpack Compose it's possible to initialize in the shared compose app.

It's beneficial to add support for single initialization on compose multiplatform apps since users would only need to init in one single place.

Add ability to perform basic custom instrumentation with Transaction and Spans

This would allow developers to create custom transactions and spans in their code to capture information about their application's performance and behavior.

At the very least support:

  • Transaction
  • Span
  • startTransaction()
  • startChild()
  • getSpan()
  • tracesSampleRate option
  • tracesSampler option

Align implementation with:

Blocked by

Filename guidelines to expect/actual and platform specific implementations

As our codebase grows it's important to keep it organized in a way that makes searching for specific implementations easy.

Example: we specify an expect class SentryEvent in our commonMain which is called SentryEvent.kt.
Now on commonAppleMain and commonJvmMain the actual implementations are also called SentryEvent.kt so we have 3 files with the same name.

How Google for example handles it: suffix the filename with the platform -> SentryEvent.jvm.kt or SentryEvent.apple.kt.

See here for an example.

This is not publicly endorsed by Google but could be a good starting point on how to organize this.

This could also not be only restricted to expect actuals but in general for any File name that will exist on multiple platforms with the same name. So this could also be helpful for our extensions: SentryOptionsExtensions.jvm.kt or BreadcrumbExtensions.jvm.kt

Thoughts?

Interop generation for iOS arm64

Environment

How do you use Sentry?
Sentry SaaS (sentry.io)

Which SDK and version?
Sentry 7.21.0

M1 mac with interop enabled for arm64 and simulatorArm64

Steps to Reproduce

Add pod"Sentry", "~> 7.21.0") to cocoapods gradle plugin

Expected Result

Sync succeeds

Actual Result

Sync step fails in android studio.

it fails on 3 steps :

  1. cinteropSentryIosArm64
  2. cinteropSentryIosSimulatorArm64
  3. shared:cinteropSentryIosX64

Example error log for one of the steps :
Link

Additional info

When trying to sync the kmp-app sample i get a failure on the following step:
Task 'wrapper' not found in project ':sentry-samples:kmp-app'.

So i'm wondering if there might be something wrong in my environment ?

Question

Are there any requirements to make the interop work on an M1 setting or is it supposed to work out of the box ?

Let me know if you need any more details. Thanks for your help !

Use trimmed headers instead of cocoapods for Apple targets

Problem

Currently we use cocoapods to pull in the Sentry Cocoa SDK dependency for Apple targets. This might create an overhead by also pulling in many headers that we don't use. (needs investigation how big this overhead actually is)

Solution

Grab and trim headers that we need so we only define the utmost minimum that we need to support the Cocoa SDK features that we are using and run cinterop on those.

We are already doing this for accessing private Sentry Cocoa SDK features: https://github.com/getsentry/sentry-kotlin-multiplatform/tree/main/sentry-kotlin-multiplatform/src/nativeInterop/cinterop

Testing

This will break internal tests on the cocoa side but that's easily fixable by just introducing the workaround mentioned here

Improve initialization naming consistency

Problem

If possible we can improve the naming to be more consistent with how platform specific Sentry SDKs initialize

Expected result

// Android
Sentry.init(context) {
  ...
} 

// Cocoa
Sentry.start {
  ...
}

Actual result

// on both platforms
SentryKMP.start {  
  ...
}

feat: add JS Browser support

It's possible to install NPM packages via implementation(npm(...)) and create bindings through @JsModule(...) annotation

Ideally we install @sentry/browser and wrap our KMP sdk around it.

I have played around with it and was able to do basic things like init and captureMessage

beforeSend is not called for Fatal Exceptions on Android

Environment

Version: 0.2.0
Platform: Android

I'm trying to filter fatal exceptions, so that they are not reported to sentry. I use the beforeSend hook to filter out the events:

    Sentry.init(context) {
        ...
        it.beforeSend = { event ->
                if (event.level == SentryLevel.FATAL) {
                    // Ignore fatal errors
                    null
                } else {
                    event
                }
            }
    }

Steps to Reproduce

  1. Setup Sentry and configure a beforeSend callback
  2. Throw exception in Activity onCreate, which crashes the android app
  3. App closes, but beforeSend is not called
  4. Crash event is shown in sentry UI

Expected Result

beforeSend is called for fatal exception, so I can filter or modify the events before they are send to sentry.

Actual Result

I can not filter and modify the event before it is send to sentry.

Question: Why cocoapods and cinterop?

There's no "discussions" so I thought I'd ask. I started looking through the code. Is there a reason the library has both direct cinterop and a pod dependency? I would assume the pod is to link for tests, but that seems like it could be wired in directly with linker args. I haven't gone into the actual code much, though. Just curious.

[Gradle Plugin] Add support for creating a dynamic library when using SPM and Cocoapods (not kotlin cocoapods)

Description

Currently if someone wants to use SPM or (native, not kotlin) Cocoapods with our SDK it is only possible when making the shared libary static (dynamic is the default), e.g:

kotlin {
  listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
  ).forEach {
    it.binaries.framework {
        baseName = "shared"
        isStatic = true // Using SPM is only available when creating a static framework
    }
  }

Why the current solution is not ideal

  • The sure way to get dynamic framework to work is by using the kotlin cocoapods plugin to pull in the sentry-cocoa dependency, however that is inefficient as it runs through c-interop which also creates extra compile time and overhead in the final binary (also probably a lot of dead code)

Advantages of having it work as a dynamic library

  • SwiftUI previews don't work with static libraries. There might be some workaround but that adds extra layers of complexity for the user.

Why it doesn't work

On iOS only the definitions for Sentry are added when compiling the Kotlin code and building the framework. The binary (the actual Sentry Cocoa library) isn't added until later when you build the iOS app. When building a dynamic framework, the Kotlin compile expects to be able to resolve everything and it ends up with this error:
ld: symbol(s) not found for architecture x86_64 which basically tells us it cannot find the binary.

Solution

Crashkios has solved this by basically telling the linker to treat the listed symbols as undefined. That means the linker will not try to find these symbols during the linking process and assumes these symbols will be provided by other means.

Essentially this means creating a KMP gradle plugin.

Blocked by

  1. Platform: KMP

Does My iOS KMM Library Need to Be Static For dSYM to Work Properly?

Description

A point I've found endlessly confusing and not well explained on the Kotlin docs... do I need my iOS shared library to be static? If so why? and if not why do I not seem to be getting line numbers from my dynamic lib crash reports? Are there any additional Gradle configs I might be missing?

Here's what my Gradle cocoapods config looks like:

    cocoapods {
        // Configure fields required by CocoaPods.
        summary = "some description"
        homepage = "myurl.com"
        pod("Sentry", "~> 8.4.0")
        ios.deploymentTarget = "14"
        framework {

            // You can change the name of the produced framework.
            // By default, it is the name of the Gradle project.
            baseName = "shared"

            // this needs to be false in order to view SwiftUI previews, but needs to be true
            // to get symbolical builds. :/
            isStatic = false

            export("co.touchlab:kermit:$kermit_version")
        }
    }

commonizeCInterop fails with `Unresolved classifier: platform/darwin/xpc_rich_error_t` on XCode 14.2

Environment

Apple M1 Pro
XCode 14.2
macOS Ventura 13.0.1

Steps to Reproduce

./gradlew build

Expected Result

Builds successfully.

Actual Result

> Task :sentry-kotlin-multiplatform:commonizeCInterop FAILED
Exception in thread "main" java.lang.IllegalStateException: Unresolved classifier: platform/darwin/xpc_rich_error_t
        at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpansion$Companion.create(CirTypeAliasExpander.kt:183)
        at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.type(CirDeserializers.kt:367)
        at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.valueParameter(CirDeserializers.kt:199)
        at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.function(CirDeserializers.kt:178)
        at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreeFunctionDeserializer.invoke(CirTreeFunctionDeserializer.kt:29)
        at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreePackageDeserializer.invoke(CirTreePackageDeserializer.kt:33)
        at org.jetbrains.kotlin.commonizer.tree.deserializer.CirTreeModuleDeserializer.invoke(CirTreeModuleDeserializer.kt:32)
        at org.jetbrains.kotlin.commonizer.tree.deserializer.RootCirTreeDeserializer.invoke(RootCirTreeDeserializer.kt:37)
 ...

Seems to be related to this issue: https://youtrack.jetbrains.com/issue/KT-54225/Native-update-to-Xcode-14.1

Updating Kotlin to 1.8.0 (Kotlin and Kotlin Gradle Plugin) solves this issue but creates a new one.

> Task :sentry-samples:kmp-app:shared:commonizeCInterop FAILED
Exception in thread "main" java.lang.IllegalStateException: Unresolved classifier: cocoapods/Sentry/SentryBreadcrumb
	at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpander.expandClassType(CirTypeAliasExpander.kt:216)
	at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpander.expandTypeProjection(CirTypeAliasExpander.kt:73)
	at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpander.expandClassType(CirTypeAliasExpander.kt:140)
	at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpander.expandTypeProjection(CirTypeAliasExpander.kt:73)
	at org.jetbrains.kotlin.commonizer.metadata.CirTypeAliasExpander.expand(CirTypeAliasExpander.kt:44)
	at org.jetbrains.kotlin.commonizer.metadata.CirDeserializers.type(CirDeserializers.kt:366)

Removing the samples project ultimately resolved the issue.

IOS crash while handling event

I'm getting app crashes while sentry is handling some exception.

Uncaught Kotlin exception: kotlin.ClassCastException: class kotlin.Int cannot be cast to class kotlin.Long
The stacktrace indicates that it happens in toKmpSentryException kfun:io.sentry.kotlin.multiplatform.extensions#toKmpSentryException__at__cocoapods.Sentry.SentryException(){}io.sentry.kotlin.multiplatform.protocol.SentryException + 723
I think it happens at this line:

Add dedicated Context class

Adding a Context class instead of using maps makes managing setting values much easier and avoids code duplication since the implementation between JVM and Cocoa differs and we need to use context in multiple places.

Sample is broken

I cloned the repo, imported the mobile app into Android Studio and tried to run it without any modification. The result is this error:

e: /<path>/sentry-kotlin-multiplatform/Samples/mobile-app/app/src/main/java/sample/SampleAndroid.kt: (7, 18): Unresolved reference: ContextProvider

Support configuration of fingerprint for Events

To group issues and messages in the sentry ui, normally the stack trace is used, but we want to customize the grouping for specific issues. The Android and IOS sdk allow to set a fingerprint for issues and messages, which used to group the issues in sentry.

It should be possible to set the fingerprint via the multiplatform sdk.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.