@@ -56,6 +56,10 @@ type Handler struct {
5656 // for spans started by this transport.
5757 StartOptions trace.StartOptions
5858
59+ // GetStartOptions allows to set start options per request. If set,
60+ // StartOptions is going to be ignored.
61+ GetStartOptions func (* http.Request ) trace.StartOptions
62+
5963 // IsPublicEndpoint should be set to true for publicly accessible HTTP(S)
6064 // servers. If true, any trace metadata set on the incoming request will
6165 // be added as a linked trace instead of being added as a parent of the
@@ -93,15 +97,21 @@ func (h *Handler) startTrace(w http.ResponseWriter, r *http.Request) (*http.Requ
9397 name = h .FormatSpanName (r )
9498 }
9599 ctx := r .Context ()
100+
101+ startOpts := h .StartOptions
102+ if h .GetStartOptions != nil {
103+ startOpts = h .GetStartOptions (r )
104+ }
105+
96106 var span * trace.Span
97107 sc , ok := h .extractSpanContext (r )
98108 if ok && ! h .IsPublicEndpoint {
99109 ctx , span = trace .StartSpanWithRemoteParent (ctx , name , sc ,
100- trace .WithSampler (h . StartOptions .Sampler ),
110+ trace .WithSampler (startOpts .Sampler ),
101111 trace .WithSpanKind (trace .SpanKindServer ))
102112 } else {
103113 ctx , span = trace .StartSpan (ctx , name ,
104- trace .WithSampler (h . StartOptions .Sampler ),
114+ trace .WithSampler (startOpts .Sampler ),
105115 trace .WithSpanKind (trace .SpanKindServer ),
106116 )
107117 if ok {
0 commit comments