1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-06-04 23:07:40 +02:00

use LinkedTo rather than ChildOf for PublicEndpoint (#272)

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.
This commit is contained in:
Liz Fong-Jones 2019-11-04 14:03:40 +01:00 committed by GitHub
parent ecf3bb9d7c
commit 9f82c642f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -103,6 +103,7 @@ type SpanOption func(*SpanOptions)
type SpanOptions struct { type SpanOptions struct {
Attributes []core.KeyValue Attributes []core.KeyValue
StartTime time.Time StartTime time.Time
Links []Link
Relation Relation Relation Relation
Record bool Record bool
SpanKind SpanKind SpanKind SpanKind
@ -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. // WithSpanKind specifies the role a Span on a Trace.
func WithSpanKind(sk SpanKind) SpanOption { func WithSpanKind(sk SpanKind) SpanOption {
return func(o *SpanOptions) { return func(o *SpanOptions) {

View File

@ -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 if sc.IsValid() { // not a valid span context, so no link / parent relationship to establish
var opt trace.SpanOption var opt trace.SpanOption
if h.public { if h.public {
// TODO: If the endpoint is a public endpoint, it should start a new trace // If the endpoint is a public endpoint, it should start a new trace
// and incoming remote sctx should be added as a link // and incoming remote sctx should be added as a link.
// (WithLinks(links...), this option doesn't exist yet). Replace ChildOf opt = trace.LinkedTo(sc)
// below with something like: opt = trace.WithLinks(sc)
opt = trace.ChildOf(sc)
} else { // not a private endpoint, so assume child relationship } else { // not a private endpoint, so assume child relationship
opt = trace.ChildOf(sc) opt = trace.ChildOf(sc)
} }

View File

@ -60,6 +60,10 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
spanName := tr.spanNameWithPrefix(name) spanName := tr.spanNameWithPrefix(name)
span := startSpanInternal(tr, spanName, parent, remoteParent, opts) span := startSpanInternal(tr, spanName, parent, remoteParent, opts)
for _, l := range opts.Links {
span.AddLink(l)
}
span.tracer = tr span.tracer = tr
if span.IsRecording() { if span.IsRecording() {