# README
ocsentry
Provides OpenCensus traces support for Sentry.
Why?
OpenCensus has tracing instrumentations for a variety of technologies (databases, services, caches, etc...), this library enables those instrumentations for Sentry performance tools with minimal effort.
Also implementing traces with Sentry client directly makes it harder to change the technology in the future, as opposed to vendor-unlocked OpenCensus.
Usage
- Replace default tracer with a wrapper:
trace.DefaultTracer = ocsentry.WrapTracer(trace.DefaultTracer)
. - Use
ocsentry.HTTPHandlerMiddleware
instead ofgithub.com/getsentry/sentry-go/http.(*Handler).Handle
so that originalsentry
tracer does not duplicate theochttp
job.
package main
import (
"log"
"net/http"
"time"
"github.com/getsentry/sentry-go"
"github.com/vearutop/ocsentry"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"
)
func main() {
// Initialize Sentry.
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/1234567",
ServerName: "my-service",
Release: "v1.2.3",
})
if err != nil {
log.Fatal(err)
}
defer func() {
sentry.Flush(time.Second)
}()
// Setup OC sampling.
trace.ApplyConfig(trace.Config{
DefaultSampler: trace.ProbabilitySampler(0.01),
})
// Enable Sentry wrapper.
trace.DefaultTracer = ocsentry.WrapTracer(trace.DefaultTracer)
var h http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("Hello, world!"))
if err != nil {
log.Print(err)
return
}
})
// Apply OpenCensus middleware and Sentry middlewares to your http.Handler.
h = ocsentry.HTTPHandlerMiddleware(h)
h = &ochttp.Handler{Handler: h}
if err := http.ListenAndServe(":80", h); err != nil {
log.Print(err)
return
}
}
# Functions
ErrorHandler is a handler for ErrorCatcher of github.com/swaggest/usecase.
HTTPHandlerMiddleware prepares request context without creating sentry trace span for trace span is to be created by OpenCensus instrumentation.
OnPanic handles recovered panics.
SkipTransactionNames is an option to skip transactions with provided names from sentry collection.
WrapTracer creates a tracer that manages Sentry spans together with OpenCensus spans.
# Type aliases
Option is a functional option.