Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

add instrumentation for spring AsyncRestTemplate.#1919

Merged
rghetia merged 6 commits intocensus-instrumentation:masterfrom
rghetia:spring_async_client
May 28, 2019
Merged

add instrumentation for spring AsyncRestTemplate.#1919
rghetia merged 6 commits intocensus-instrumentation:masterfrom
rghetia:spring_async_client

Conversation

@rghetia
Copy link
Copy Markdown
Contributor

@rghetia rghetia commented May 23, 2019

No description provided.

@rghetia rghetia requested review from a team, dinooliva and songy23 as code owners May 23, 2019 07:01
Comment thread build.gradle Outdated
signalfxVersion = '0.0.48'
springBootVersion = '1.5.15.RELEASE'
springBootTestVersion = '2.1.1.RELEASE'
springBootVersion = '2.1.5.RELEASE'
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.

IIRC Spring boot 1.x and 2.x are incompatible and we're still depending on 1.x in other artifacts. So maybe we need to keep the 1.5.15 version? /cc @dinooliva

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.

Yes - springBootVersion is used to build libraries.spring_boot_starter_web which is used to build spring_sleuth_v1x and that artifact is explicitly meant to be built with Spring 1.x (surprised the unit tests don't fail).

We may need to create a legacy version of the Spring boot library for use with existing artifacts and migrate them as possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have left the version as is for spring_sleuth_v1x. Changed the version for opencensus-contrib-spring.

@SuppressWarnings("MustBeClosedChecker")
public void should_close_span_upon_success_callback()
throws ExecutionException, InterruptedException {
this.tracer = Tracing.getTracer();
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.

Curious - why 'this.tracer' rather than 'tracer'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

copy/paste. Removed.


@Test(timeout = 10000)
@Order(1)
// Need to suppress warnings for MustBeClosed because Java-6 does not support try-with-resources.
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 thought tests were no longer constrained to Java 6.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

change the compatibility to 1.8 and removed the suppression.

.start();

future.get(500, TimeUnit.MILLISECONDS);
assertThat(true).named("should throw an exception from the controller");
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.

why 'assertThat(true)'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actually I wanted equivalent of assertThrows(). I have re-implemented this. Let me know if that works.

}

TracingAsyncClientHttpRequestInterceptor() {
System.out.println("constructing interceptor");
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.

Why the println? Here and below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

leftover from debugging. Removed it.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented May 24, 2019

@dinooliva PTAL.

Copy link
Copy Markdown
Contributor

@dinooliva dinooliva left a comment

Choose a reason for hiding this comment

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

Overall looks good - a couple minor questions.


@PostConstruct
public void init() {
if (this.restTemplates != null) {
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.

Why 'this' here and elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed all of them.

new ArrayList<org.springframework.http.client.AsyncClientHttpRequestInterceptor>(
restTemplate.getInterceptors());
interceptors.add(this.clientInterceptor);
restTemplate.setInterceptors(interceptors);
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.

Is there any concern that you may overwrite existing interceptors in the restTemplate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am adding it to existing interceptor.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented May 24, 2019

@dinooliva PTAL.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented May 28, 2019

@songy23 PTAL.

Copy link
Copy Markdown
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

A few minor nits, overall LGTM.

Comment thread build.gradle Outdated
log4j2Version = '2.11.1'
signalfxVersion = '0.0.48'
springBoot2Version = '2.1.5.RELEASE'
springBootTest2Version = '2.1.5.RELEASE'
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.

Nit: this isn't needed since it's the same as springBoot2Version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment thread contrib/spring/build.gradle Outdated
it.targetCompatibility = 1.8
}

springBootVersion = '2.1.5.RELEASE'
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.

This can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

final Tracer tracer;
final HttpClientHandler<HttpRequest, ClientHttpResponse, HttpRequest> handler;

// final Injector<HttpHeaders> injector;
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.

Should this be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes. done.

@rghetia rghetia merged commit bfe1ad3 into census-instrumentation:master May 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants