Skip to content

Address type erasure/reflection issue #36

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

Merged
merged 3 commits into from
Aug 27, 2020

Conversation

MattWhelan
Copy link
Contributor

This is a pretty broad rewrite, because the former approach cannot work.
TracingRequestHandler's type parameters erase to Object at runtime, which
defeats AWS's reflection-based automatic deserialization mechanism.

The new approach uses composition over inheritance: the user provides their
own event handler, using any mechanism AWS supports, and wraps their
business logic with our instrumentation. This allows reflection to work as
intended.

In addition, the TracingRequestStreamHandler class's doHandler method didn't
allow for IOException to be thrown, despite it being more or less inevitable.
StreamLambdaTracing addresses this issue, while mirroring the design of
LambdaTracing.

Matt Whelan added 2 commits July 30, 2020 10:13
Describes the issue though: AWS can't deserialize the event if it
can't tell what the input type is at runtime. Erasure is preventing
that.
This is a pretty broad rewrite, because the former approach cannot work.
TracingRequestHandler's type parameters erase to `Object` at runtime, which
defeats AWS's reflection-based automatic deserialization mechanism.

The new approach uses composition over inheritance: the user provides their
own event handler, using any mechanism AWS supports, and wraps their
business logic with our instrumentation. This allows reflection to work as
intended.

In addition, the TracingRequestStreamHandler class's doHandler method didn't
allow for IOException to be thrown, despite it being more or less inevitable.
`StreamLambdaTracing` addresses this issue, while mirroring the design of
`LambdaTracing`.
@CLAassistant
Copy link

CLAassistant commented Jul 30, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@jasonjkeller jasonjkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MattWhelan These changes look pretty good to me though I'd like to get input from at least one more person on the team given the scope of the changes.

To what extent have you done end to end testing with the refactored code?

Also, these changes are going to require that we update our usage examples in the tracer project as well as the example application that is provided there.

We're low on bandwidth at the moment but if I can eke out some time I might try to update the example app and do a bit of end to end testing myself, but if it is something you have cycles for please feel free to do so.

Thanks again for the overhaul!

@MattWhelan
Copy link
Contributor Author

I've verified that if you work around the reflection issues, the AWS platform's event deserialization operates correctly. But I haven't actually run a Lambda in AWS with this code. I've just unit tested it.

I may have some cycles later this week to look at the traces docs/examples; at the moment I'm fully committed elsewhere.

@MattWhelan
Copy link
Contributor Author

I did a bit more end to end testing with this (in example code, in yet another repo), and it seems to work well.

I should have some time tomorrow to revise the example code in the tracer. Do you mind if I integrate the API Gateway setup with the SAM template? It's generally best to manage those things together, and keep your API Gateway config under version control.

@jasonjkeller
Copy link
Contributor

@MattWhelan and I talked about his last comment offline. PR to update the example app and readme is here: newrelic/newrelic-lambda-tracer-java#10

Copy link

@breedx-nr breedx-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good...Thanks.

I definitely don't know all the ins and outs of how the aws code uses the lambda implementations...so I could be missing something. I did leave a few questions about how some of the code might could be improved.

README code streamlining, unnesting try blocks, exception error message.
@MattWhelan MattWhelan requested a review from breedx-nr August 27, 2020 17:24
Copy link
Contributor

@jasonjkeller jasonjkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm satisfied with the changes and reasoning for them. LGTM

@jasonjkeller jasonjkeller dismissed breedx-nr’s stale review August 27, 2020 21:31

changes have been addressed

@jasonjkeller jasonjkeller merged commit 8708919 into newrelic:main Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants