go-agent icon indicating copy to clipboard operation
go-agent copied to clipboard

Support disable ending the transaction by middleware integration

Open tanaka-takayoshi opened this issue 3 years ago • 1 comments

Summary

I'm filing this request on behalf of the customer. As described in #382, we usually face the transaction has already ended error when instrumenting async (goroutine) function. This is because the transaction has been ended when the transaction method is ended before async function is ended.

Desired Behaviour

When instrumenting async (goroutine) func, our document provides the following example.

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

Typically, the transaction (txn) is generated by middleware integration such as nrecho. These integrations end the transaction when the transaction method is ended. Assuming that async function is running longer than the transaction method, the transaction is completed before async function is ended. Therefore, async function can not be instrumented as a part of the transaction.

Users sometimes want to instrument async function as a part of the transaction.

Possible Solution

Currently, we only have a tricky workaround. If the agent API support disabling ending the transaction automatically and the async function can complete the transaction, it helps instrument async function.

Additional context

tanaka-takayoshi avatar Nov 05 '21 14:11 tanaka-takayoshi

Hi @tanaka-takayoshi , you're right, we could provide this as an option to keep the agent from disabling the ending of transactions, just as long as it was used carefully with these things in mind:

  • If the async function exits before it is able to end the transaction, the entire transaction will be invisible to New Relic.
  • The response time in the APM UI's overview page will most likely be incorrect, as will the Apdex of the application.
  • Multiple async functions would complicate this scenario -- which async function gets to declare the transaction is over?

Making sure this option isn't misused by customers will require extra attention from us in documentation and putting whatever safeguards we can imagine in place. We'd love your input on these issues!

@ak-war Possible feature request.

RichVanderwal avatar Jan 18 '22 23:01 RichVanderwal