Skip to content

Conversation

@felixbarny
Copy link
Member

@felixbarny felixbarny commented Nov 2, 2018

closes #212

Copy link
Contributor

@eyalkoren eyalkoren left a comment

Choose a reason for hiding this comment

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

The unit test demonstrates how great this API is!
Several comments/clarifications and a suggestion to add a class-level annotation just to make type matching more efficient on the expense of slightly more complicated API.

@Override
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
return isInAnyPackage(config.getApplicationPackages(), ElementMatchers.<NamedElement>none())
.<TypeDescription>and(not(nameContains("$MockitoMock$")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this required?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had some transformation errors but I don't seem to get them now, deleting for now.

public ElementMatcher<? super TypeDescription> getTypeMatcher() {
return isInAnyPackage(config.getApplicationPackages(), ElementMatchers.<NamedElement>none())
.<TypeDescription>and(not(nameContains("$MockitoMock$")))
.and(declaresMethod(getMethodMatcher()));
Copy link
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 adds performance advantage, as it means you invoke the method matcher on all methods of all examined classes anyway.
For the sake of performance, we can add a class-level annotation, something like @Instrumented or @Captured to help us with efficient type matching

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not for performance but to avoid type matches being logged even though no methods get instrumented.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are only scanning the application packages, so I don't know if this is needed. Depends on the size of the code base if that's worth it so evaluating the performance with our toy applications does probably not tell the full story...

Copy link
Contributor

Choose a reason for hiding this comment

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

We are only scanning the application packages

Right, missed the none default. I assumed (and still think) any is a better default, so that we don't force users to configure packages.
Anyway, if they are not going to get anything recorded without that configuration, the API documentation should state that in a very visible way

@Advice.Local("span") Span span) {
if (tracer != null) {
final AbstractSpan<?> parent = tracer.activeSpan();
if (parent != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also check parent.isSampled()

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if the parent is not sampled, we should create a span, for example for log correlation.

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 how we treat it in our instrumentation. Is that because it is an API?

span = parent.createSpan()
.withName(transactionName.isEmpty() ? signature : transactionName)
.withType(type)
.activate();
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check whether span.isSampled() before activating it?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to activate non sampled spans to aid log correlation.

* The name of the {@link Span}.
* Defaults to the {@code ClassName#methodName}
*/
String value() default "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be called name or spanName

Copy link
Member Author

Choose a reason for hiding this comment

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

The method value has special semantics in annotations. It is the default property when declaring an annotation. That means we can do @CaptureSpan("name") instead of @CaptureSpan(name = "name"). I think the most frequent use case would be to only add a span name but to not care about the span type.

* The name of the {@link Transaction}.
* Defaults to the {@code ClassName#methodName}
*/
String value() default "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be called name or transactionName

@codecov-io
Copy link

codecov-io commented Nov 5, 2018

Codecov Report

Merging #281 into master will decrease coverage by 0.43%.
The diff coverage is 41.17%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #281      +/-   ##
============================================
- Coverage     73.11%   72.68%   -0.44%     
- Complexity     1165     1179      +14     
============================================
  Files           126      130       +4     
  Lines          4385     4440      +55     
  Branches        440      447       +7     
============================================
+ Hits           3206     3227      +21     
- Misses          970     1007      +37     
+ Partials        209      206       -3
Impacted Files Coverage Δ Complexity Δ
...c/apm/plugin/api/ElasticApmApiInstrumentation.java 52% <ø> (-3.56%) 3 <0> (-2)
...co/elastic/apm/plugin/api/SpanInstrumentation.java 53.48% <ø> (-2.07%) 3 <0> (-2)
...c/apm/impl/stacktrace/StacktraceConfiguration.java 100% <ø> (ø) 4 <0> (ø) ⬇️
...tic/apm/plugin/api/TransactionInstrumentation.java 52.94% <ø> (-4.96%) 3 <0> (-2)
...ddy/SimpleMethodSignatureOffsetMappingFactory.java 25% <0%> (-3.58%) 2 <0> (ø)
...lastic/apm/plugin/api/ApiScopeInstrumentation.java 60% <100%> (-11.43%) 3 <1> (-2)
.../co/elastic/apm/plugin/api/ApiInstrumentation.java 100% <100%> (ø) 3 <3> (?)
...pm/plugin/api/CaptureExceptionInstrumentation.java 57.14% <100%> (-5.36%) 3 <1> (-1)
.../main/java/co/elastic/apm/bci/ElasticApmAgent.java 71.75% <100%> (+0.21%) 19 <0> (ø) ⬇️
...bytebuddy/AnnotationValueOffsetMappingFactory.java 16.66% <16.66%> (ø) 2 <2> (?)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8acd694...ff4f26b. Read the comment docs.

@felixbarny felixbarny merged commit 279d8b4 into elastic:master Nov 5, 2018
@felixbarny felixbarny deleted the annotations-api branch November 5, 2018 09:49
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.

Add annotations to the public API to create transactions and spans.

3 participants