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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Missing trace for JUnit5 BeforeAll/AfterAll methods in CIVisibility Instrumentation #6936

Open
sergeidyga opened this issue Apr 23, 2024 · 3 comments
Assignees

Comments

@sergeidyga
Copy link

sergeidyga commented Apr 23, 2024

Hello team 馃憢

I'm using JUnit5 Instrumentation with following config:

dd.civisibility.enabled=true
dd.civisibility.agentless.enabled=true

Following class:

import datadog.trace.api.CorrelationIdentifier
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class TestSuite {

    @BeforeAll
    fun beforeAll() {
        println("beforeAll " + CorrelationIdentifier.getTraceId())
    }

    @BeforeEach
    fun beforeEach() {
        println("beforeEach " + CorrelationIdentifier.getTraceId())
    }

    @Test
    fun test() {
        println("test " + CorrelationIdentifier.getTraceId())
    }

    @AfterEach
    fun afterEach() {
        println("afterEach " + CorrelationIdentifier.getTraceId())
    }

    @AfterAll
    fun afterAll() {
        println("afterAll " + CorrelationIdentifier.getTraceId())
    }

}

Gives following output:

beforeAll 0
beforeEach 8692252888825984513
test 8692252888825984513
afterEach 8692252888825984513
afterAll 0

I'm curious why active trace is missing in beforeAll and afterAll? I was expecting TestSession and TestModule spans to be already created at this point by CIVisibility auto-instrumentation.

Beside this main question I also noticed that beforeEach and afterEach spans are not visible in DD UI (only the test span).

Context: JUnit5 Lifecycle methods (methods annotated with @BeforeAll, @AfterAll, @BeforeEach, or @AfterEach that are used for setting up and tearing down tests) are significant subjects for tracing because, like test methods, they often involve network requests, database queries, and similar operations.

Thank you for looking into this!

@sergeidyga sergeidyga changed the title Trace Lifecycle methods in JUnit5 instrumentation Feature Request: JUnit5 Instrumentation to Include Lifecycle Methods in Tracing Apr 23, 2024
@sergeidyga sergeidyga changed the title Feature Request: JUnit5 Instrumentation to Include Lifecycle Methods in Tracing Feature Request: Missing trace for JUnit5 BeforeAll/AfterAll methods in CIVisibility Instrumentation Apr 30, 2024
@sergeidyga
Copy link
Author

I've updated the description - turns out the trace is only missing for BeforeAll/AfterAll methods

@nikita-tkachenko-datadog
Copy link
Contributor

Hi @sergeidyga, thank you for reporting this!

You're right that TestSession and TestModule spans already exist by the time a method marked with@BeforeAll is executed. Moreover, TestSuite exists as well, so it'd make sense to have spans for these lifecycle methods as children of their respective suite.
The problem is that to have a suite child that is not a test case a few things have to be changed both in the tracer and in the Datadog backend.
We've had this feature in our backlog for a while, unfortunately there are no plans to support it in the near future (although it might change given that there is user demand).

@sergeidyga
Copy link
Author

sergeidyga commented May 21, 2024

Hi @nikita-tkachenko-datadog,

Thank you for confirming that the TestSuite span exists by the time JUnit lifecycle methods start. But although TestSuite span exist I'm not able to get its traceId with CorrelationIdentifier.getTraceId()? So I'm I doubt how to access a suite span in order to build a test span as its child?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants