Skip to content

Conversation

@idegtiarenko
Copy link
Contributor

This change contains a small utility that allows to create a sub-spans for synchronous blocks of code that do not require task registration for them. The change itself is not adding any usages. They are going to be implemented separately. Utility could be used as following:

try (var trace = trace(threadPool, tracer, "my-trace") { ... }

I have couple of example usages in #109244

@idegtiarenko idegtiarenko added >non-issue :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team v8.15.0 labels Jun 7, 2024
@idegtiarenko idegtiarenko requested review from a team and rjernst June 7, 2024 09:55
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Comment on lines +34 to +35
var ctx = threadPool.getThreadContext().newTraceContext();
tracer.startTrace(threadPool.getThreadContext(), span, name, attributes);
Copy link
Contributor

Choose a reason for hiding this comment

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

First off: this is great and allows to create sub-spans of the current thread context very easily.

However, I wonder if we should use threadPool.getThreadContext().newTraceContext(); this mutates the current thread local state, and in particular only works if there's a strict hierarchy of spans. @elastic/es-core-infra what do you think?

It might be sufficient to copy the logic from newTraceContext to create a new, separate TraceContext and store it as part of the Releaseable that is returned here. I attempted that here and it seemed to work fine.

This would allow create interleaved traces in the same thread which would provide more flexibility; my use case for this is seeing when individual ESQL operators start and stop, even though they are executed concurrently on the same thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried about the use of threadpool & threadcontext here.
we should aim to use org.eleasticsearch.telemetry.tracing.TraceContext
I think it should be possible to either:

  • refactor the Pr to have the new context and context to restore (would be probably a bit ugly)
  • refactor the TraceContext to create a newTraceContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactor the Pr to have the new context and context to restore (would be probably a bit ugly)

Not sure I follow, threadPool.getThreadContext().newTraceContext() creates a new context and returns a releasable to rollback to the previous one.
To me it sounds like what is suggested, however implicit (may be the comment is about it?)

Copy link
Contributor

Choose a reason for hiding this comment

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

refactor the Pr to have the new context and context to restore (would be probably a bit ugly)

as part of a method signature.
My point is that we should not try to add ThreadContext in the telemetry api

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

I am not convinced we should do this like this. This will be only usable in server, would we like to use it in plugins too? (currently possible due to this api living in server, but this was just a shortcut we did in the past)

Comment on lines +34 to +35
var ctx = threadPool.getThreadContext().newTraceContext();
tracer.startTrace(threadPool.getThreadContext(), span, name, attributes);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried about the use of threadpool & threadcontext here.
we should aim to use org.eleasticsearch.telemetry.tracing.TraceContext
I think it should be possible to either:

  • refactor the Pr to have the new context and context to restore (would be probably a bit ugly)
  • refactor the TraceContext to create a newTraceContext

import org.elasticsearch.core.Releasable;
import org.elasticsearch.telemetry.tracing.Traceable;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.threadpool.ThreadPool;
Copy link
Contributor

Choose a reason for hiding this comment

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

so I am planning to move the telemetry package into its own :lib this import will make it impossible.

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

Labels

:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants