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 a74dd31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -35,6 +35,7 @@ https://github.com/elastic/apm-agent-go/compare/v1.8.0...master[View commits]
- Add cloud metadata, configurable with ELASTIC_APM_CLOUD_PROVIDER {pull}823[#(823)]
- Round ELASTIC_APM_SAMPLING_RATE with 4 digits precision {pull}828[#(828)]
- module/apmhttp: implement io.ReaderFrom in wrapped http.ResponseWriter {pull}830[#(830)]
- Fixed Transaction.Discard so that it sets TransactionData to nil {pull}836[#(836)]
[[release-notes-1.x]]
=== Go Agent version 1.x
Expand Down
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 a74dd31

Please sign in to comment.