Commit 1bf31ca 1 parent 76881bf commit 1bf31ca Copy full SHA for 1bf31ca
File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -136,12 +136,18 @@ func (s *spanImpl) FinishWithOptions(opts opentracing.FinishOptions) {
136
136
137
137
s .onFinish (s .raw )
138
138
s .tracer .options .Recorder .RecordSpan (s .raw )
139
+
140
+ // Last chance to get options before the span is possbily reset.
141
+ poolEnabled := s .tracer .options .EnableSpanPool
139
142
if s .tracer .options .DebugAssertUseAfterFinish {
140
143
// This makes it much more likely to catch a panic on any subsequent
141
144
// operation since s.tracer is accessed on every call to `Lock`.
142
145
s .reset ()
143
146
}
144
- spanPool .Put (s )
147
+
148
+ if poolEnabled {
149
+ spanPool .Put (s )
150
+ }
145
151
}
146
152
147
153
func (s * spanImpl ) SetBaggageItem (restrictedKey , val string ) opentracing.Span {
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ type Options struct {
73
73
// When set, it attempts to exacerbate issues emanating from use of Spans
74
74
// after calling Finish by running additional assertions.
75
75
DebugAssertUseAfterFinish bool
76
+ // EnableSpanPool enables the use of a pool, so that the tracer reuses spans
77
+ // after Finish has been called on it. Adds a slight performance gain as it
78
+ // reduces allocations. However, if you have any use-after-finish race
79
+ // conditions the code may panic.
80
+ EnableSpanPool bool
76
81
}
77
82
78
83
// DefaultOptions returns an Options object with a 1 in 64 sampling rate and
@@ -122,9 +127,12 @@ func (t *tracerImpl) StartSpan(
122
127
}
123
128
124
129
func (t * tracerImpl ) getSpan () * spanImpl {
125
- sp := spanPool .Get ().(* spanImpl )
126
- sp .reset ()
127
- return sp
130
+ if t .options .EnableSpanPool {
131
+ sp := spanPool .Get ().(* spanImpl )
132
+ sp .reset ()
133
+ return sp
134
+ }
135
+ return & spanImpl {}
128
136
}
129
137
130
138
func (t * tracerImpl ) StartSpanWithOptions (
You can’t perform that action at this time.
0 commit comments