Skip to content

Commit

Permalink
Merge branch 'master' into dynamic-sampling
Browse files Browse the repository at this point in the history
# Conflicts:
#	sentry.go
  • Loading branch information
cleptric committed Nov 29, 2022
2 parents 135e56b + c5a9734 commit c60dcb3
Show file tree
Hide file tree
Showing 15 changed files with 915 additions and 240 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
@@ -1,10 +1,13 @@
# Changelog

## Unreleased
- *[breaking]* ref: Unify TracesSampler (#444)

## 0.15.0

- fix: Scope values should not override Event values (#446)
- feat: Extend User inteface by adding Data, Name and Segment (#483)
- feat: Make maximum amount of spans configurable (#460)
- feat: Add a method to start a transaction (#482)
- feat: Extend User interface by adding Data, Name and Segment (#483)
- feat: Add ClientOptions.SendDefaultPII (#485)

## 0.14.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ The only requirement is a Go compiler.

We verify this package against the 3 most recent releases of Go. Those are the
supported versions. The exact versions are defined in
[`GitHub workflow`](.github/workflows/ci.yml).
[`GitHub workflow`](.github/workflows/test.yml).

In addition, we run tests against the current master branch of the Go toolchain,
though support for this configuration is best-effort.
Expand Down
9 changes: 3 additions & 6 deletions client.go
Expand Up @@ -3,7 +3,6 @@ package sentry
import (
"context"
"crypto/x509"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -126,6 +125,8 @@ type ClientOptions struct {
// 0.0 is treated as if it was 1.0. To drop all events, set the DSN to the
// empty string.
SampleRate float64
// Enable performance tracing.
EnableTracing bool
// The sample rate for sampling traces in the range [0.0, 1.0].
TracesSampleRate float64
// Used to customize the sampling of traces, overrides TracesSampleRate.
Expand Down Expand Up @@ -235,10 +236,6 @@ type Client struct {
// single goroutine) or hub methods (for concurrent programs, for example web
// servers).
func NewClient(options ClientOptions) (*Client, error) {
if options.TracesSampleRate != 0.0 && options.TracesSampler != nil {
return nil, errors.New("TracesSampleRate and TracesSampler are mutually exclusive")
}

if options.Debug {
debugWriter := options.DebugWriter
if debugWriter == nil {
Expand Down Expand Up @@ -323,7 +320,7 @@ func (client *Client) setupTransport() {
// accommodate more concurrent events.
// TODO(tracing): consider using separate buffers per
// event type.
if opts.TracesSampleRate != 0 || opts.TracesSampler != nil {
if opts.EnableTracing {
httpTransport.BufferSize = 1000
}
transport = httpTransport
Expand Down
23 changes: 12 additions & 11 deletions example/http/main.go
Expand Up @@ -3,7 +3,7 @@
//
// Try it by running:
//
// go run main.go
// go run main.go
//
// To actually report events to Sentry, set the DSN either by editing the
// appropriate line below or setting the environment variable SENTRY_DSN to
Expand Down Expand Up @@ -53,30 +53,31 @@ func run() error {
log.Printf("BeforeSend event [%s]", event.EventID)
return event
},
// Specify either TracesSampleRate or set a TracesSampler to
// enable tracing.
// TracesSampleRate: 0.5,
TracesSampler: sentry.TracesSamplerFunc(func(ctx sentry.SamplingContext) sentry.Sampled {
// Enable tracing
EnableTracing: true,
// Specify either a TracesSampleRate...
TracesSampleRate: 1.0,
// ... or a TracesSampler
TracesSampler: sentry.TracesSampler(func(ctx sentry.SamplingContext) float64 {
// As an example, this custom sampler does not send some
// transactions to Sentry based on their name.
hub := sentry.GetHubFromContext(ctx.Span.Context())
name := hub.Scope().Transaction()
if name == "GET /favicon.ico" {
return sentry.SampledFalse
return 0.0
}
if strings.HasPrefix(name, "HEAD") {
return sentry.SampledFalse
return 0.0
}
// As an example, sample some transactions with a
// uniform rate.
// As an example, sample some transactions with a uniform rate.
if strings.HasPrefix(name, "POST") {
return sentry.UniformTracesSampler(0.2).Sample(ctx)
return 0.2
}
// Sample all other transactions for testing. On
// production, use TracesSampleRate with a rate adequate
// for your traffic, or use the SamplingContext to
// customize sampling per-transaction.
return sentry.SampledTrue
return 1.0
}),
})
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions example/logrus/main.go
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"net/http"
"os"
"time"

"github.com/sirupsen/logrus"

"github.com/getsentry/sentry-go"
sentrylogrus "github.com/getsentry/sentry-go/logrus"
)

func main() {
logger := logrus.New()

// Log DEBUG and higher level logs to STDERR
logger.Level = logrus.DebugLevel
logger.Out = os.Stderr

// Send only ERROR and higher level logs to Sentry
sentryLevels := []logrus.Level{logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel}

sentryHook, err := sentrylogrus.New(sentryLevels, sentry.ClientOptions{
Dsn: "",
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
if hint.Context != nil {
if req, ok := hint.Context.Value(sentry.RequestContextKey).(*http.Request); ok {
// You have access to the original Request
fmt.Println(req)
}
}
fmt.Println(event)
return event
},
Debug: true,
AttachStacktrace: true,
})
if err != nil {
panic(err)
}
defer sentryHook.Flush(5 * time.Second)
logger.AddHook(sentryHook)

// The following line is logged to STDERR, but not to Sentry
logger.Infof("Application has started")

// The following line is logged to STDERR and also sent to Sentry
logger.Errorf("oh no!")
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -11,6 +11,7 @@ require (
github.com/labstack/echo/v4 v4.9.0
github.com/pingcap/errors v0.11.4
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/urfave/negroni v1.0.0
github.com/valyala/fasthttp v1.40.0
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec
Expand Down Expand Up @@ -59,7 +60,6 @@ require (
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/tdewolff/minify/v2 v2.12.4 // indirect
github.com/tdewolff/parse/v2 v2.6.4 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
Expand Down
23 changes: 0 additions & 23 deletions internal/crypto/randutil/randutil.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/crypto/randutil/randutil_test.go

This file was deleted.

0 comments on commit c60dcb3

Please sign in to comment.