@@ -261,10 +261,12 @@ func parseIP(ip string) string {
261261func (i * Instrumentation ) ExportSpans (ctx context.Context , nSpans int ) ExportOp {
262262 start := time .Now ()
263263
264- addOpt := get [metric.AddOption ](addOptPool )
265- defer put (addOptPool , addOpt )
266- * addOpt = append (* addOpt , i .addOpt )
267- i .inflightSpans .Add (ctx , int64 (nSpans ), * addOpt ... )
264+ if i .inflightSpans .Enabled (ctx ) {
265+ addOpt := get [metric.AddOption ](addOptPool )
266+ defer put (addOptPool , addOpt )
267+ * addOpt = append (* addOpt , i .addOpt )
268+ i .inflightSpans .Add (ctx , int64 (nSpans ), * addOpt ... )
269+ }
268270
269271 return ExportOp {
270272 ctx : ctx ,
@@ -299,14 +301,18 @@ func (e ExportOp) End(err error, status int) {
299301 defer put (addOptPool , addOpt )
300302 * addOpt = append (* addOpt , e .inst .addOpt )
301303
302- e .inst .inflightSpans .Add (e .ctx , - e .nSpans , * addOpt ... )
304+ if e .inst .inflightSpans .Enabled (e .ctx ) {
305+ e .inst .inflightSpans .Add (e .ctx , - e .nSpans , * addOpt ... )
306+ }
303307
304308 success := successful (e .nSpans , err )
305309 // Record successfully exported spans, even if the value is 0 which are
306310 // meaningful to distribution aggregations.
307- e .inst .exportedSpans .Add (e .ctx , success , * addOpt ... )
311+ if e .inst .exportedSpans .Enabled (e .ctx ) {
312+ e .inst .exportedSpans .Add (e .ctx , success , * addOpt ... )
313+ }
308314
309- if err != nil {
315+ if err != nil && e . inst . exportedSpans . Enabled ( e . ctx ) {
310316 attrs := get [attribute.KeyValue ](measureAttrsPool )
311317 defer put (measureAttrsPool , attrs )
312318 * attrs = append (* attrs , e .inst .attrs ... )
@@ -321,12 +327,14 @@ func (e ExportOp) End(err error, status int) {
321327 e .inst .exportedSpans .Add (e .ctx , e .nSpans - success , * addOpt ... )
322328 }
323329
324- recOpt := get [metric.RecordOption ](recordOptPool )
325- defer put (recordOptPool , recOpt )
326- * recOpt = append (* recOpt , e .inst .recordOption (err , status ))
330+ if e .inst .opDuration .Enabled (e .ctx ) {
331+ recOpt := get [metric.RecordOption ](recordOptPool )
332+ defer put (recordOptPool , recOpt )
333+ * recOpt = append (* recOpt , e .inst .recordOption (err , status ))
327334
328- d := time .Since (e .start ).Seconds ()
329- e .inst .opDuration .Record (e .ctx , d , * recOpt ... )
335+ d := time .Since (e .start ).Seconds ()
336+ e .inst .opDuration .Record (e .ctx , d , * recOpt ... )
337+ }
330338}
331339
332340// recordOption returns a RecordOption with attributes representing the
0 commit comments