jcpsantiago / sentryR

Unofficial R client for Sentry
https://jcpsantiago.github.io/sentryR/
Other
38 stars 14 forks source link

How to get DSN? #35

Closed durraniu closed 2 months ago

durraniu commented 3 months ago

Thank you for creating this package. I have not used sentry before so I am not sure how to get started. I understand the instructions in the README. But what should I select as a platform while creating a new project on sentry website? R is not an option there. Without that, how do I get the DSN?

durraniu commented 2 months ago

I have now tried using dsn from node and python projects on sentry. Python sentry SDK works fine but when I use the same dsn in a shiny app with sentryR, I do not see any error reports on sentry. Any help is appreciated. @jcpsantiago @egnor @AhmedSamy @ellisvalentiner @kirel @AEBilgrau @AndLLA @jwebbvalent

jcpsantiago commented 2 months ago

Hello @durraniu thanks for trying out SentryR, and sorry I couldn't get to you earlier. Small ask: I'm the current maintainer of this package, so please avoid @mentioning everyone that contributed code before 🙏

When you create a new project select "Other" as your platform:

Screenshot 2024-08-02 at 16 45 46

In the next screen you'll see your DSN (looks like https:/xxxx@xxxxxxx.ingest.de.sentry.io/xxx) — copy it and replace it as per the example in the README:

library(sentryR)

configure_sentry(dsn = "THE DSN HERE",
                 app_name = "myapp", app_version = "8.8.8",
                 environment = Sys.getenv("APP_ENV"),
                 tags = list(foo = "tag1", bar = "tag2"),
                 runtime = NULL)

capture(message = "my message", level = "info")

Running the last capture function should create an event in Sentry.

The README uses Sys.getenv("SENTRY_DSN") which gets the DSN from an env var instead of hardcoding it in the code, which is recommended because of security issues, plus it makes your code cleaner.

Let me know if this helps.

durraniu commented 2 months ago

Thank you so much for your reply. I apologize for tagging others.

With 'Other' project I do see 'my message' on sentry. My goal is to track errors in shiny. So, I tried the following but that did not send anything to sentry:

library(shiny)
library(sentryR)

configure_sentry(dsn = "DSN",
                 app_name = "my_shiny_app",
                 app_version = "1.0.0"
)

error_handler <- function() {
  capture_exception(error = geterrmessage())
}

options(shiny.error = error_handler)

ui <- fluidPage(
  titlePanel("sentryR Shiny App Example"),
  sidebarLayout(
    sidebarPanel(
      actionButton("errorBtn", "Trigger Error")
    ),
    mainPanel(
      textOutput("text")
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$errorBtn, {
    stop("This is a test error for Sentry!")
  })
}

shinyApp(ui, server)

What am I missing here?

durraniu commented 2 months ago

Replacing capture_exception(error = geterrmessage()) with capture(message = geterrmessage(), level = 'error') worked in the shiny app. README probably needs an update.

Thanks again for creating this package. It is going to be immensely helpful.