• /
  • Log in
  • Free account

Trace asynchronous applications

The ability to trace asynchronous segments with the NewGoroutine API is available as of Go agent version 2.6.0. If you do not have version 2.6.0 or higher, update your Go agent to the latest version.


The Transaction.NewGoroutine() Transaction method allows transactions to create segments in multiple goroutines.

NewGoroutine returns a new reference to the Transaction. This must be called any time you are passing the Transaction to another goroutine which makes segments. Each segment-creating goroutine must have its own Transaction reference. It does not matter if you call this before or after the other goroutine has started.

All Transaction methods can be used in any Transaction reference. The Transaction will end when End() is called in any goroutine.

Example passing a new Transaction reference directly to another goroutine:

go func(txn *newrelic.Transaction) {
defer txn.StartSegment("async").End()
time.Sleep(100 * time.Millisecond)

Example passing a new Transaction reference on a channel to another goroutine:

ch := make(chan *newrelic.Transaction)
go func() {
txn := <-ch
defer txn.StartSegment("async").End()
time.Sleep(100 * time.Millisecond)
ch <- txn.NewGoroutine()

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.