Skip to content

Commit

Permalink
Merge branch 'dynamic-sampling' into head-of-trace
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Nov 7, 2022
2 parents c039340 + 7ecd814 commit 74f80b4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
47 changes: 29 additions & 18 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ func TestCaptureMessageEmptyString(t *testing.T) {
},
}
got := transport.lastEvent
opts := cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
}
})
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
}
}),
}

if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -282,7 +286,7 @@ func TestCaptureEvent(t *testing.T) {
},
}
got := transport.lastEvent
opts := cmp.Options{cmpopts.IgnoreFields(Event{}, "Release")}
opts := cmp.Options{cmpopts.IgnoreFields(Event{}, "Release", "sdkMetaData")}
if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("Event mismatch (-want +got):\n%s", diff)
}
Expand All @@ -309,11 +313,14 @@ func TestCaptureEventNil(t *testing.T) {
},
}
got := transport.lastEvent
opts := cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
}
})
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
}
}),
}
if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -476,13 +483,17 @@ func TestRecover(t *testing.T) {
t.Fatalf("events = %s\ngot %d events, want 1", b, len(events))
}
got := events[0]
opts := cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Message: e.Message,
Exception: e.Exception,
Level: e.Level,
}
})
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Message: e.Message,
Exception: e.Exception,
Level: e.Level,
}
}),
}

if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("(-want +got):\n%s", diff)
}
Expand Down
1 change: 1 addition & 0 deletions fasthttp/sentryfasthttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Extra", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Tags", "Timestamp",
"sdkMetaData",
),
cmpopts.IgnoreMapEntries(func(k string, v string) bool {
// fasthttp changed Content-Length behavior in
Expand Down
1 change: 1 addition & 0 deletions http/sentryhttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Extra", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Tags", "Timestamp",
"sdkMetaData",
),
cmpopts.IgnoreFields(
sentry.Request{},
Expand Down
6 changes: 3 additions & 3 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ const (
DynamicSamplingContextKey SDKMetaDataKey = "DynamicSamplingContext"
)

// SDKMetaData is a struct to stash data which is needed at some point in the SDK's event processing pipeline
// sdkMetaData is a struct to stash data which is needed at some point in the SDK's event processing pipeline
// but which shouldn't get send to Sentry.
type SDKMetaData = struct {
type SDKMetaData struct {
DynamicSamplingContextKey DynamicSamplingContext
}

Expand Down Expand Up @@ -266,7 +266,7 @@ type Event struct {

// The fields below are not part of the final JSON payload.

SDKMetaData SDKMetaData `json:"-"`
sdkMetaData SDKMetaData
}

// TODO: Event.Contexts map[string]interface{} => map[string]EventContext,
Expand Down
8 changes: 4 additions & 4 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ func (s *Span) ToSentryTrace() string {
}

func (s *Span) ToBaggage() string {
if dsc := s.dynamicSamplingContext; len(dsc.Entries) > 0 {
return dsc.String()
if len(s.dynamicSamplingContext.Entries) > 0 {
return s.dynamicSamplingContext.String()
}

return ""
Expand Down Expand Up @@ -377,7 +377,7 @@ func (s *Span) toEvent() *Event {
Timestamp: s.EndTime,
StartTime: s.StartTime,
Spans: finished,
SDKMetaData: SDKMetaData{
sdkMetaData: SDKMetaData{
DynamicSamplingContextKey: s.dynamicSamplingContext,
},
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func ContinueFromRequest(r *http.Request) SpanOption {

// ContinueFromHeaders returns a span option that updates the span to continue
// an existing TraceID and propagates the Dynamic Sampling context.
func ContinueFromHeaders(trace string, baggage string) SpanOption {
func ContinueFromHeaders(trace, baggage string) SpanOption {
return func(s *Span) {
if trace != "" {
s.updateFromSentryTrace([]byte(trace))
Expand Down
3 changes: 3 additions & 0 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestStartSpan(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"Contexts", "EventID", "Level", "Platform",
"Release", "Sdk", "ServerName", "Modules",
"sdkMetaData",
),
cmpopts.EquateEmpty(),
}
Expand Down Expand Up @@ -229,6 +230,7 @@ func TestStartChild(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"EventID", "Level", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Timestamp", "StartTime",
"sdkMetaData",
),
cmpopts.IgnoreMapEntries(func(k string, v interface{}) bool {
return k != "trace"
Expand Down Expand Up @@ -312,6 +314,7 @@ func TestStartTransaction(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"Contexts", "EventID", "Level", "Platform",
"Release", "Sdk", "ServerName", "Modules",
"sdkMetaData",
),
cmpopts.EquateEmpty(),
}
Expand Down
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func transactionEnvelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body
var b bytes.Buffer
enc := json.NewEncoder(&b)

dsc := event.SDKMetaData.DynamicSamplingContextKey
dsc := event.sdkMetaData.DynamicSamplingContextKey
var trace = map[string]string{}

for k, v := range dsc.Entries {
Expand Down

0 comments on commit 74f80b4

Please sign in to comment.