Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not double sample transactions #328

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func (client *Client) processEvent(event *Event, hint *EventHint, scope EventMod
options.SampleRate = 1.0
}

if !sample(options.SampleRate) {
if event.Type != transactionType && !sample(options.SampleRate) {
rhcarvalho marked this conversation as resolved.
Show resolved Hide resolved
Logger.Println("Event dropped due to SampleRate hit.")
return nil
}
Expand Down
28 changes: 28 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math"
"net/http"
"reflect"
"testing"
Expand Down Expand Up @@ -313,3 +315,29 @@ func TestSpanFromContext(t *testing.T) {
// RecorderLen: 1,
// }.Check(t, child)
}

func TestDoubleSampling(t *testing.T) {
transport := &TransportMock{}
ctx := NewTestContext(ClientOptions{
SampleRate: math.SmallestNonzeroFloat64,
TracesSampleRate: 1.0,
Transport: transport,
})
span := StartSpan(ctx, "op", TransactionName("name"))

// CaptureException should not send any event because of SampleRate.
GetHubFromContext(ctx).CaptureException(errors.New("ignored"))
if got := len(transport.Events()); got != 0 {
t.Fatalf("got %d events, want 0", got)
}

// Finish should send one transaction event, always sampled via
// TracesSampleRate.
span.Finish()
if got := len(transport.Events()); got != 1 {
t.Fatalf("got %d events, want 1", got)
}
if got := transport.Events()[0].Type; got != transactionType {
t.Fatalf("got %v event, want %v", got, transactionType)
}
}