Skip to content

Add OpenTelemetry tracing to EditorServiceManager and formatting #104

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davo-canva
Copy link

@davo-canva davo-canva commented Apr 30, 2025

This is pretty gnarly, but chucking this up to get feedback. This uses IntelliJ's OpenTelemetry tracing support. The hard yards was authored by JetBrains AI Assistant with Claude 3.7 Sonnet.

You'll probably want to review this with "hide whitespace changes" on.

Jaeger screenshot

Happy to rename the spans if anyone has good suggestions.

The below description was generated by JetBrains AI Assistant:

Extended EditorServiceManager and related classes with OpenTelemetry spans to track performance and debug issues effectively. Applied spans to key methods, such as service initialization, formatting, and cache priming, to capture execution details and errors comprehensively.

Extended EditorServiceManager and related classes with OpenTelemetry spans to track performance and debug issues effectively. Applied spans to key methods, such as service initialization, formatting, and cache priming, to capture execution details and errors comprehensively.
@@ -28,72 +38,143 @@ class DprintFormattingTask(
) {
private var formattingIds = mutableListOf<Int>()
private var isCancelled = false
private val tracer: Tracer = TelemetryManager.getInstance().getTracer(DprintScope.FormatterScope)
Copy link
Author

@davo-canva davo-canva May 1, 2025

Choose a reason for hiding this comment

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

TelemetryManager is technically annotated as internal API, but AFAICT the API hasn't really changed 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be fine and there is a IJ verify gradle task that makes sure it works with the configured IJ versions in the verifier

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the build, this blows up.

} else {
mutableListOf(
TextRange(0, content.length),
val rootSpan =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just as an FYI this class is only run for the replacement of the default IJ formatter. So when you run shift+cmd+option+L or whatever it is.

You probably want to have something that wraps the lower level activities that are shared between this and the code which runs if the user has configured format on save through the dprint config window. I believe that is the EditorServiceManager or the Process depending on what you want to capture in OTEL.

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.

2 participants