Skip to content

Commit

Permalink
Stop sending span.fp to the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Slotin committed Feb 12, 2021
1 parent dcbe1ec commit fea4b23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 125 deletions.
75 changes: 0 additions & 75 deletions instrumentation_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"

instana "github.com/instana/go-sensor"
"github.com/instana/go-sensor/w3ctrace"
"github.com/instana/testify/assert"
"github.com/instana/testify/require"
)
Expand Down Expand Up @@ -49,8 +48,6 @@ func TestTracingHandlerFunc_Write(t *testing.T) {
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)

assert.Nil(t, span.ForeignParent)

require.IsType(t, instana.HTTPSpanData{}, span.Data)
data := span.Data.(instana.HTTPSpanData)

Expand Down Expand Up @@ -133,8 +130,6 @@ func TestTracingHandlerFunc_SecretsFiltering(t *testing.T) {
assert.Empty(t, span.CorrelationType)
assert.Empty(t, span.CorrelationID)

assert.Nil(t, span.ForeignParent)

require.IsType(t, instana.HTTPSpanData{}, span.Data)
data := span.Data.(instana.HTTPSpanData)

Expand Down Expand Up @@ -184,76 +179,6 @@ func TestTracingHandlerFunc_Error(t *testing.T) {
}, data.Tags)
}

func TestTracingHandlerFunc_W3CTraceContext_ForeignParent(t *testing.T) {
examples := map[string]struct {
IncomingHeaders map[string]string
Expected *instana.ForeignParent
}{
"incoming w3c, no instana headers, latest state from instana": {
IncomingHeaders: map[string]string{
w3ctrace.TraceParentHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
w3ctrace.TraceStateHeader: "in=abc123;def456,vendorname1=opaqueValue1",
},
Expected: &instana.ForeignParent{
TraceID: "4bf92f3577b34da6a3ce929d0e0e4736",
ParentID: "00f067aa0ba902b7",
LatestTraceState: "in=abc123;def456",
},
},
"incoming w3c, with instana headers, latest state from instana": {
IncomingHeaders: map[string]string{
w3ctrace.TraceParentHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
w3ctrace.TraceStateHeader: "in=abc123;def456,vendorname1=opaqueValue1",
instana.FieldT: "abc123",
instana.FieldS: "def456",
},
},
"incoming w3c, with instana headers, latest state not from instana": {
IncomingHeaders: map[string]string{
w3ctrace.TraceParentHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
w3ctrace.TraceStateHeader: "vendorname1=opaqueValue1,in=abc123;def456",
instana.FieldT: "abc123",
instana.FieldS: "def456",
},
Expected: &instana.ForeignParent{
TraceID: "4bf92f3577b34da6a3ce929d0e0e4736",
ParentID: "00f067aa0ba902b7",
LatestTraceState: "vendorname1=opaqueValue1",
},
},
}

for name, example := range examples {
t.Run(name, func(t *testing.T) {
recorder := instana.NewTestRecorder()
s := instana.NewSensorWithTracer(instana.NewTracerWithEverything(&instana.Options{
Service: "go-sensor-test",
}, recorder))

h := instana.TracingHandlerFunc(s, "test-handler", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "Ok")
})

rec := httptest.NewRecorder()

req := httptest.NewRequest(http.MethodGet, "/test", nil)
for k, v := range example.IncomingHeaders {
req.Header.Set(k, v)
}

h.ServeHTTP(rec, req)

assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "Ok\n", rec.Body.String())

spans := recorder.GetQueuedSpans()
require.Len(t, spans, 1)

assert.Equal(t, example.Expected, spans[0].ForeignParent)
})
}
}

func TestTracingHandlerFunc_SyntheticCall(t *testing.T) {
recorder := instana.NewTestRecorder()
s := instana.NewSensorWithTracer(instana.NewTracerWithEverything(&instana.Options{}, recorder))
Expand Down
64 changes: 14 additions & 50 deletions json_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"time"

"github.com/instana/go-sensor/w3ctrace"
"github.com/opentracing/opentracing-go/ext"
)

Expand Down Expand Up @@ -111,37 +110,6 @@ func (k SpanKind) String() string {
}
}

// ForeignParent represents a related 3rd-party trace context, e.g. a W3C Trace Context
type ForeignParent struct {
TraceID string `json:"t"`
ParentID string `json:"p"`
LatestTraceState string `json:"lts,omitempty"`
}

func newForeignParent(p interface{}) *ForeignParent {
switch p := p.(type) {
case w3ctrace.Context:
return newW3CForeignParent(p)
default:
return nil
}
}

func newW3CForeignParent(trCtx w3ctrace.Context) *ForeignParent {
p, s := trCtx.Parent(), trCtx.State()

var lastVendorData string
if len(s) > 0 {
lastVendorData = s[0]
}

return &ForeignParent{
TraceID: p.TraceID,
ParentID: p.ParentID,
LatestTraceState: lastVendorData,
}
}

// Span represents the OpenTracing span document to be sent to the agent
type Span struct {
TraceID int64
Expand All @@ -157,7 +125,6 @@ type Span struct {
Ec int
Data typedSpanData
Synthetic bool
ForeignParent *ForeignParent
CorrelationType string
CorrelationID string
}
Expand All @@ -173,7 +140,6 @@ func newSpan(span *spanS) Span {
Duration: uint64(span.Duration) / uint64(time.Millisecond),
Name: string(data.Type()),
Ec: span.ErrorCount,
ForeignParent: newForeignParent(span.context.ForeignParent),
CorrelationType: span.Correlation.Type,
CorrelationID: span.Correlation.ID,
Kind: int(data.Kind()),
Expand Down Expand Up @@ -203,21 +169,20 @@ func (sp Span) MarshalJSON() ([]byte, error) {
}

return json.Marshal(struct {
TraceID string `json:"t"`
ParentID string `json:"p,omitempty"`
SpanID string `json:"s"`
Timestamp uint64 `json:"ts"`
Duration uint64 `json:"d"`
Name string `json:"n"`
From *fromS `json:"f"`
Batch *batchInfo `json:"b,omitempty"`
Kind int `json:"k"`
Ec int `json:"ec,omitempty"`
Data typedSpanData `json:"data"`
Synthetic bool `json:"sy,omitempty"`
ForeignParent *ForeignParent `json:"fp,omitempty"`
CorrelationType string `json:"crtp,omitempty"`
CorrelationID string `json:"crid,omitempty"`
TraceID string `json:"t"`
ParentID string `json:"p,omitempty"`
SpanID string `json:"s"`
Timestamp uint64 `json:"ts"`
Duration uint64 `json:"d"`
Name string `json:"n"`
From *fromS `json:"f"`
Batch *batchInfo `json:"b,omitempty"`
Kind int `json:"k"`
Ec int `json:"ec,omitempty"`
Data typedSpanData `json:"data"`
Synthetic bool `json:"sy,omitempty"`
CorrelationType string `json:"crtp,omitempty"`
CorrelationID string `json:"crid,omitempty"`
}{
FormatID(sp.TraceID),
parentID,
Expand All @@ -231,7 +196,6 @@ func (sp Span) MarshalJSON() ([]byte, error) {
sp.Ec,
sp.Data,
sp.Synthetic,
sp.ForeignParent,
sp.CorrelationType,
sp.CorrelationID,
})
Expand Down

0 comments on commit fea4b23

Please sign in to comment.