Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

StartSpanFromContext cannot be used with FollowFromRef #249

Open
nbaztec opened this issue Sep 9, 2021 · 0 comments
Open

StartSpanFromContext cannot be used with FollowFromRef #249

nbaztec opened this issue Sep 9, 2021 · 0 comments

Comments

@nbaztec
Copy link

nbaztec commented Sep 9, 2021

Use Case

Given a parent context, using the following code always results in ChildOfRef:

span, ctx := opentracing.StartSpanFromContext(parentCtx, "foo")

I'd however wish to start a FollowsFromRef from the parent context.

Problem

Using an option doesn't work since the ChildOf() option is appended last and hence takes precedence. Moreover the FollowsFrom() option requires a SpanContext which would be required to be extracted beforehand

// extra (boilerplate) work that would be needed each time 
var opts []StartSpanOption
if parentSpan := SpanFromContext(parentCtx); parentSpan != nil {
	opts = append(opts, FollowsFrom(parentSpan.Context()))
}

// doesn't work either way since the `ChildOf` option takes precedence
// and adds multiple conflicting references to the span
span, ctx := opentracing.StartSpanFromContext(parentCtx, "foo", opts...)

There is no matching function that can start a FollowsFrom span from context.

Proposal

This can be solved via either of two ways:

  1. Add a new function StartFollowsFromSpanFromContext with similar semantics to StartSpanFromContextWithTracer but that creates a FollowsFromRef

or,

  1. Add a StartSpanOption to signal StartSpanFromContextWithTracer to use a FollowsFrom instead of ChildOf

Questions to address (if any)

  • Which one of the solutions best fits the project semantics.
  • If opting for 1., adding a new function for follows from, is minimal code duplication from StartSpanFromContextWithTracer okay?
  • If opting for 2., adding a new option but reusing the same function StartSpanFromContext, the current documentation states that it builds a ChildOfRef - would that qualify as major version API change?
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant