Skip to content

Commit

Permalink
use LinkedTo rather than ChildOf for PublicEndpoint (open-telemetry#272)
Browse files Browse the repository at this point in the history
This causes us to no longer emit missing root spans if we do not have the trace associated with the tracing headers we receive on public endpoints.
  • Loading branch information
lizthegrey authored Nov 4, 2019
1 parent ecf3bb9 commit 9f82c64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type SpanOption func(*SpanOptions)
type SpanOptions struct {
Attributes []core.KeyValue
StartTime time.Time
Links []Link
Relation Relation
Record bool
SpanKind SpanKind
Expand Down Expand Up @@ -197,6 +198,13 @@ func FollowsFrom(sc core.SpanContext) SpanOption {
}
}

// LinkedTo allows instantiating a Span with initial Links.
func LinkedTo(sc core.SpanContext, attrs ...core.KeyValue) SpanOption {
return func(o *SpanOptions) {
o.Links = append(o.Links, Link{sc, attrs})
}
}

// WithSpanKind specifies the role a Span on a Trace.
func WithSpanKind(sk SpanKind) SpanOption {
return func(o *SpanOptions) {
Expand Down
8 changes: 3 additions & 5 deletions plugin/othttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if sc.IsValid() { // not a valid span context, so no link / parent relationship to establish
var opt trace.SpanOption
if h.public {
// TODO: If the endpoint is a public endpoint, it should start a new trace
// and incoming remote sctx should be added as a link
// (WithLinks(links...), this option doesn't exist yet). Replace ChildOf
// below with something like: opt = trace.WithLinks(sc)
opt = trace.ChildOf(sc)
// 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)
} else { // not a private endpoint, so assume child relationship
opt = trace.ChildOf(sc)
}
Expand Down
4 changes: 4 additions & 0 deletions sdk/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti

spanName := tr.spanNameWithPrefix(name)
span := startSpanInternal(tr, spanName, parent, remoteParent, opts)
for _, l := range opts.Links {
span.AddLink(l)
}

span.tracer = tr

if span.IsRecording() {
Expand Down

0 comments on commit 9f82c64

Please sign in to comment.