Skip to content

Commit

Permalink
Transaction.Discard sets TransactionData to nil
Browse files Browse the repository at this point in the history
Fix Transaction.Discard so that it sets TransactionData
to nil, like its documentation says. This is necessary
to avoid Transaction.End from enqueuing a transaction
after it has been discarded.
  • Loading branch information
axw committed Oct 20, 2020
1 parent e50bbbd commit e526943
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions transaction.go
Expand Up @@ -246,6 +246,7 @@ func (tx *Transaction) Discard() {
return
}
tx.reset(tx.tracer)
tx.TransactionData = nil
}

// End enqueues tx for sending to the Elastic APM server.
Expand Down
14 changes: 14 additions & 0 deletions transaction_test.go
Expand Up @@ -300,6 +300,20 @@ func TestTransactionSampleRateOmission(t *testing.T) {
}
}

func TestTransactionDiscard(t *testing.T) {
tracer, transport := transporttest.NewRecorderTracer()
defer tracer.Close()

tx := tracer.StartTransaction("name", "type")
tx.Discard()
assert.Nil(t, tx.TransactionData)
tx.End() // ending after discarding should be a no-op

tracer.Flush(nil)
payloads := transport.Payloads()
require.Empty(t, payloads)
}

func BenchmarkTransaction(b *testing.B) {
tracer, err := apm.NewTracer("service", "")
require.NoError(b, err)
Expand Down

0 comments on commit e526943

Please sign in to comment.