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

WASM support #227

Open
nowiwr01w opened this issue May 19, 2024 · 5 comments
Open

WASM support #227

nowiwr01w opened this issue May 19, 2024 · 5 comments

Comments

@nowiwr01w
Copy link

Problem Statement

Hi, guys
What do you think about supporting Kotlin/Wasm target for this library? Are there any plans for it?
It would be great

Solution Brainstorm

No response

@buenaflor
Copy link
Contributor

buenaflor commented May 21, 2024

Hi, of course if there is enough demand we will support it.

But currently there is no plan to tackle this.

We can keep this issue open and let people upvote it so we know how many people are interested

@chrisjenx
Copy link

Vote here for WASM support too please

@oblakr24
Copy link

oblakr24 commented Aug 26, 2024

Here is my workaround which uses the JS interop via the JS Sentry SDK:

Note: if you use a browser extension such as UBlock Origin, it may block the outgoing Sentry requests, so you may have to disable it.

  1. add the npm dependency
   wasmJsMain.dependencies {
          ...
            implementation(npm("@sentry/browser", "8.26.0"))
        }
  1. define the external interfaces
package sentry

@JsModule("@sentry/browser")
external object SentryJs {
    fun init(options: JsAny)
    fun captureException(e: JsAny)
    fun captureMessage(message: String)
    fun addBreadcrumb(message: String)
}

fun createOptions(dsn: String): JsAny = js("""
    ({
    dsn: dsn,
  // Tracing
  debug: true,
  tracesSampleRate: 1.0, //  Capture 100% of the transactions
  // Session Replay
  replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  // Set profilesSampleRate to 1.0 to profile every transaction.
  // Since profilesSampleRate is relative to tracesSampleRate,
  // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  // results in 25% of transactions being profiled (0.5*0.5=0.25)
  profilesSampleRate: 1.0
  })
""")

fun createErrorMessage(message: String): JsAny =
    js("new Error(message)")

fun createErrorWithStackTrace(message: String, stackTrace: String, className: String): JsAny =
    js(
        """
        (() => {
            const err = new Error(message);
            err.stack = stackTrace;
            err.name = className;
            return err;
        })()
    """
    )
  1. now you can use it similarly to the KMP lib:
  val dsn = "..."
  SentryJs.init(createOptions(dsn = dsn))


SentryJs.addBreadcrumb("Breadcrumb 1")

val e: Throwable? = ...
 if (e != null) {
      val stackTrace = e.stackTraceToString()
      val error = createErrorWithStackTrace(
          message = "$msg: ${e.message}",
          stackTrace = stackTrace,
          className = e::class.simpleName ?: "Throwable"
      )
      SentryJs.captureException(error)
  } else {
      SentryJs.captureException(createErrorMessage("$msg: ${e?.message}"))
  }

@bruno-garcia
Copy link
Member

Did you guys figure out the symbolication part of it? To upload symbols and then build the stack traces the 'right way' so we can symbolicate server side?

Just put this ticket together but from my tests, that was an issue on .NET still. That's opened here:

@buenaflor
Copy link
Contributor

I haven't taken a deep dive yet, also depends on what kotlin/wasm produces, might either be dwarf or sourcemap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

5 participants