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

WIP: Implemetation Issue#35 #42

Closed

Conversation

kameshsampath
Copy link

@kameshsampath kameshsampath commented Sep 5, 2017

fixes #35

* @author kamesh
*/
@Configuration
@EnableAsync
Copy link

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.

Copy link
Contributor

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.

Copy link
Author

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";
Copy link

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?

Copy link
Author

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;
Copy link

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?

Copy link
Author

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;
Copy link

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?

Copy link
Author

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;
Copy link
Contributor

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?

Copy link
Author

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>
Copy link
Contributor

Choose a reason for hiding this comment

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

export version to property.

Copy link
Author

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
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

and also .gitkeep

Copy link
Author

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>
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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())
Copy link
Contributor

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

Copy link
Author

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);
Copy link
Contributor

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()

Copy link
Author

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();
Copy link
Contributor

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.

Copy link
Author

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 ??

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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))
Copy link
Contributor

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

Copy link
Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

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>
Copy link
Contributor

Choose a reason for hiding this comment

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

there is double -``-

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>
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

fixed in latest commit

Copy link
Contributor

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 {
Copy link
Contributor

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)

Copy link
Author

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

Copy link
Contributor

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?

@@ -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">
Copy link
Contributor

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?

Copy link
Author

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) {
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Author

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")
Copy link
Contributor

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?

Copy link
Author

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>
Copy link
Contributor

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());
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

not used here

Copy link
Author

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();
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Author

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

@pavolloffay
Copy link
Contributor

pavolloffay commented Sep 6, 2017

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

Kamesh Sampath added 3 commits September 6, 2017 20:36
Handles instrumentation for

* Async annotated methods
* WebAsyncTask return types method for RestController/Controller
* Callable return types method for RestController/Controller
@pavolloffay
Copy link
Contributor

closing implemented in #43 , @kameshsampath thanks a lot!

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.

Trace async
3 participants