Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Nov 30, 2022
1 parent 30506ea commit b182fc5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
9 changes: 5 additions & 4 deletions dynamic_sampling_context.go
Expand Up @@ -37,12 +37,13 @@ func DynamicSamplingContextFromHeader(header []byte) (DynamicSamplingContext, er
}, nil
}

func DynamicSamplingContextFromTransaction(span *Span) (DynamicSamplingContext, error) {
func DynamicSamplingContextFromTransaction(span *Span) DynamicSamplingContext {
entries := map[string]string{}

hub := hubFromContext(span.Context())
scope := hub.Scope()
options := hub.Client().Options()
client := hub.Client()
options := client.Options()

if traceID := span.TraceID.String(); traceID != "" {
entries["trace_id"] = traceID
Expand All @@ -51,7 +52,7 @@ func DynamicSamplingContextFromTransaction(span *Span) (DynamicSamplingContext,
entries["sample_rate"] = strconv.FormatFloat(sampleRate, 'f', -1, 64)
}

if dsn := hub.Client().dsn; dsn != nil {
if dsn := client.dsn; dsn != nil {
if publicKey := dsn.publicKey; publicKey != "" {
entries["public_key"] = publicKey
}
Expand All @@ -77,7 +78,7 @@ func DynamicSamplingContextFromTransaction(span *Span) (DynamicSamplingContext,
return DynamicSamplingContext{
Entries: entries,
Frozen: true,
}, nil
}
}

func (d DynamicSamplingContext) HasEntries() bool {
Expand Down
5 changes: 1 addition & 4 deletions dynamic_sampling_context_test.go
Expand Up @@ -110,10 +110,7 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) {
}

for _, tc := range tests {
got, err := DynamicSamplingContextFromTransaction(tc.input)
if err != nil {
t.Fatal(err)
}
got := DynamicSamplingContextFromTransaction(tc.input)
assertEqual(t, got, tc.want)
}
}
Expand Down
2 changes: 1 addition & 1 deletion http/sentryhttp.go
Expand Up @@ -72,7 +72,7 @@ func (h *Handler) Handle(handler http.Handler) http.Handler {
// literal.
//
// http.Handle(pattern, h.HandleFunc(func (w http.ResponseWriter, r *http.Request) {
// // handler code here
// // handler code here
// }))
func (h *Handler) HandleFunc(handler http.HandlerFunc) http.HandlerFunc {
return h.handle(handler)
Expand Down
5 changes: 1 addition & 4 deletions tracing.go
Expand Up @@ -403,10 +403,7 @@ func (s *Span) toEvent() *Event {
// Create and attach a DynamicSamplingContext to the transaction.
// If the DynamicSamplingContext is not frozen at this point, we can assume being head of trace.
if !s.dynamicSamplingContext.IsFrozen() {
dsc, err := DynamicSamplingContextFromTransaction(s)
if err == nil {
s.dynamicSamplingContext = dsc
}
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(s)
}

return &Event{
Expand Down

0 comments on commit b182fc5

Please sign in to comment.