From 33562f066eb53de589f9a1b08646ff8e21668ad2 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 30 Nov 2022 17:37:11 +0100 Subject: [PATCH] Transaction Source --- dynamic_sampling_context_test.go | 2 +- interfaces.go | 19 +++++++++++++------ tracing.go | 1 + tracing_test.go | 1 + transport.go | 9 +++++---- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dynamic_sampling_context_test.go b/dynamic_sampling_context_test.go index ca8bec70d..6957f8384 100644 --- a/dynamic_sampling_context_test.go +++ b/dynamic_sampling_context_test.go @@ -93,7 +93,7 @@ func TestDynamicSamplingContextFromTransaction(t *testing.T) { Dsn: "http://public@example.com/sentry/1", Release: "1.0.0", }) - txn := StartTransaction(ctx, "name") + txn := StartTransaction(ctx, "name", TransctionSource(SourceURL)) txn.TraceID = TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03") return txn }(), diff --git a/interfaces.go b/interfaces.go index 5adf12518..ae581c403 100644 --- a/interfaces.go +++ b/interfaces.go @@ -222,6 +222,11 @@ type SDKMetaData struct { transactionSource TransactionSource } +// Contains information about how the name of the transaction was determined. +type TransactionInfo struct { + Source TransactionSource `json:"source,omitempty"` +} + // EventID is a hexadecimal string representing a unique uuid4 for an Event. // An EventID must be 32 characters long, lowercase and not have any dashes. type EventID string @@ -255,9 +260,10 @@ type Event struct { // The fields below are only relevant for transactions. - Type string `json:"type,omitempty"` - StartTime time.Time `json:"start_timestamp"` - Spans []*Span `json:"spans,omitempty"` + Type string `json:"type,omitempty"` + StartTime time.Time `json:"start_timestamp"` + Spans []*Span `json:"spans,omitempty"` + TransactionInfo *TransactionInfo `json:"transaction_info,omitempty"` // The fields below are not part of the final JSON payload. @@ -303,9 +309,10 @@ func (e *Event) defaultMarshalJSON() ([]byte, error) { // be sent for transactions. They shadow the respective fields in Event // and are meant to remain nil, triggering the omitempty behavior. - Type json.RawMessage `json:"type,omitempty"` - StartTime json.RawMessage `json:"start_timestamp,omitempty"` - Spans json.RawMessage `json:"spans,omitempty"` + Type json.RawMessage `json:"type,omitempty"` + StartTime json.RawMessage `json:"start_timestamp,omitempty"` + Spans json.RawMessage `json:"spans,omitempty"` + TransactionInfo json.RawMessage `json:"transaction_info,omitempty"` } x := errorEvent{event: (*event)(e)} diff --git a/tracing.go b/tracing.go index 33b4e5aa6..efd5dd884 100644 --- a/tracing.go +++ b/tracing.go @@ -83,6 +83,7 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp Op: operation, StartTime: time.Now(), Sampled: SampledUndefined, + Source: SourceCustom, ctx: context.WithValue(ctx, spanContextKey{}, &span), parent: parent, diff --git a/tracing_test.go b/tracing_test.go index dc98277aa..1508abf5c 100644 --- a/tracing_test.go +++ b/tracing_test.go @@ -207,6 +207,7 @@ func TestStartChild(t *testing.T) { ParentSpanID: child.ParentSpanID, Op: child.Op, Sampled: SampledTrue, + Source: child.Source, }, }, } diff --git a/transport.go b/transport.go index 6661f6a2c..841b4d782 100644 --- a/transport.go +++ b/transport.go @@ -98,11 +98,12 @@ func transactionEnvelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body var b bytes.Buffer enc := json.NewEncoder(&b) - dsc := event.sdkMetaData.dsc + // Construct the trace envolope header var trace = map[string]string{} - - for k, v := range dsc.Entries { - trace[k] = v + if dsc := event.sdkMetaData.dsc; dsc.HasEntries() { + for k, v := range dsc.Entries { + trace[k] = v + } } // Envelope header