-
Notifications
You must be signed in to change notification settings - Fork 142
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
WIP: Implemetation Issue#35 #42
Conversation
* @author kamesh | ||
*/ | ||
@Configuration | ||
@EnableAsync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we enable async? I think user should decide to enable/disable spring features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same question, although sleuth enables it here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had the same doubt when doing it, Sleuth does it so added it but then I had another thought is that unless @Async
added this will not be triggered, so when I do @Async
then I need to @EnabledAsync
private static final String ASYNC_COMPONENT = "async"; | ||
public static final String TAG_LC = "localcomponent"; | ||
public static final String TAG_CLASS = "class"; | ||
public static final String TAG_METHOD = "method"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be all these strings private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes noted!
public static final String TAG_CLASS = "class"; | ||
public static final String TAG_METHOD = "method"; | ||
|
||
Tracer tracer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be private final
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
||
Tracer tracer; | ||
protected final ActiveSpan.Continuation continuation; | ||
protected final ActiveSpan activeSpan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be both private
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
public static final String TAG_METHOD = "method"; | ||
|
||
Tracer tracer; | ||
protected final ActiveSpan.Continuation continuation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this aspect singleton or instance per-invocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is per invocation? why?
pom.xml
Outdated
@@ -123,6 +123,12 @@ | |||
</dependency> | |||
|
|||
<dependency> | |||
<groupId>io.opentracing.contrib</groupId> | |||
<artifactId>opentracing-concurrent</artifactId> | |||
<version>0.0.1</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export version to property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes done
.editorconfig
Outdated
@@ -0,0 +1,18 @@ | |||
# top-most EditorConfig file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not push this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also .gitkeep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.gitkeep is fine, why .editorconfig
- helps accidental formats done on the code and we can maintain the standard formatting.. now adding to .gitkeep but IMHO worth having it
@@ -6,7 +6,7 @@ | |||
<parent> | |||
<groupId>io.opentracing.contrib</groupId> | |||
<artifactId>opentracing-spring-cloud-parent</artifactId> | |||
<version>0.0.1-SNAPSHOT</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need probably to rebase off master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still a change here and it should not be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same in other pom files
* @author kamesh | ||
*/ | ||
@Configuration | ||
@EnableAsync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same question, although sleuth enables it here too.
this.continuation.activate(); | ||
|
||
Span span = this.tracer.buildSpan(operationName(pjp)) | ||
.asChildOf(this.activeSpan.context()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an active span it will be automatically considered as parent. This line can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
.asChildOf(this.activeSpan.context()) | ||
.startManual(); | ||
|
||
this.activeSpan.setTag(TAG_LC, ASYNC_COMPONENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set all this tags directly when calling tracer.buildSpan("foo").tag()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@Autowired | ||
public TraceAsyncAspect(Tracer tracer) { | ||
this.tracer = tracer; | ||
this.activeSpan = tracer.activeSpan(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not needed just capture the continuation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how do I capture continuation without activeSpan ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just capture a continuation then when you activate continuation it will set that span as active.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I get you correctly you don't want that extra member there for activeSpan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, just get activeSpan capture continuation but do not store the active span in the class.
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable { | ||
this.continuation.activate(); | ||
|
||
Span span = this.tracer.buildSpan(operationName(pjp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if operationName(pjp)
throws an exception the span won't be closed. I would move it to the try block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Span span = null; | ||
try { | ||
span = this.tracer.buildSpan(operationName(pjp)) | ||
.withTag(TAG_LC, ASYNC_COMPONENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use sandard OT tag Tags.Component
. https://github.com/opentracing/specification/blob/master/semantic_conventions.yaml#L10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! thanks for pointing out
pom.xml
Outdated
@@ -46,6 +46,7 @@ | |||
<version.io.opentracing>0.30.0</version.io.opentracing> | |||
<version.io.opentracing.contrib-opentracing-spring-web>0.0.8</version.io.opentracing.contrib-opentracing-spring-web> | |||
<version.io.opentracing.contrib-opentracing-spring-jms>0.0.3</version.io.opentracing.contrib-opentracing-spring-jms> | |||
<version.io.opentracing.contrib--java-concurrent>0.0.1</version.io.opentracing.contrib--java-concurrent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is double -``-
295f350
to
22b6c00
Compare
pom.xml
Outdated
@@ -47,6 +47,7 @@ | |||
<version.io.opentracing.contrib-opentracing-spring-web>0.0.8</version.io.opentracing.contrib-opentracing-spring-web> | |||
<version.io.opentracing.contrib-opentracing-spring-jms>0.0.3</version.io.opentracing.contrib-opentracing-spring-jms> | |||
<version.io.opentracing.contrib-java-jdbc>0.0.3</version.io.opentracing.contrib-java-jdbc> | |||
<version.io.opentracing.contrib--java-concurrent>0.0.1</version.io.opentracing.contrib--java-concurrent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is still double -- in the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it's still here
@ConditionalOnBean(AsyncConfigurer.class) | ||
@AutoConfigureBefore(AsyncDefaultAutoConfiguration.class) | ||
//TODO when Scheduling is added we need to do @AutoConfigurationAfter here | ||
public class AsyncCustomAutoConfiguration implements BeanPostProcessor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to be added to spring factories file. (located in resources)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry missed in previous commit, added to new commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add class level comment what it does, what it traces?
…uration to spring.factories
@@ -1,112 +1,114 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please revert changes in this file which are not related to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry about, thought i had reverted in previous commit, it was because of the test changes introduced earlier using zipkin for IT
} | ||
|
||
@Override | ||
public void execute(Runnable command) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why overriding only this method?
} | ||
|
||
private String operationName(ProceedingJoinPoint pjp) { | ||
return getMethod(pjp, pjp.getTarget()).getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this safe? Can this throw NPE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think so - i cant have a "@aspect" on a method whose name can be null??
|
||
@Configuration | ||
@EnableAsync | ||
@ComponentScan("io.opentracing.contrib.spring.cloud.async") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to make the test bit efficient, and confined only to Async testing, otherwise it tends to load a whole lot from classpath which is not required for this test context
pom.xml
Outdated
@@ -47,6 +47,7 @@ | |||
<version.io.opentracing.contrib-opentracing-spring-web>0.0.8</version.io.opentracing.contrib-opentracing-spring-web> | |||
<version.io.opentracing.contrib-opentracing-spring-jms>0.0.3</version.io.opentracing.contrib-opentracing-spring-jms> | |||
<version.io.opentracing.contrib-java-jdbc>0.0.3</version.io.opentracing.contrib-java-jdbc> | |||
<version.io.opentracing.contrib--java-concurrent>0.0.1</version.io.opentracing.contrib--java-concurrent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it's still here
|
||
@Override | ||
public Executor getAsyncExecutor() { | ||
return new LazyTraceExecutor(this.beanFactory, new SimpleAsyncTaskExecutor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to directly return TracerExecutorService from ot-concurrent
BeanFactory beanFactory; | ||
|
||
@Mock | ||
AsyncConfigurer asyncConfigurer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be used by "@Injectmocks"
public class LazyTraceExecutorTest { | ||
|
||
@Mock | ||
BeanFactory beanFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be used by "@Injectmocks"
List<MockSpan> finishedSpans = mockTracer.finishedSpans(); | ||
assertThat(finishedSpans.size()).isEqualTo(1); | ||
MockSpan mockSpan = mockTracer.finishedSpans().get(0); | ||
assertThat(mockSpan).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant
} | ||
|
||
@Test | ||
public void testAsyncTraceAndSpans() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why there is @Before
and one test, in the before you execute traced interface but you assert in the test. I think it should be merged.
Most important is a wiring test. e.g. create active span before calling the delayer
and then verify that reported spans are in the same trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was having it when I had multiple tests, now its not needed will remove
We also need a "wiring" test where a callable is returned from the REST controller. Inside the callable create a span and verify that server span and span from callable are in the same trace. edit: needed for this use cases https://github.com/redhat-developer-demos/brewery/blob/iteration-3/brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientsController.java#L54 |
Handles instrumentation for * Async annotated methods * WebAsyncTask return types method for RestController/Controller * Callable return types method for RestController/Controller
closing implemented in #43 , @kameshsampath thanks a lot! |
fixes #35