Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use NewRoot() standard code. #513

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions plugin/othttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type Handler struct {
tracer trace.Tracer
props propagation.Propagators
spanStartOptions []trace.StartOption
public bool
readEvent bool
writeEvent bool
}
Expand All @@ -74,7 +73,7 @@ func WithTracer(tracer trace.Tracer) Option {
// association instead of a link.
func WithPublicEndpoint() Option {
return func(h *Handler) {
h.public = true
h.spanStartOptions = append(h.spanStartOptions, trace.WithNewRoot())
}
}

Expand All @@ -91,7 +90,7 @@ func WithPropagators(ps propagation.Propagators) Option {
// trace.StartOptions, which are applied to each new span.
func WithSpanOptions(opts ...trace.StartOption) Option {
return func(h *Handler) {
h.spanStartOptions = opts
h.spanStartOptions = append(h.spanStartOptions, opts...)
}
}

Expand Down Expand Up @@ -153,20 +152,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// TODO: do something with the correlation context
ctx := propagation.ExtractHTTP(r.Context(), h.props, r.Header)

// not a valid span context, so no link / parent relationship to establish
if sc := trace.RemoteSpanContextFromContext(ctx); sc.IsValid() {
var opt trace.StartOption
if h.public {
// If the endpoint is a public endpoint, it should start a new trace
// and incoming remote sctx should be added as a link.
opt = trace.LinkedTo(sc)
opts = append(opts, opt)
} else { // not a private endpoint, so assume child relationship
ctx = trace.ContextWithRemoteSpanContext(ctx, sc)
}
}

ctx, span := h.tracer.Start(ctx, h.operation, opts...)
defer span.End()

Expand Down