Skip to content

Commit

Permalink
fix variable names and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rghetia committed Aug 9, 2019
1 parent 009d7a2 commit 9411593
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions propagation/http_textformat_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (t textFormatPropagator) Injector(req *http.Request) trace.Injector {
// TextFormatPropagator creates a new propagator. The propagator is then used
// to create Injector and Extrator associated with a specific request. Injectors
// and Extractors respectively provides method to inject and extract SpanContext
// into/from the http request.
// into/from the http request. Inject method encodes SpanContext into W3C
// TraceContext Header and injects the header in the request. Extract extracts
// the header and decodes SpanContext.
func TextFormatPropagator() textFormatPropagator {
return textFormatPropagator{}
}
Expand All @@ -63,8 +65,8 @@ var _ trace.Extractor = textFormatExtractor{}

// Extract implements Extract method of trace.Extractor interface. It extracts
// W3C TraceContext Header and decodes SpanContext from the Header.
func (f textFormatExtractor) Extract() (sc core.SpanContext, tm tag.Map) {
h, ok := getRequestHeader(f.req, traceparentHeader, false)
func (tfe textFormatExtractor) Extract() (sc core.SpanContext, tm tag.Map) {
h, ok := getRequestHeader(tfe.req, traceparentHeader, false)
if !ok {
return core.INVALID_SPAN_CONTEXT, nil
}
Expand Down Expand Up @@ -137,15 +139,15 @@ var _ trace.Injector = textFormatInjector{}
// Inject implements Inject method of trace.Injector interface. It encodes
// SpanContext into W3C TraceContext Header and injects the header into
// the associated request.
func (f textFormatInjector) Inject(sc core.SpanContext, tm tag.Map) {
func (tfi textFormatInjector) Inject(sc core.SpanContext, tm tag.Map) {
if sc.IsValid() {
h := fmt.Sprintf("%.2x-%.16x%.16x-%.16x-%.2x",
supportedVersion,
sc.TraceID.High,
sc.TraceID.Low,
sc.SpanID,
sc.TraceOptions)
f.req.Header.Set(traceparentHeader, h)
tfi.req.Header.Set(traceparentHeader, h)
}
// TODO: [rghetia] add tag.Map (distributed context) injection
}
Expand Down
8 changes: 4 additions & 4 deletions propagation/http_textformat_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func TestExtractTraceContextFromHTTPReq(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
req.Header.Set("traceparent", tt.header)
f := propagator.Extractor(req)
e := propagator.Extractor(req)

gotSc, _ := f.Extract()
gotSc, _ := e.Extract()
if diff := cmp.Diff(gotSc, tt.wantSc); diff != "" {
t.Errorf("Extract Tracecontext: %s: -got +want %s", tt.name, diff)
}
Expand Down Expand Up @@ -117,8 +117,8 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", "http://example.com", nil)
f := propagator.Injector(req)
f.Inject(tt.sc, nil)
i := propagator.Injector(req)
i.Inject(tt.sc, nil)

gotHeader := req.Header.Get("traceparent")
if diff := cmp.Diff(gotHeader, tt.wantHeader); diff != "" {
Expand Down

0 comments on commit 9411593

Please sign in to comment.