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

Bump OT to 0.30.0 #36

Merged
merged 5 commits into from
Jun 21, 2017

Conversation

pavolloffay
Copy link
Collaborator

No description provided.

@@ -59,7 +57,8 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
spanBuilder.asChildOf(extractedSpanContext);
}

Span span = spanBuilder.start();
Span span = spanBuilder.startManual();
tracer.makeActive(span);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is ugly and the reason for this is that in async requests the thread in response filter is different and active span cannot be deactivated/finished: https://github.com/opentracing/opentracing-java/blob/master/opentracing-util/src/main/java/io/opentracing/util/ThreadLocalActiveSpan.java#L50.

The most ideal solution would be to instrument ExecutorService/or something like onAsync but I could not find a way how to do it in jax-rs.

Other options:

  1. do not activate at all (not wanted)
  2. create "manual" span and activate explicitly.
  3. activate only for sync requests. (this is Brave doing https://github.com/pavolloffay/brave/blob/629a7da8d8e650124918b0e613b68bedd39cef34/instrumentation/jaxrs2/src/main/java/brave/jaxrs2/TracingContainerFilter.java#L74-L74)

cc @jpkrohling @objectiser

Copy link

@malafeev malafeev Jun 20, 2017

Choose a reason for hiding this comment

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

tracer.makeActive(span); - will make span active forever? (if thread is not destroyed because it is taken from thread pool and returned back). So you also need to deactivate span explicitly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@malafeev exactly, I think 3. is the most consistent solution. If we cannot deactivate span then do not activate. I'm wondering what other people think about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried using a continuation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean e.g. could you outline possible solution? What should be done in request and response filters.

Copy link
Contributor

Choose a reason for hiding this comment

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

One possible approach would be to replace in the request filter requestContext.setProperty(SPAN_PROP_ID, new SpanWrapper(span)); by a request context property that stores the Continuation returned from span.capture() - and on a following line do span.deactivate().

Then in the response filter retrieve the Continuation and activate it to retrieve the active span which can then be deactivated at the end of the method.

Copy link

@malafeev malafeev Jun 20, 2017

Choose a reason for hiding this comment

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

@objectiser if span is deactivated in request filter then during processing of request (before response filter) span will not be picked up as parent span. In such case there is no sense to activate/deactivate span.
For example:

  1. Client send request
  2. Server Endpoint send another REST request. Here we should get active span from request filter to use as parent for new REST request.
  3. Server send response

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One possible approach would be to replace in the request filter requestContext.setProperty(SPAN_PROP_ID, new SpanWrapper(span)); by a request context property that stores the Continuation returned from span.capture() - and on a following line do span.deactivate().

Then in the response filter retrieve the Continuation and activate it to retrieve the active span which can then be deactivated at the end of the method.

As @malafeev said this does not make sense, we could simply use Span and just finish it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah was forgetting about the child spans :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@pavolloffay Would be worth creating an issue on opentracing-java to see if a general solution can be found.

protected Client getClient() {
return new ResteasyClientBuilder()
/**
* To awoid RESTEASY004655 "connection is still allocated" in {@link #testAsyncMultipleRequests()}
Copy link
Contributor

Choose a reason for hiding this comment

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

s/awoid/avoid

@pavolloffay
Copy link
Collaborator Author

PR updated.

Based on discussion with @jpkrohling, span is activated only in sync requests, because we should make sure that the span can be properly deactivated.

@pavolloffay
Copy link
Collaborator Author

@jpkrohling @objectiser could you please re-review? Or is it good to go?

README.md Outdated
### Async
Async requests are executed in a different thread than when the client has been invoked, therefore
spans representing client requests are not connected to appropriate parent. To fix this JAX-RS client
has to use OpenTracing-aware `ExecutorService`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to provide a reference to java-concurrent.

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, TracedExecutorService is used in a code snippet below but there is no clue for user where to find it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1 will add

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Link added, actually that dependency is pulled by default so users would find it.

@pavolloffay pavolloffay merged commit 8bb54f8 into opentracing-contrib:master Jun 21, 2017
@pavolloffay
Copy link
Collaborator Author

@jpkrohling @objectiser thanks

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.

4 participants