Skip to content

Resteasy support#234

Closed
avram wants to merge 8 commits into
DataDog:masterfrom
scopely:features/resteasy
Closed

Resteasy support#234
avram wants to merge 8 commits into
DataDog:masterfrom
scopely:features/resteasy

Conversation

@avram
Copy link
Copy Markdown

@avram avram commented Feb 16, 2018

  • Adds scope manager for JAX-RS when running outside of servlet
  • Separates JAX-RS tests for different frameworks due to clashing implementations of JAX-RS APIs

While the Resteasy integration probably works under Java 7, I've excluded it from test runs because the tests fail.

@avram
Copy link
Copy Markdown
Author

avram commented Feb 16, 2018

Unclear why CI didn't run again; maybe it was getting tired of running and failing.

The last issue was Java 7 support in the tests, which I just gave up on.

@tylerbenson
Copy link
Copy Markdown
Contributor

Thanks for your contribution.

It's not really clear from reading your PR... was there something wrong with the existing JAX-RS instrumentation that it wasn't working for V2 or resteasy, or were you mainly adding a test suite?

@avram
Copy link
Copy Markdown
Author

avram commented Feb 16, 2018

@tylerbenson Without the new filter that I added, we weren't getting a parent scope at all when using Netty.

@avram avram force-pushed the features/resteasy branch from 1b8497f to f946a25 Compare February 17, 2018 01:21
@avram
Copy link
Copy Markdown
Author

avram commented Feb 17, 2018

I've re-run the tests and they now pass without issue.

@tylerbenson
Copy link
Copy Markdown
Contributor

tylerbenson commented Feb 17, 2018

Ah, I see... my instrumentation was focused on naming. It assumes you are using servlets which generates it's own trace/span. Later, when we add instrumentation for Netty, it should work correctly.

How does this PR improve things? I don't see additional instrumentation. Does OpenTracingFilter just automatically get picked up because it's on the classpath? Any issues if you're using a weird setup (Spring Boot Executable Jar) that doesn't have the application code on the system classpath?

@avram
Copy link
Copy Markdown
Author

avram commented Feb 18, 2018

In my usage and in the test included here,OpenTracingFilter is explicitly registered, so the parent span is created by that filter. Usually there is some discovery or explicit provider registration stage; all of our applications explicitly enumerate the filters they are using when initializing Resteasy. I can't say for sure that there are no JAX-RS implementations out there that would automatically pick up this filter if it is on the classpath; I can only comment on Resteasy. Even if they did pick it up, it only creates the parent scope if there is not already an established scope, so it would be quite harmless.

Explicit registration:

deployment.setActualProviderClasses(Collections.singletonList(OpenTracingFilter))

Copy link
Copy Markdown
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

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

See comments above.

import javax.ws.rs.ext.Provider;

@Provider
public final class OpenTracingFilter implements ContainerRequestFilter, ContainerResponseFilter {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you provide a class comment here describing the purpose and (since it's not explicit) how it gets picked up?

Comment thread settings.gradle
include ':dd-java-agent:benchmark-integration:jetty-perftest'

// Resteasy integration test requires Java 8+
include ':dd-java-agent:instrumentation:jax-rs:resteasy'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of excluding the whole project, exclude just the test by doing something like this: https://github.com/DataDog/dd-trace-java/blob/master/dd-trace-ot/dd-trace-ot.gradle#L21-L30


dependencies {
compileOnly group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather not have both on the classpath to avoid confusion. Can this line be removed?

compile project(':dd-trace-ot')
compile project(':dd-java-agent:agent-tooling')

testCompile project(':dd-java-agent:testing')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you leave JaxRsInstrumentationTest.groovy in this project and only move the jersey specific portion?

final Scope scope = tracer.scopeManager().active();
if (scope == null) {
final Span span = tracer.buildSpan("request-parent").start();
tracer.scopeManager().activate(span, true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the reason for activating the span in the scope manager (on the thread)? Since netty is async, this seems like a dangerous proposition. Perhaps this would be a good opportunity to explore the new API for ScopeMangers that I'm proposing: #233.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll look into it. I haven't really looked into what it means to "activate" a span, so perhaps this is a bit misguided.

Since the complexity could also be driven by multithreaded access, I can also extend my Netty test coverage to try to stress the tracing more; plenty of naïve patterns will look workable in simple tests like we have here.

I can also put the PR on hold until we've had a chance to try the scope-annotating filter in our larger deployments (~1.5M RPM); the existing JAX-RS support should work for us in the meantime if I just add the filter to our internal codebase.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's fine. Just ping me when you're ready to revisit. I'll leave the PR open for now. Thanks for the contribution.

@tylerbenson tylerbenson added the tag: do not merge Do not merge changes label Feb 21, 2018
@realark realark closed this Apr 26, 2018
@tylerbenson tylerbenson added this to the Closed milestone Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: do not merge Do not merge changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants