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

Closes #1555: [Feature] - fix StackTraceSampler / AutoTracing #1558

Merged
merged 8 commits into from
Jan 18, 2023

Conversation

heiko-holz
Copy link
Contributor

@heiko-holz heiko-holz commented Dec 23, 2022

Closes #1555


This change is Reviewable

@heiko-holz heiko-holz marked this pull request as ready for review January 8, 2023 12:29
Copy link
Member

@Dimi-Ma Dimi-Ma left a comment

Choose a reason for hiding this comment

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

Reviewed 81 of 81 files at r1, all commit messages.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @heiko-holz)

a discussion (no related file):
There were a few inconsistencies regarding code formatting, maybe we should discuss this in a Meeting.



inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/special/logging/Log4J2TraceIdAutoInjectorTest.java line 58 at r1 (raw file):

        Span span = tracer.spanBuilder("test").startSpan();
        try (Scope scope = span.makeCurrent()) {
            traceId = Span.current().getSpanContext().getTraceId();

in LogCorelationTest.java this part was extracted into their own function so to keep everything the same we should do this here too or move the previous implementation into a higher order to be able to use this function everywhere its needed and don't have redundancy.


inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/special/logging/Log4JTraceIdAutoInjectorTest.java line 36 at r1 (raw file):

        try (Scope scope = tracer.spanBuilder("test").startSpan().makeCurrent()) {
            traceId = Span.current().getSpanContext().getTraceId();

Same here for the extraction into their own function.


inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/opentelemetry/IOpenTelemetryController.java line 61 at r1 (raw file):

    /**
     * Registers a new {@link rocks.inspectit.ocelot.core.service.DynamicallyActivatableService trace exporter service} that is used to export {@link io.opentelemetry.sdk.trace.data.SpanData} for sampled {@link io.opentelemetry.api.trace.Span}s
     * This method should ONLY be used in tests of the {@code agent} package.

Is it a good idea to implement a test only function here?


inspectit-ocelot-core/src/main/java/io/opentelemetry/sdk/trace/OcelotAnchoredClockUtils.java line 87 at r1 (raw file):

            throw new RuntimeException(e);
        }

This space is not needed.


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/config/MethodHookConfigurationResolver.java line 55 at r1 (raw file):

        boolean traceEntryHook = Stream.of(matchedRules.stream()
                .map(InstrumentationRule::getPreEntryActions)
                .flatMap(Collection::stream), matchedRules.stream()

I think it would be better to format this one with the commas instead of the dots to make it more readable for each value. e.g.

Code snippet:

        boolean traceEntryHook = Stream.of(
            matchedRules.stream().map(InstrumentationRule::getPreEntryActions).flatMap(Collection::stream), 
            matchedRules.stream().map(InstrumentationRule::getEntryActions).flatMap(Collection::stream), 
            matchedRules.stream().map(InstrumentationRule::getPostEntryActions).flatMap(Collection::stream)).flatMap(s -> s).anyMatch(ActionCallConfig::isActionTracing);
            ...

inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/context/InspectitContextImpl.java line 3 at r1 (raw file):

package rocks.inspectit.ocelot.core.instrumentation.context;

import io.opencensus.tags.*;

Is this something that can't be done with open telemetry?


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookGenerator.java line 176 at r1 (raw file):

        String sampleProbability = tracing.getSampleProbability();
        if (!StringUtils.isBlank(sampleProbability)) {
            

this empty line can be removed.


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/opentelemetry/trace/samplers/HybridParentTraceIdRatioBasedSampler.java line 52 at r1 (raw file):

        // if any parent link has been sampled, keep the sampling decision.
        if (isAnyParentLinkSampled) {

Could we not put this if into the previous if statement with an OR since they are both returning the same?


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/utils/OpenCensusShimUtils.java line 90 at r1 (raw file):

    }

    // TODO: über Reflection auf die Copy-Helper-Methode zuzugreifen, anstatt diese zu kopieren

Is this TODO supposed to be finished in this PR? If not it might be a better idea to create a separate Ticket for it before it gets forgotten.


inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/actions/span/WriteSpanAttributesTest.java line 30 at r1 (raw file):

    IObfuscatory obfuscatory;

    @Spy

Do we still need to use @Spyhere? If yes, a comment explaining why would be helpful 🙂

Copy link
Member

@Dimi-Ma Dimi-Ma left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @heiko-holz)

a discussion (no related file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

There were a few inconsistencies regarding code formatting, maybe we should discuss this in a Meeting.

Additionally, there is a failing Test in the class JaegerThriftExporterServiceIntTestwhich i have tested multiple times with the name verifyTraceSent.


Copy link
Member

@Dimi-Ma Dimi-Ma left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @heiko-holz)

a discussion (no related file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Additionally, there is a failing Test in the class JaegerThriftExporterServiceIntTestwhich i have tested multiple times with the name verifyTraceSent.

Follow up information: the failing Test only fails, if all other tests run too but passes if run alone, this indicates that something isn't cleaned up properly from previous tests.


Copy link
Member

@Dimi-Ma Dimi-Ma left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @heiko-holz)


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/context/InspectitContextImpl.java line 3 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Is this something that can't be done with open telemetry?

Since the changes only were supposed to affect traces and not metrics i will retract this comment.

Copy link
Contributor Author

@heiko-holz heiko-holz left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @Dimi-Ma)

a discussion (no related file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Follow up information: the failing Test only fails, if all other tests run too but passes if run alone, this indicates that something isn't cleaned up properly from previous tests.

Let's have a chat and look into this issue



inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/special/logging/Log4J2TraceIdAutoInjectorTest.java line 58 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

in LogCorelationTest.java this part was extracted into their own function so to keep everything the same we should do this here too or move the previous implementation into a higher order to be able to use this function everywhere its needed and don't have redundancy.

I agree.
I have refactored Log4J2TraceIdAutoInjectorTest.java and moved the logic to start the span, extract the trace id, and log the message into the method startSpanAndExtractTraceIdAndLogMessage


inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/special/logging/Log4JTraceIdAutoInjectorTest.java line 36 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Same here for the extraction into their own function.

I would leave this class as it. In my opinion, we would create more boilerplate code when trying to extract this into an extra method as this is the only call to Span.current().getSpanContext().getTraceId(); in this class


inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/opentelemetry/IOpenTelemetryController.java line 61 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Is it a good idea to implement a test only function here?

I added this for the tests in the agent package, as we do not have access to the core package there.
Otherwise, I could have directly worked with the OpenTelemetryControllerImpl.java class.

I would not know how I could otherwise register a trace exporter in the agent test package, without re-building OpenTelemetry from scratch and discarding the configurations.

Let's discuss this in a meeting.


inspectit-ocelot-core/src/main/java/io/opentelemetry/sdk/trace/OcelotAnchoredClockUtils.java line 87 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

This space is not needed.

Thanks for catching this.
I have deleted the empty line.


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/config/MethodHookConfigurationResolver.java line 55 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

I think it would be better to format this one with the commas instead of the dots to make it more readable for each value. e.g.

I cannot really follow.
What do you exactly mean, can you make an example?


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/context/InspectitContextImpl.java line 3 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Is this something that can't be done with open telemetry?

It can be replaced at a later point with Baggage and Attributes of OpenTelemetry,
However, this would add more complexity (and take at least 2 more days to this ticket).


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/hook/MethodHookGenerator.java line 176 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

this empty line can be removed.

Thanks, I have deleted the empty line.


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/opentelemetry/trace/samplers/HybridParentTraceIdRatioBasedSampler.java line 52 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Could we not put this if into the previous if statement with an OR since they are both returning the same?

Technically we could. However, I have followed OpenCensus' implementation of https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/trace/samplers/ProbabilitySampler.java.
But we can change it to this if you think this is more readable:

 // If the parent or any parent link has been sampled keep, the sampling decision.
        if ((parentSpanContext.isValid() && parentSpanContext.isSampled()) || isAnyParentLinkSampled(parentLinks)) {
            return SamplingResult.recordAndSample();
        }

inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/utils/OpenCensusShimUtils.java line 90 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Is this TODO supposed to be finished in this PR? If not it might be a better idea to create a separate Ticket for it before it gets forgotten.

Good catch!
Actually, the methods mapKind where not used. Thus, I have removed the TODO statement and the unused methods.


inspectit-ocelot-core/src/test/java/rocks/inspectit/ocelot/core/instrumentation/hook/actions/span/WriteSpanAttributesTest.java line 30 at r1 (raw file):

Previously, Dimi-Ma (Dimitiros Mantas) wrote…

Do we still need to use @Spyhere? If yes, a comment explaining why would be helpful 🙂

Yes, we need the @Spy to have a dummy span for the evaluation in verifyAttributesWritten. I have added a comment

@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #1558 (eb2637d) into master (e1d0861) will increase coverage by 0.70%.
The diff coverage is 58.61%.

❗ Current head eb2637d differs from pull request most recent head 2d4b6cc. Consider uploading reports for the commit 2d4b6cc to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1558      +/-   ##
============================================
+ Coverage     77.54%   78.24%   +0.70%     
- Complexity     2320     2404      +84     
============================================
  Files           240      246       +6     
  Lines          7730     7909     +179     
  Branches        924      936      +12     
============================================
+ Hits           5994     6188     +194     
+ Misses         1350     1307      -43     
- Partials        386      414      +28     
Impacted Files Coverage Δ
...tstrap/opentelemetry/IOpenTelemetryController.java 100.00% <ø> (ø)
...rap/opentelemetry/NoopOpenTelemetryController.java 20.00% <0.00%> (-2.22%) ⬇️
...del/instrumentation/rules/RuleTracingSettings.java 100.00% <ø> (ø)
...t/ocelot/config/model/tracing/TracingSettings.java 100.00% <ø> (ø)
...t/core/instrumentation/autotracing/Invocation.java 90.91% <ø> (ø)
...nstrumentation/autotracing/InvocationResolver.java 89.66% <0.00%> (+1.42%) ⬆️
...e/instrumentation/autotracing/PlaceholderSpan.java 0.00% <0.00%> (-2.44%) ⬇️
...mentation/autotracing/events/MethodEntryEvent.java 100.00% <ø> (ø)
...instrumentation/autotracing/events/TraceEvent.java 100.00% <ø> (ø)
...nstrumentation/hook/actions/TracingHookAction.java 0.00% <0.00%> (ø)
... and 41 more

@heiko-holz
Copy link
Contributor Author

inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/opentelemetry/trace/samplers/HybridParentTraceIdRatioBasedSampler.java line 52 at r1 (raw file):

Previously, heiko-holz (Heiko Holz) wrote…

Technically we could. However, I have followed OpenCensus' implementation of https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/trace/samplers/ProbabilitySampler.java.
But we can change it to this if you think this is more readable:

 // If the parent or any parent link has been sampled keep, the sampling decision.
        if ((parentSpanContext.isValid() && parentSpanContext.isSampled()) || isAnyParentLinkSampled(parentLinks)) {
            return SamplingResult.recordAndSample();
        }

We have agreed to change it to the shorter version

Copy link
Contributor Author

@heiko-holz heiko-holz left a comment

Choose a reason for hiding this comment

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

Reviewable status: 72 of 81 files reviewed, 10 unresolved discussions (waiting on @Dimi-Ma)


inspectit-ocelot-core/src/main/java/rocks/inspectit/ocelot/core/instrumentation/config/MethodHookConfigurationResolver.java line 55 at r1 (raw file):

Previously, heiko-holz (Heiko Holz) wrote…

I cannot really follow.
What do you exactly mean, can you make an example?

After the discussion, we agreed that we need to tweak the code styling of inspectIT Ocelot, but not in this ticket.

Copy link
Member

@Dimi-Ma Dimi-Ma left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r2, 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @heiko-holz)


inspectit-ocelot-agent/src/system-test/java/rocks/inspectit/ocelot/instrumentation/special/logging/Log4JTraceIdAutoInjectorTest.java line 36 at r1 (raw file):

Previously, heiko-holz (Heiko Holz) wrote…

I would leave this class as it. In my opinion, we would create more boilerplate code when trying to extract this into an extra method as this is the only call to Span.current().getSpanContext().getTraceId(); in this class

Yes, you are right. I probably overlooked the fact that it was the only call in this class.

@heiko-holz heiko-holz merged commit 3152c9a into inspectIT:master Jan 18, 2023
@heiko-holz heiko-holz deleted the feat/feat-1555-auto-tracing branch January 18, 2023 14:22
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.

[Feature] - fix StackTraceSampler / AutoTracing
2 participants