18
18
package core
19
19
20
20
import (
21
+ "fmt"
21
22
"reflect"
22
23
"runtime/debug"
23
24
@@ -55,14 +56,15 @@ func (t *Tracer) CreateEntrySpan(operationName string, extractor interface{}, op
55
56
return tracingSpan , nil
56
57
}
57
58
var ref = & SpanContext {}
58
- if err := ref .Decode (extractor .(tracing.ExtractorWrapper ).Fun ()); err != nil {
59
- return nil , err
59
+ if err1 := ref .Decode (extractor .(tracing.ExtractorWrapper ).Fun ()); err1 != nil {
60
+ return nil , err1
60
61
}
61
62
if ! ref .Valid {
62
63
ref = nil
63
64
}
64
65
65
- return t .createSpan0 (ctx , tracingSpan , opts , withRef (ref ), withSpanType (SpanTypeEntry ), withOperationName (operationName ))
66
+ span , _ , err := t .createSpan0 (ctx , tracingSpan , opts , withRef (ref ), withSpanType (SpanTypeEntry ), withOperationName (operationName ))
67
+ return span , err
66
68
}
67
69
68
70
func (t * Tracer ) CreateLocalSpan (operationName string , opts ... interface {}) (s interface {}, err error ) {
@@ -74,7 +76,8 @@ func (t *Tracer) CreateLocalSpan(operationName string, opts ...interface{}) (s i
74
76
saveSpanToActiveIfNotError (ctx , s , err )
75
77
}()
76
78
77
- return t .createSpan0 (ctx , tracingSpan , opts , withSpanType (SpanTypeLocal ), withOperationName (operationName ))
79
+ span , _ , err := t .createSpan0 (ctx , tracingSpan , opts , withSpanType (SpanTypeLocal ), withOperationName (operationName ))
80
+ return span , err
78
81
}
79
82
80
83
func (t * Tracer ) CreateExitSpan (operationName , peer string , injector interface {}, opts ... interface {}) (s interface {}, err error ) {
@@ -90,14 +93,17 @@ func (t *Tracer) CreateExitSpan(operationName, peer string, injector interface{}
90
93
if tracingSpan != nil && tracingSpan .IsExit () && reflect .ValueOf (tracingSpan ).Type () != snapshotType {
91
94
return tracingSpan , nil
92
95
}
93
- span , err := t .createSpan0 (ctx , tracingSpan , opts , withSpanType (SpanTypeExit ), withOperationName (operationName ), withPeer (peer ))
96
+ span , noop , err := t .createSpan0 (ctx , tracingSpan , opts , withSpanType (SpanTypeExit ), withOperationName (operationName ), withPeer (peer ))
94
97
if err != nil {
95
98
return nil , err
96
99
}
100
+ if noop {
101
+ return span , nil
102
+ }
97
103
spanContext := & SpanContext {}
98
104
reportedSpan , ok := span .(SegmentSpan )
99
105
if ! ok {
100
- return nil , errors .New ("span type is wrong" )
106
+ return nil , errors .New (fmt . Sprintf ( "span type is wrong: %T" , span ) )
101
107
}
102
108
103
109
firstSpan := reportedSpan .GetSegmentContext ().FirstSpan
@@ -246,7 +252,8 @@ func (t *Tracer) createNoop(operationName string) (*TracingContext, TracingSpan,
246
252
return ctx , nil , false
247
253
}
248
254
249
- func (t * Tracer ) createSpan0 (ctx * TracingContext , parent TracingSpan , pluginOpts []interface {}, coreOpts ... interface {}) (s TracingSpan , err error ) {
255
+ func (t * Tracer ) createSpan0 (ctx * TracingContext , parent TracingSpan , pluginOpts []interface {},
256
+ coreOpts ... interface {}) (s TracingSpan , noop bool , err error ) {
250
257
ds := NewDefaultSpan (t , parent )
251
258
var parentSpan SegmentSpan
252
259
if parent != nil {
@@ -262,7 +269,7 @@ func (t *Tracer) createSpan0(ctx *TracingContext, parent TracingSpan, pluginOpts
262
269
sampled := t .Sampler .IsSampled (ds .OperationName )
263
270
if ! sampled {
264
271
// Filter by sample just return noop span
265
- return newNoopSpan (), nil
272
+ return newNoopSpan (), true , nil
266
273
}
267
274
}
268
275
// process the opts from agent core for prepare building segment span
@@ -271,13 +278,13 @@ func (t *Tracer) createSpan0(ctx *TracingContext, parent TracingSpan, pluginOpts
271
278
}
272
279
s , err = NewSegmentSpan (ctx , ds , parentSpan )
273
280
if err != nil {
274
- return nil , err
281
+ return nil , false , err
275
282
}
276
283
// process the opts from plugin, split opts because the DefaultSpan not contains the tracing context information(AdaptSpan)
277
284
for _ , opt := range pluginOpts {
278
285
opt .(tracing.SpanOption ).Apply (s )
279
286
}
280
- return s , nil
287
+ return s , false , nil
281
288
}
282
289
283
290
func withSpanType (spanType SpanType ) tracing.SpanOption {
0 commit comments