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

Autoinstrumentation without @NewSpan? #202

Open
alberth-li opened this issue Nov 9, 2022 · 5 comments
Open

Autoinstrumentation without @NewSpan? #202

alberth-li opened this issue Nov 9, 2022 · 5 comments
Labels
type: question Further information is requested

Comments

@alberth-li
Copy link

Feature description

Hello,

I am not very familiar with the project, so apologize in advance if I am asking a stupid question...
Open Telemetry has an auto instrumentation agent that works out of the box without need to change any code: https://opentelemetry.io/docs/instrumentation/java/automatic/
However, it appears that Micronaut is not supported yet: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/supported-libraries.md
So what does this project do in term of Otel support? It appears that in order for us to have multiple spans under one incoming http request on a http server running Micronaut, we need to add @NewSpan annotation to every single function in the call stack? Is this how it is suppose to be used? Or there is some out of the box usage here? I am very confused.

@graemerocher
Copy link
Contributor

you can add the HTTP module if you want auto instrumentation of HTTP requests https://micronaut-projects.github.io/micronaut-tracing/latest/guide/#http

@graemerocher graemerocher added the type: question Further information is requested label Nov 9, 2022
@alberth-li
Copy link
Author

you can add the HTTP module if you want auto instrumentation of HTTP requests https://micronaut-projects.github.io/micronaut-tracing/latest/guide/#http

Thank you for answering. We already have that, but there is only one span per http request despite within a request many functions are called. How to trace individual function calls without annotating with @newspan or @continuespan on each single one of them?

@maccuaa
Copy link

maccuaa commented Dec 2, 2022

Further to the original question, is there anything in Micronaut Tracing that's similar to Spring Cloud Sleuth that automatically adds trace and span ids to the Slf4J MDC so that they can be included in the application logs?

@maccuaa
Copy link

maccuaa commented Dec 6, 2022

Not sure where to post this but to get Span and Trace IDs to show up in the Logback logs I had to do the following:

  1. Add dependencies to build.gradle:
implementation("io.micronaut.tracing:micronaut-tracing-opentelemetry-http")
runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-logback-mdc-1.0") // version is pulled from micronaut tracing BOM groovy
  1. Update logback.xml to include trace_id, span_id and include OTEL Logback Appender:
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{ISO8601} %-5level [%X{trace_id},%X{span_id}] [%thread] %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="OTEL" class="io.opentelemetry.instrumentation.logback.v1_0.OpenTelemetryAppender">
        <appender-ref ref="STDOUT"/>
    </appender>

    <root level="info">
        <appender-ref ref="OTEL"/>
    </root>
</configuration>

This was enough to get the trace and span ID to show up in the logs but then our system and integration tests started failing. I found #152 which was the same issue but still our tests were failing. In order to overcome I had to extend that fix by also resetting OTEL on @AfterEach:

public class BaseIntegrationTest {

    @PreDestroy
    @AfterEach()
    void resetForTest() {
        GlobalOpenTelemetry.resetForTest();
    }
    ...

@nhandev552
Copy link

@alberth-li how about this issue?, I also get the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants