@@ -47,6 +47,7 @@ type Daemon struct {
47
47
receiverCount int
48
48
processorCount int
49
49
receiveBufferSize int
50
+ enableTelemetry bool
50
51
51
52
// Boolean channel, set to true if error is received reading from Socket.
52
53
done chan bool
@@ -134,7 +135,12 @@ func initDaemon(config *cfg.Config, enableTelemetry bool) *Daemon {
134
135
log .Infof ("Using region: %v" , aws .StringValue (awsConfig .Region ))
135
136
136
137
if enableTelemetry {
138
+ // Telemetry can be quite verbose, for example 10+ PutTelemetryRecords requests for a single invocation
137
139
telemetry .Init (awsConfig , session , config .ResourceARN , noMetadata )
140
+ } else {
141
+ // Telemetry cannot be nil because it is used internally in the X-Ray daemon, for example in batchprocessor.go
142
+ // We assume that SegmentReceived is never invoked internally in X-Ray because it enables postTelemetry.
143
+ telemetry .T = telemetry .GetTestTelemetry ()
138
144
}
139
145
140
146
// If calculated number of buffer is lower than our default, use calculated one. Otherwise, use default value.
@@ -152,6 +158,7 @@ func initDaemon(config *cfg.Config, enableTelemetry bool) *Daemon {
152
158
receiverCount : parameterConfig .ReceiverRoutines ,
153
159
processorCount : processorCount ,
154
160
receiveBufferSize : receiveBufferSize ,
161
+ enableTelemetry : enableTelemetry ,
155
162
done : make (chan bool ),
156
163
std : std ,
157
164
pool : bufferPool ,
@@ -180,12 +187,12 @@ func (d *Daemon) close() {
180
187
// Signal routines to finish
181
188
// This will push telemetry and customer segments in parallel
182
189
d .std .Close ()
183
- if telemetry . T != nil {
190
+ if d . enableTelemetry {
184
191
telemetry .T .Quit <- true
185
192
}
186
193
187
194
<- d .processor .Done
188
- if telemetry . T != nil {
195
+ if d . enableTelemetry {
189
196
<- telemetry .T .Done
190
197
}
191
198
@@ -231,7 +238,7 @@ func (d *Daemon) poll() {
231
238
fallbackPointerUsed = true
232
239
}
233
240
rlen := d .read (bufPointer )
234
- if rlen > 0 && telemetry . T != nil {
241
+ if rlen > 0 && d . enableTelemetry {
235
242
telemetry .T .SegmentReceived (1 )
236
243
}
237
244
if rlen == 0 {
@@ -242,7 +249,7 @@ func (d *Daemon) poll() {
242
249
}
243
250
if fallbackPointerUsed {
244
251
log .Warn ("Segment dropped. Consider increasing memory limit" )
245
- if telemetry . T != nil {
252
+ if d . enableTelemetry {
246
253
telemetry .T .SegmentSpillover (1 )
247
254
}
248
255
continue
@@ -257,7 +264,7 @@ func (d *Daemon) poll() {
257
264
if len (slices [1 ]) == 0 {
258
265
log .Warnf ("Missing header or segment: %s" , string (slices [0 ]))
259
266
d .pool .Return (bufPointer )
260
- if telemetry . T != nil {
267
+ if d . enableTelemetry {
261
268
telemetry .T .SegmentRejected (1 )
262
269
}
263
270
continue
@@ -273,7 +280,7 @@ func (d *Daemon) poll() {
273
280
default :
274
281
log .Warnf ("Invalid header: %s" , string (header ))
275
282
d .pool .Return (bufPointer )
276
- if telemetry . T != nil {
283
+ if d . enableTelemetry {
277
284
telemetry .T .SegmentRejected (1 )
278
285
}
279
286
continue
0 commit comments