Search code examples
javasentry

Where to get the Sentry/Raven DSN from at runtime?


Sentry.io requires a Data source name (DSN) for it's clients to upload exceptions. It's unclear to me from the docs

  • where this DSN ought to be kept, i.e. inside the application's open source code (doesn't seem to be a good idea, because what's the point of the private key then) or whether it ought to be queried from the user who reports the error and is registered at sentry.io (that would mean that it's not really automatic, but sentry.io doesn't define that neither)
  • which scope this string has, i.e. whether it's bound to a project or to a user and if the latter is the case to an sentry.io user which maintains the project or any user which uses a software which contains a sentry.io client and is registered at sentry.io. This is almost a separate question which becomes relevant as soon as I have to program user input for the DSN (in case it's user specific).

Why does the generic documentation use Javascript, i.e. is it for Javascript only or is it an example? In the practical example the Raven DSN comes from main method's arguments. When is this ever going to be the case in reality?


Solution

  • Sorry about the poor documentation. I'm working to overhaul them all right now, actually.

    You are correct that hardcoding the DSN or retrieving it manually from the program arguments is not preferred. The preferred way to set your DSN (and other configuration) is via process environment variables or Java system properties. See the example here: https://github.com/getsentry/raven-java/blob/08c45e38a859e222b56d21570d00ad6a1411ebdd/raven-logback/README.md

    This way, the Raven client code can be included in the project (even in open source projects) but the configuration of the DSN happens at runtime however the administrator prefers to setup their environment (or not configured at all, if they want to leave Sentry disabled).

    In regards to the other question: a DSN is tied to a specific Sentry project so that all exceptions that occur in that project are aggregated regardless of which end user encountered the issue.