getsentry / raven-go

Sentry client in Go
https://sentry.io
BSD 3-Clause "New" or "Revised" License
561 stars 148 forks source link

Docs: Add example of client setup using environment variable for dsn #153

Closed valentin-krasontovitsch closed 6 years ago

valentin-krasontovitsch commented 7 years ago

The Configuring the client section of the Usage and Examples mentions that the DSN can be picked up automagically from an environment variable SENTRY_DSN - yet using the provided examples and leaving out the call to raven.setDNS does (surprisingly to me ^^) not yield a functioning client.

Maybe I expect to much automagic, but in any case I think there should be an example where a sentry client is invoked without specifying the DSN explicitely.

In that context it should at least be mentioned that sentry doesn't care if the dsn is empty, and that it's the user's responsibility to check for that, cf. #85

tsauvajon commented 6 years ago

I've done it like that:

// Get the config from the environment
dsn := os.Getenv("SENTRY_DSN")
projectID := os.Getenv("SENTRY_PROJECT")

// Build the url
uri := fmt.Sprintf("https://%s@sentry.io/%s", dsn, projectID)

// Init sentry
raven.SetDSN(uri)
valentin-krasontovitsch commented 6 years ago

Okay, I've actually tried to understand and use the automagic configuration one more time, and it turns out there's literally nothing that you have to do when you set the SENTRY_DSN variable to a valid sentry dsn - in your code, you can just start capturing using raven.CaptureError (or whatever you wanna use), which is gonna call the default client internally, which gets configured automatically, reading the environment variable... cool ^^

I must have made a mistake in my earlier trials, so I'm gonna go ahead and close this issue.