-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use active span as parent if exists (#74)
* using active span (probably initialized in preceeding filter) if exists instead of extracting from http headers * readbility improvement of parentSpan method * test for resolving parent span in case it already exists * added tests to cxf and resteasy providers
- Loading branch information
1 parent
f3d52a4
commit 1ead39f
Showing
5 changed files
with
143 additions
and
15 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
.../test/java/io/opentracing/contrib/jaxrs2/itest/cxf/ApacheCXFParentSpanResolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.opentracing.contrib.jaxrs2.itest.cxf; | ||
|
||
import io.opentracing.contrib.jaxrs2.itest.common.AbstractParentSpanResolutionTest; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
||
public class ApacheCXFParentSpanResolutionTest extends AbstractParentSpanResolutionTest { | ||
|
||
@Override | ||
protected void initServletContext(ServletContextHandler context) { | ||
super.initServletContext(context); | ||
ApacheCXFHelper.initServletContext(context); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...ain/java/io/opentracing/contrib/jaxrs2/itest/common/AbstractParentSpanResolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.opentracing.contrib.jaxrs2.itest.common; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
|
||
import io.opentracing.Scope; | ||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.tag.Tags; | ||
import org.eclipse.jetty.servlet.FilterHolder; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.EnumSet; | ||
import java.util.List; | ||
|
||
import javax.servlet.*; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.Response; | ||
|
||
public abstract class AbstractParentSpanResolutionTest extends AbstractJettyTest { | ||
|
||
@Override | ||
protected void initServletContext(ServletContextHandler context) { | ||
context.addFilter(new FilterHolder(new FilterThatInitsSpan()), "/*", | ||
EnumSet.of( | ||
DispatcherType.REQUEST, | ||
DispatcherType.FORWARD, | ||
// TODO CXF does not call AsyncListener#onComplete() without this (it calls only onStartAsync) | ||
DispatcherType.ASYNC, | ||
DispatcherType.ERROR, | ||
DispatcherType.INCLUDE | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void testUseActiveSpanIfSet() { | ||
Client client = ClientBuilder.newClient(); | ||
Response response = client.target(url("/hello/1")) | ||
.request() | ||
.get(); | ||
response.close(); | ||
await().until(finishedSpansSizeEquals(2)); | ||
|
||
List<MockSpan> spans = mockTracer.finishedSpans(); | ||
|
||
Assert.assertEquals(2, spans.size()); | ||
|
||
MockSpan preceding = getSpanWithTag(spans, new ImmutableTag(Tags.COMPONENT.getKey(), "preceding-opentracing-filter")); | ||
MockSpan original = getSpanWithTag(spans, new ImmutableTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)); | ||
|
||
Assert.assertEquals(preceding.context().spanId(), original.parentId()); | ||
} | ||
|
||
class FilterThatInitsSpan implements Filter { | ||
|
||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
|
||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
Scope scope = mockTracer.buildSpan("initializing-span") | ||
.withTag(Tags.COMPONENT.getKey(), "preceding-opentracing-filter") | ||
.startActive(true); | ||
chain.doFilter(request, response); | ||
scope.close(); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../test/java/io/opentracing/contrib/jaxrs2/itest/jersey/JerseyParentSpanResolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.opentracing.contrib.jaxrs2.itest.jersey; | ||
|
||
import io.opentracing.contrib.jaxrs2.itest.common.AbstractParentSpanResolutionTest; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
||
public class JerseyParentSpanResolutionTest extends AbstractParentSpanResolutionTest{ | ||
@Override | ||
protected void initServletContext(ServletContextHandler context) { | ||
super.initServletContext(context); | ||
JerseyHelper.initServletContext(context); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...t/java/io/opentracing/contrib/jaxrs2/itest/resteasy/RestEasyParentSpanResolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.opentracing.contrib.jaxrs2.itest.resteasy; | ||
|
||
import io.opentracing.contrib.jaxrs2.itest.common.AbstractParentSpanResolutionTest; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
|
||
public class RestEasyParentSpanResolutionTest extends AbstractParentSpanResolutionTest { | ||
|
||
protected void initServletContext(ServletContextHandler context) { | ||
super.initServletContext(context); | ||
RestEasyHelper.initServletContext(context); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters