Spark Java Framework Instrumentation#254
Conversation
There was a problem hiding this comment.
You're also going to want to add instrumentation for spark specifically to set the resource name for a request. This is similar to what I'm doing in the spring web instrumentation. So for example, on this line, the resource name should be GET /param/:param, regardless of what the parameter is.
Unfortunately Spark doesn't seem to be a great spot for this. Maybe getTarget()? When it is called, get the matchUri value? That doesn't have the HTTP method though.
Other ideas?
There was a problem hiding this comment.
This doesn't need to be copied in both places. I'd suggest removing this class.
There was a problem hiding this comment.
Instead say, sparkjava uses servlet filters under the covers, so we want to include that instrumentation here for verification.
There was a problem hiding this comment.
Remove these lines and replace with a dependency on sparkjava (the earliest version the instrumentation supports), then rename the project to match sparkjava-<version>.
There was a problem hiding this comment.
While I don't love it, it does seem this is a best way to generically cover what you need. The other option might be to instrument Jetty's Handler.handle interface. Which do you think is better?
There was a problem hiding this comment.
Looking at the Jetty handler interface, I like that a lot more. I think that will fit better and have less edge cases like the Filter has.
Should that go in a seperate package "jetty"?
There was a problem hiding this comment.
Since this span could come from a potentially large number of classes, I'd like to have something to trace it back to the origin. Please add a tag with the class name like so:
.withTag("span.origin.type", statement.getClass().getName());
Would you mind also adding that to the other servlet-{2,3} instrumentation as well?
Thanks!
There was a problem hiding this comment.
What is statement here? Cannot find it, and nothing logically matches.
There was a problem hiding this comment.
Sorry that was copy paste from the statement instrumentation. For jetty instrumentation it would be this.getClass().
There was a problem hiding this comment.
once you have the instrumentation working, I'd like to see this test suite include deeper verification and some edge cases. Use this for inspiration.
|
Also, it appears spark dropped support for Java 7 in 2.0, so if we don't plan on supporting anything before then, you can exclude the tests from running on java 7 by doing this, except change the check to |
|
Thanks for the good feedback. I do see that I have messed up a bit, so I want to clear some things up. I had the impression that blindly adding instrumentation for Does my view match your understanding? Or would having the Right now there are two "identical" files. EDIT: saw your specific comment about this, will remove! |
There was a problem hiding this comment.
What are all these opentracing things used for?
|
I have made some changes now.
Once the overall structure is ok, I'll take another look at the tests etc. |
|
I have attempted to use google java format in the project, but the verification step still fails. Any tips? |
|
There’s a gradle task you can run to format everything. I think it’s googleFormatJava or something like that. |
tylerbenson
left a comment
There was a problem hiding this comment.
I am ok with the approach. Needs some polish and more testing on both the jetty and spark side. Let me know if you get stuck. Thanks for working through this. I hope it’s interesting for you.
There was a problem hiding this comment.
This part is a bit confusing and poorly documented. We use this to make sure we are only instrumenting classes we expect it to work on. Please update the group and module for jetty. You can remove the legacy part.
There was a problem hiding this comment.
I think this jetty hook requires the Async things from servlet?
There was a problem hiding this comment.
We might still want to check if there is an active trace and return early to avoid duplicate traces if the existing servlet instrumentation applies.
There was a problem hiding this comment.
Change to isJava8Compatible()
There was a problem hiding this comment.
The main reason for adding this line is to limit the versions of the sparkjava library we try to instrument. This list should match the verifyPresent block in a versionScan in the gradle file.
There was a problem hiding this comment.
Added version scan for sparkjava as well.
There was a problem hiding this comment.
Standard practice. Since this is new instrumentation, can you override the default enabled method to return false? We will change to enabled by default in a future release. Same applies to the spark instrumentation.
There was a problem hiding this comment.
Any reason this instrumentation wouldn’t work with older versions of jetty? We usually name the instrumentation with the earliest version it can support.
There was a problem hiding this comment.
Added support for oldest 8.0.0 where signature is the same for Handler.
|
I will work on some tests later this week. |
There was a problem hiding this comment.
This version range should match the version for the instrumentation, so in this case [ 8.0.0.v20110901,).
There was a problem hiding this comment.
This version range should match the version for the instrumentation, so in this case [ 2.5,).
There was a problem hiding this comment.
These classes are probably not what you need, unless 8.0 was the first version to support Servlet 3.
There was a problem hiding this comment.
Looks like that is in fact the case: https://wiki.eclipse.org/Jetty/Starting/Jetty_Version_Comparison_Table. Carry on.
There was a problem hiding this comment.
Was this class newly added in 2.5 and available in all following versions?
There was a problem hiding this comment.
I think I'd like to see this as a setupSpec() method with a corresponding cleanupSpec() method to shut it down. (Is it possible to shut down programmatically?)
There was a problem hiding this comment.
I think this would look nicer if span.context() was declared as a variable and maybe even the tags.
There was a problem hiding this comment.
Partially fixed by extracting to a variable.
|
After a clean build, I think this is mostly ready. I'm going to pass over to @realark for secondary review. |
|
My problem right now is that the basic test does not work. I think this is because my understanding of how to activate the instrumentation is wrong. Since the tests are failing, we can't verify if it works. Since |
|
In the latest commit, we can observe that Spark is started in the tests, however no traces are registered, thus our tests don't work. How can we activate tracing for the default disabled instrumentation? |
There was a problem hiding this comment.
Looks like this instrumentation is only intended to apply to Java 8 and above, correct? If so, I think we have a problem. Attempting to load a 1.8 class on a 1.7 jvm, will cause an exception to be thrown when we initialize the instrumentation.
@JorgenG There's nothing for you to do about this (unless you can change source and target compatibility to 1.7?). @tylerbenson and I will have to figure out a solution. I'm sure we'll want to do this often, especially as more frameworks are compiled against newer jvms.
There was a problem hiding this comment.
Maybe we could configure the tests to be Java 8 but leave the instrumentation at Java 7?
|
@JorgenG You can enable the instrumentation in the test using a static initializer to set the system property. I think you'll want something like this: |
realark
left a comment
There was a problem hiding this comment.
I think the PR looks good once the tests are enabled.
I'm good to merge after we figure out the java 1.7 issue.
|
Attempted to add the enabling of instrumentation in tests, not able to get it working. I am leaving for two weeks vacation on thursday, and will be back at beginning of April. Will not be able to do any contributions during this time, so if you are able to provide support on getting the tests running that would be nice. |
|
@JorgenG Thanks for your patience while we work on unblocking you. We're still working on a solution for Java 8 instrumentation, but we'll let you know as soon as we can get this merged. |
…being loaded properly
and rebase off master.
| import java.lang.reflect.Field | ||
|
|
||
| @Timeout(1) | ||
| @Timeout(10) |
|
Looks good! |
|
@JorgenG Thanks for your contribution. Glad we could finally get this merged. Sorry for the delay. |
|
Thanks for all the help, and happy to see it getting in. 👍 |
This is a WIP of looking into sparkjava support.