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

Implement the TraceInterceptor API #253

Merged
merged 4 commits into from Mar 12, 2018

Conversation

tylerbenson
Copy link
Contributor

@tylerbenson tylerbenson commented Mar 6, 2018

Add a TraceInterceptor API with the design intent to only require a dependency on dd-trace-api. This is done by using java's ServiceLoader. Unfortunately in my testing, this doesn't seem to work smoothly with Spring Boot's executable jar. If this issue comes up, I can revisit.

(Merging into configurable-scope-manager branch)

@tylerbenson tylerbenson added the tag: do not merge Do not merge changes label Mar 6, 2018
@tylerbenson tylerbenson mentioned this pull request Mar 7, 2018
Still doesn’t work with Spring Boot because the way they structure their Jars.
@tylerbenson tylerbenson changed the base branch from master to configurable-scope-manager March 9, 2018 04:37
@@ -40,7 +41,7 @@ public JMS1MessageProducerInstrumentation() {
public AgentBuilder apply(final AgentBuilder agentBuilder) {
return agentBuilder
.type(
not(isInterface()).and(hasSuperType(named("javax.jms.MessageProducer"))),
not(isInterface()).and(failSafe(hasSuperType(named("javax.jms.MessageProducer")))),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were causing warnings when dealing with injected classes: raphw/byte-buddy#373
Added the failSafe to suppress the noise.

@tylerbenson tylerbenson added comp: core Tracer core and removed tag: do not merge Do not merge changes labels Mar 9, 2018
To prevent errors on injected classes.
new EmptyNonDelegatingLoader()

then:
1 * tracer.registerClassLoader(_ as EmptyNonDelegatingLoader)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this syntax mean? Not sure what's being asserted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means that tracer.registerClassLoader was called one time with an argument of type EmptyNonDelegatingLoader.
Basically a way of asserting the mock interactions.

import java.util.concurrent.atomic.AtomicInteger;

public class CallDepthThreadLocalMap {
private static final ThreadLocal<AtomicInteger> tls = new ThreadLocal<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the count is in a thread-local, why not use an integer instead of an atomic integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but AtomicInteger has nice increment and decrement operations whereas with Integer, I'd have to do those operations then reset on the threadlocal. Still think I should do Integer instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, AtomicInteger is fine.

Copy link
Contributor

@realark realark left a comment

Choose a reason for hiding this comment

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

Few random questions, but the changes look good.

However, there's a problem for javaagent users.

We relocate the api namespace when we run as an agent: https://github.com/DataDog/dd-trace-java/blob/master/dd-java-agent/dd-java-agent.gradle#L53-L56

So the ServiceLocator will end up searching the datadog.trace.agent.api.

I'd be in favor of removing those relocate rules. See any downside to that?

@tylerbenson
Copy link
Contributor Author

Good point about the relocation. I forgot about that, but I agree the API classes should not be relocated. I'll just do that.

We expect customers to be using these also, so we can’t change them.
@tylerbenson tylerbenson merged commit 0fbec69 into configurable-scope-manager Mar 12, 2018
@tylerbenson tylerbenson deleted the tyler/traceinterceptor branch March 12, 2018 22:30
@realark realark added this to the 0.5.0 milestone Mar 13, 2018
jpbempel pushed a commit that referenced this pull request May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: core Tracer core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants