Skip to content

Commit

Permalink
fix tag.Map.
Browse files Browse the repository at this point in the history
  • Loading branch information
rghetia committed Aug 23, 2019
1 parent 20222ed commit 107023d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions propagation/http_textformat_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,66 +68,66 @@ var _ apipropagation.Extractor = textFormatExtractor{}
func (tfe textFormatExtractor) Extract() (sc core.SpanContext, tm tag.Map) {
h, ok := getRequestHeader(tfe.req, traceparentHeader, false)
if !ok {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
sections := strings.Split(h, "-")
if len(sections) < 4 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}

if len(sections[0]) != 2 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
ver, err := hex.DecodeString(sections[0])
if err != nil {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
version := int(ver[0])
if version > maxVersion {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}

if version == 0 && len(sections) != 4 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}

if len(sections[1]) != 32 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}

result, err := strconv.ParseUint(sections[1][0:16], 16, 64)
if err != nil {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
sc.TraceID.High = result

result, err = strconv.ParseUint(sections[1][16:32], 16, 64)
if err != nil {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
sc.TraceID.Low = result

if len(sections[2]) != 16 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
result, err = strconv.ParseUint(sections[2][0:], 16, 64)
if err != nil {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
sc.SpanID = result

opts, err := hex.DecodeString(sections[3])
if err != nil || len(opts) < 1 {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}
sc.TraceOptions = opts[0]

if !sc.IsValid() {
return core.EmptySpanContext(), nil
return core.EmptySpanContext(), tag.NewEmptyMap()
}

// TODO: [rghetia] add tag.Map (distributed context) extraction
return sc, nil
return sc, tag.NewEmptyMap()
}

type textFormatInjector struct {
Expand Down
4 changes: 3 additions & 1 deletion propagation/http_textformat_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"net/http"
"testing"

"go.opentelemetry.io/api/tag"

"github.com/google/go-cmp/cmp"
"go.opentelemetry.io/api/core"
"go.opentelemetry.io/propagation"
Expand Down Expand Up @@ -118,7 +120,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
i := propagator.Injector(req)
i.Inject(tt.sc, nil)
i.Inject(tt.sc, tag.NewEmptyMap())

gotHeader := req.Header.Get("traceparent")
if diff := cmp.Diff(gotHeader, tt.wantHeader); diff != "" {
Expand Down
2 changes: 0 additions & 2 deletions sdk/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/tag"
apitrace "go.opentelemetry.io/api/trace"
)

Expand Down Expand Up @@ -93,4 +92,3 @@ func (tr *tracer) WithComponent(component string) apitrace.Tracer {
tr.component = component
return tr
}

0 comments on commit 107023d

Please sign in to comment.