Skip to content

Dynamically disable wrapping of servlet types if cast exception happens #138

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 1 commit into from
Dec 2, 2020

Conversation

pavolloffay
Copy link
Member

Signed-off-by: Pavol Loffay p.loffay@gmail.com


if (throwable instanceof ClassCastException) {
ClassCastException cast = (ClassCastException) throwable;
System.out.println(cast.getMessage().contains("hypertrace"));

Choose a reason for hiding this comment

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

Worth to mention why this piece is important? Maybe abstracting "hypertrace" into something meaningful like HYPERTRACE_OWN_PREFIX or something that makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

ignore this code completely this is just a nasty example.

The right solution could parse the class name and store it into the global config. The global config would be used by instrumentation points that create wrappers. If no exception is recorded for the wrapped type the wrapping would be applied.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another interesting fact in this example is the place where the exceptions are caught. In servlet this can be done in exit filter advice. In other frameworks it can be a different place.

The problem also is if the casting would be inside user defined try-catch(Throwable) block, this instrumentation would not catch this. I have tried to define adice for ClassCastException but that does not seem to be triggered.

@pavolloffay pavolloffay force-pushed the intercept-class-cast branch 2 times, most recently from 7d6e5f1 to 34e77ec Compare December 2, 2020 12:21
@pavolloffay pavolloffay changed the title Intercept class cast exceptions Dynamically disable wrapping of servlet types if cast exception happens Dec 2, 2020
}

@Test
public void requestCast() throws Exception {
Copy link
Member Author

Choose a reason for hiding this comment

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

@davexroth @surajpuvvada here is an example of the cast exception. The first request fails, however the second passes but the attributes that are captured via wrappers are omitted. This is the best what we can do.

@pavolloffay pavolloffay marked this pull request as ready for review December 2, 2020 12:25
…appens

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay pavolloffay merged commit b3273de into hypertrace:main Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants