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

Support Tracing of Dependency Injection #11449

Merged
merged 16 commits into from
Jan 14, 2025
Merged

Conversation

graemerocher
Copy link
Contributor

@graemerocher graemerocher commented Dec 16, 2024

Adds the ability to trace the behaviour of dependency and configuration injection. Can be activated a number of different ways, the simplest being an environment variable:

MICRONAUT_INJECT_TRACE=.+ ./gradlew run

Which enables useful output such as what is the configuration profile of the application, where configuration is read from, what beans are created, how long the bean took to be created, the graph of the bean creation and where it was created from.

To support this, the PR also adds property origin tracking so that one can inspect where a property originated from.

In addition, some of the changes in DefaultBeanContext are in order to reduce stack trace sizes which were starting to get out of hand.

@graemerocher graemerocher added the type: enhancement New feature or request label Dec 16, 2024
@graemerocher graemerocher marked this pull request as draft December 16, 2024 19:43
@graemerocher graemerocher force-pushed the dependency-injection-debugger branch from 3735137 to e01e206 Compare January 2, 2025 19:01
@graemerocher graemerocher marked this pull request as ready for review January 3, 2025 17:14
return Set.of();
}

void startTrace(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move all the tracing code into some other class, not to have it in a public enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the trace methods are not currently public but package private. In the future yes it would be good to add a public API but for the moment it is package private / internal

@dstepanov
Copy link
Contributor

Can you show an example of the output?

@dstepanov
Copy link
Contributor

Maybe one of the outputs can be a flame graph like the async profiler output Async profiler output

@graemerocher graemerocher force-pushed the dependency-injection-debugger branch from 079f97d to 25e2da1 Compare January 13, 2025 16:17
@graemerocher
Copy link
Contributor Author

Example Output

Screenshot 2025-01-08 at 08 45 59

@graemerocher
Copy link
Contributor Author

More complex bean resolution debug output of the creation of the DataSource from Micronaut-SQL

Screenshot 2025-01-13 at 14 41 05

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
4 New Bugs (required ≤ 0)
9 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@graemerocher graemerocher merged commit 40f5e30 into 4.8.x Jan 14, 2025
19 of 22 checks passed
@graemerocher graemerocher deleted the dependency-injection-debugger branch January 14, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants