You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature request proposes adding a new method to the New Relic Go agent's Transaction object that allows developers to check if a transaction has been ended.
Desired Behaviour
Currently, there is no way to directly determine if a transaction has been ended, especially when the End() call is made in a separate goroutine. This can lead to uncertainty and potential issues in tracking the status of transactions.
The desired behavior is to have a method, such as IsEnded(), that returns a boolean value indicating whether the End() method has been called on the transaction. This would allow developers to reliably check the transaction's status and handle it accordingly.
For example:
txn:=newrelic.FromContext(r.Context())
//... some code...gofunc() {
//... some code...txn.End()
}()
//... some code...iftxn.IsEnded() {
// Transaction has ended
} else {
// Transaction is still active
}
Possible Solution
Examining the current Transaction struct reveals a finished boolean field within the nested txn struct, which appears to track the transaction's end state.
typeTransactionstruct {
Privateanythread*thread
}
typethreadstruct {
*txn// ... other fields
}
typetxnstruct {
// ... other fieldsfinishedbool// ... other fields
}
Leveraging this existing field, the IsEnded() method could be implemented as follows:
This method first handles potential nil cases to prevent panics and then directly accesses the finished field to provide the desired functionality.
Additional context
This feature is important for applications that heavily rely on asynchronous processing and goroutines. In such scenarios, it can be difficult to keep track of the status of transactions, and the proposed method would provide a clear and reliable way to do so. This would help in debugging, ensuring proper transaction completion, and managing resources effectively.
The text was updated successfully, but these errors were encountered:
Summary
This feature request proposes adding a new method to the New Relic Go agent's
Transaction
object that allows developers to check if a transaction has been ended.Desired Behaviour
Currently, there is no way to directly determine if a transaction has been ended, especially when the
End()
call is made in a separate goroutine. This can lead to uncertainty and potential issues in tracking the status of transactions.The desired behavior is to have a method, such as
IsEnded()
, that returns a boolean value indicating whether theEnd()
method has been called on the transaction. This would allow developers to reliably check the transaction's status and handle it accordingly.For example:
Possible Solution
Examining the current
Transaction
struct reveals afinished
boolean field within the nestedtxn
struct, which appears to track the transaction's end state.Leveraging this existing field, the
IsEnded()
method could be implemented as follows:This method first handles potential nil cases to prevent panics and then directly accesses the
finished
field to provide the desired functionality.Additional context
This feature is important for applications that heavily rely on asynchronous processing and goroutines. In such scenarios, it can be difficult to keep track of the status of transactions, and the proposed method would provide a clear and reliable way to do so. This would help in debugging, ensuring proper transaction completion, and managing resources effectively.
The text was updated successfully, but these errors were encountered: