Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing nrlambda.Wrap and newrelic.WrapHandle #638

Open
rittneje opened this issue Feb 4, 2023 · 0 comments
Open

Mixing nrlambda.Wrap and newrelic.WrapHandle #638

rittneje opened this issue Feb 4, 2023 · 0 comments

Comments

@rittneje
Copy link
Contributor

rittneje commented Feb 4, 2023

Summary

We are trying to build an adapter for our API Gateway proxy request lambdas to convert them into Go's net/http framework. That way we can share more of our framework code regardless of whether the application is serverless.

Unfortunately, we have encountered a bit of a snag with the way this library handles transactions. At the top level, the desire is to use nrlambda.Wrap, which will automatically start a transaction where the name is the function name. However, after we've adapted the incoming request into the net/http framework, we'd like to leverage newrelic.WrapHandle as part of the common routing logic. The issue is that newrelic.WrapHandle just directly starts a transaction no matter what is already in the context, so we would end up with two separate transactions for one request.

Desired Behaviour

There should only be one transaction.

Possible Solution

Perhaps newrelic.WrapHandle could be amended to simply call Transaction.SetName and Transaction.SetOption if there is already a transaction in the request's context?

The trickier part is Transaction.SetWebResponse. My assumption is that wrapping an already wrapped ResponseWriter will cause weird issues, and if newrelic.WrapHandle isn't the one that started the transaction, it has no way in general of knowing if it was already wrapped.

We can also go do our own custom thing instead of using newrelic.WrapHandle, but it would be desirable not to have to do that.

We could also skip calling nrlambda.Wrap, but it's nice to have the attributes like AWS request ID automatically included, and it's also nice to not mandate the use of newrelic.WrapHandle as developers may not bother if the lambda function only has one endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant