Skip to content

Add auto-config for the tracer resolver - #16

Closed
objectiser wants to merge 2 commits into
opentracing-contrib:masterfrom
objectiser:tracerresolver
Closed

Add auto-config for the tracer resolver#16
objectiser wants to merge 2 commits into
opentracing-contrib:masterfrom
objectiser:tracerresolver

Conversation

@objectiser

Copy link
Copy Markdown
Contributor

This PR extracts the tracer resolver auto-config from #15.

@objectiser

Copy link
Copy Markdown
Contributor Author

@pavolloffay @malafeev Continuation of the conversation from previous PR.

To address your comments from the previous PR:

How does the TracerResolver work? IIRC it registers the resolved tracer to GlobalTracer and the app obtains the tracer from it.

No the tracer resolver does not register the tracer with the GlobalTracer.

As I propose we can simply change the current TracerAutoConfiguration for fallback to GlobalTracer if there is no Tracer bean available in the context. Or does this PR has other benefits?

There are two problems that need to be addressed, (1) how instrumentations access the tracer, and (2) how does the Tracer get configured in the first place.

This PR is simply dealing with the second problem. As mentioned before, there are two ways the Tracer can be created/configured - either explicitly by the application, or via the TracerResolver mechanism. This PR is simply providing an auto-config mechanism to enable the TracerResolver to be used - it does not make it mandatory in anyway - it only enables it to be supported, if the app developer includes a tracer resolver impl in their classpath.

@objectiser

Copy link
Copy Markdown
Contributor Author

Have created #17 to discuss the first problem (i.e. how instrumentations access the tracer).

@RunWith(SpringJUnit4ClassRunner.class)
public class TracerResolverConfigurationTest {

@Autowired(required=false)

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 required=false?

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.

No specific reason - can be removed.

<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>opentracing-spring-cloud-tracerresolver</artifactId>

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 should include starter in the name: we could name it:
opentracing-spring-cloud-tracerresolver-starter or opentracing-spring-cloud-starter-tracerresolver. It seems that the second is a convention in spring.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${version.org.springframework.boot}</version>

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.

not needed

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${version.org.springframework.boot}</version>

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.

not needed


@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class TracerResolverConfigurationTest {

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.

To test this you have to make sure that instance provided by traceresolver is the one used by instrumentations.

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.

We had a similar problem in jaeger-k8s,

This solved the problem https://github.com/snowdrop/jaeger-opentracing/blob/master/spring-cloud-kubernetes-jaeger/src/main/java/org/springframework/cloud/kubernetes/jaeger/JaegerKubernetesAutoConfiguration.java#L49
I think it was failing on an error that there are two tracer beans although I'm not sure why it works here.

import io.opentracing.contrib.tracerresolver.TracerResolver;

@Configuration
@ConditionalOnClass(value = {TracerResolver.class})

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 is this here?

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.

So when there is no trace resolver it will use TracerAutoConfiguration (e.g. NoopTracer)?

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.

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.

Although it should probably be conditional on no Tracer bean as well, in case one has been provided.

@objectiser

Copy link
Copy Markdown
Contributor Author

@pavolloffay Thanks for the comments - will revisit on my return next week if there is resolution as to whether this should be included in this repo.

@pavolloffay

Copy link
Copy Markdown
Contributor

If we really want it here I would maybe prefer to have it in TracerAutoconfiguration. The order of getting the tracer would be:

  1. spring context
  2. tracer resolver
  3. NoopTracer

@pavolloffay

Copy link
Copy Markdown
Contributor

Closing, done in opentracing-contrib/java-spring-web#30

@pavolloffay

Copy link
Copy Markdown
Contributor

@objectiser thanks for bringing this up

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.

2 participants