Skip to content

scala instrumentation#255

Merged
realark merged 7 commits into
configurable-scope-managerfrom
ark/scala_instrumentation
Mar 12, 2018
Merged

scala instrumentation#255
realark merged 7 commits into
configurable-scope-managerfrom
ark/scala_instrumentation

Conversation

@realark
Copy link
Copy Markdown
Contributor

@realark realark commented Mar 6, 2018

(merging to feature branch)

Propagate traces alongscala.concurrent.* classes (Future, Promise, Map) by instrumenting Java executors.

  • ExecutorInstrumentation: Provides async context propagation by wrapping calls to submit and execute.
  • FutureInstrumentation: Cancels jobs which are removed from executors. This is an optimization to allow the trace to report without waiting for GC to collect the continuation reference.

As a precaution, the instrumented executors/futures are limited to a whitelist of tested implementation classes. In the future we may want to remove this whitelist and instrument all executors.

@realark realark added the tag: do not merge Do not merge changes label Mar 6, 2018
@realark realark force-pushed the ark/scala_instrumentation branch 6 times, most recently from 20aef1c to 3f6bf62 Compare March 6, 2018 23:29
@realark realark added the inst: others All other instrumentations label Mar 6, 2018
Copy link
Copy Markdown
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

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

Lots of questions and comments. If possible I'd really like to see the tests moved out of ittests. I also don't like the new dependency for dd-trace-api.

(Sorry if I got carried away.)

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.

Can you move these tests to the java-concurrent instrumentation, since isn't that what it depends on?

Since the tests use @Trace you can add a testCompile dependency on the trace annotation instrumentation as well.

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 originally did that, but ran into a problem. Bootstrap instrumentation is incompatible with our current test api.

My plan is to fix that as part of the akka tests, then move these tests over. Any objections to leaving them in the integration tests for a little while?

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 guess that's fine.

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.

Eew... are these sleeps necessary?
I would much rather use something like a Phaser than have a bunch of sleeps...

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.

Ha, sure.

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 is a java class in the groovy folder. Can you move it over or make it a groovy class?

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

Choose a reason for hiding this comment

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

Try using a Phaser instead.

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.

Do you care about the ordering or the hierarchy of the trace? Might be good to assert the parental relationship, not just the count.

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 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'm curious... what's the reason to use a HashSet here? If the type matters, maybe you should inspect the type of Collection to see if it's a List or a Set and choose the one that matches.

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 particular reason for picking HashSet. I just need a collection to pass to the executor. A list would work fine also. I don't need to preserve the type of tasks.

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.

There are several cases above where you don't wrap the job. Maybe do a type check before casting?

Copy link
Copy Markdown
Contributor Author

@realark realark Mar 7, 2018

Choose a reason for hiding this comment

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

Everything from @Advice.Enter should be a DatadogWrapper at this point (assuming wrappedJobs is non-null). Did I miss something?

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.

Maybe consider adding the close() method for canceling?

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.

Can this be moved to the module instead of being in ittests, or does the bootstrap class issue prevent that?

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.

Cool idea.

@tylerbenson
Copy link
Copy Markdown
Contributor

Do you have a feel for what versions of scala this would support?

@realark
Copy link
Copy Markdown
Contributor Author

realark commented Mar 7, 2018

I've tested against Scala 2.11 and 2.12.

@realark realark force-pushed the ark/scala_instrumentation branch from 3f6bf62 to dfe267e Compare March 7, 2018 21:29
@realark realark removed the tag: do not merge Do not merge changes label Mar 7, 2018
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 don't think this is used anymore...

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.

Any time I see us instrumenting an anonymous class like this, I expect it to be very fragile across versions.

@tylerbenson tylerbenson force-pushed the configurable-scope-manager branch from 13c354a to 4fffb61 Compare March 9, 2018 04:32
@realark realark force-pushed the ark/scala_instrumentation branch 2 times, most recently from 90111f5 to 7f57924 Compare March 9, 2018 20:54
@realark
Copy link
Copy Markdown
Contributor Author

realark commented Mar 9, 2018

@tylerbenson Changes pushed. Notably, I removed the opentracing dependency from dd-trace-api.

@realark realark dismissed tylerbenson’s stale review March 9, 2018 20:58

Please review new changes.

@realark realark force-pushed the ark/scala_instrumentation branch from 7f57924 to 45aff57 Compare March 9, 2018 20:59
testWriter.size() == 1
trace.size() == 2
trace.get(0).operationName == "parent"
trace.get(1).operationName == "asyncChild"
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.

Minor, but maybe assert that child's parentId is parent's spanId?

package datadog.trace.context;

/** An object when can propagate a datadog trace across multiple threads. */
public interface ContextPropagator {
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.

Thoughts on just renaming this to Scope or TraceScope?

Copy link
Copy Markdown
Contributor

@tylerbenson tylerbenson left a comment

Choose a reason for hiding this comment

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

Only question is if we want to change the name of ContextPropagator.

@realark realark force-pushed the ark/scala_instrumentation branch from c8d961a to 428e304 Compare March 12, 2018 17:29
@realark
Copy link
Copy Markdown
Contributor Author

realark commented Mar 12, 2018

Renamed ContextPropagator to TraceScope.

@realark realark merged commit 34a8c0e into configurable-scope-manager Mar 12, 2018
@realark realark deleted the ark/scala_instrumentation branch March 12, 2018 17:43
@realark realark added this to the 0.5.0 milestone Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: others All other instrumentations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants