From 94115938dff15d1ab11df20b3d3b15ef459cb124 Mon Sep 17 00:00:00 2001 From: rahulpa Date: Fri, 9 Aug 2019 15:02:13 -0700 Subject: [PATCH] fix variable names and comments. --- propagation/http_textformat_propagator.go | 12 +++++++----- propagation/http_textformat_propagator_test.go | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/propagation/http_textformat_propagator.go b/propagation/http_textformat_propagator.go index cd1bdad33f60..57b40eeea4ba 100644 --- a/propagation/http_textformat_propagator.go +++ b/propagation/http_textformat_propagator.go @@ -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{} } @@ -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 } @@ -137,7 +139,7 @@ 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, @@ -145,7 +147,7 @@ func (f textFormatInjector) Inject(sc core.SpanContext, tm tag.Map) { 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 } diff --git a/propagation/http_textformat_propagator_test.go b/propagation/http_textformat_propagator_test.go index a0b510e7f9bc..5e95bef3d67f 100644 --- a/propagation/http_textformat_propagator_test.go +++ b/propagation/http_textformat_propagator_test.go @@ -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) } @@ -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 != "" {