-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Micrometer tracing #451
Comments
@kagkarlsson If you agree with this idea, I can contribute the required changes. |
I think that makes sense yes, as long as the code is acceptable. Not sure if we have all we need for it, I was thinking it could be implemented with what is now called |
The starting idea would be to play around with
|
We would also benefit from this, maybe I don't think it's possible to implement tracing using the |
A loose plan is to deprecate StatsRegistry and replace it with one or many Listener interfaces, also covering started and completed events. If anyone would like to take a stab at that (adding some form of adapter for StatsRegistry), feel free to try |
I've created a basic proof of concept that divides However, a more efficient approach might be to transform |
How does #504 work for this? void onExecutionStart(CurrentlyExecuting currentlyExecuting);
void onExecutionComplete(ExecutionComplete executionComplete); |
@NicklasWallgren Any chance you could try reimplementing your PoC using the new |
Great! It should possible to implement tracing with help of the new I've implemented a temporary public class ElasticApmExecutionHandler<T extends ObservableTaskContext> implements ExecutionHandler<T> {
private static final String TRANSACTION_TYPE = "queue.task";
private final ExecutionHandler<T> executionHandler;
private ElasticApmExecutionHandler(final ExecutionHandler<T> executionHandler) {
this.executionHandler = executionHandler;
}
@Override
public CompletionHandler<T> execute(final TaskInstance<T> taskInstance, final ExecutionContext executionContext) {
final Execution execution = executionContext.getExecution();
final T data = taskInstance.getData();
final Transaction transaction = ElasticApm
.startTransactionWithRemoteParent((it) -> TraceIdHeaderValueFactory.create(data.traceId(), data.spanId()));
try (final Scope scope = transaction.activate()) {
transaction.setName("QueueTask#" + execution.getTaskName());
transaction.setType(TRANSACTION_TYPE);
transaction.setLabel("queue.task.id", execution.getId());
transaction.setLabel("queue.task.name", execution.getTaskName());
return executionHandler.execute(taskInstance, executionContext);
} catch (final Exception e) {
transaction.captureException(e);
throw e;
} finally {
transaction.end();
}
}
public static <T extends ObservableTaskContext> ElasticApmExecutionHandler<T> wrap(final ExecutionHandler<T> executionHandler) {
return new ElasticApmExecutionHandler<>(executionHandler);
}
private static class TraceIdHeaderValueFactory {
/**
* Builds a trace parent which follows the W3C TraceParent standard.
* <p>
* Format: trace-id "-" span-id "-" trace-flags
*
* @return the trace parent
*/
public static String create(final String traceId, final String spanId) {
return String.format("00-%s-%s-01", traceId, spanId);
}
}
} |
After some consideration I added an interceptor-concept as well. See PR #504 |
Replaces the old `StatsRegistry` and adds more detailed events: ```java void onExecutionScheduled(TaskInstanceId taskInstanceId, Instant executionTime); void onExecutionStart(CurrentlyExecuting currentlyExecuting); void onExecutionComplete(ExecutionComplete executionComplete); void onExecutionDead(Execution execution); void onExecutionFailedHeartbeat(CurrentlyExecuting currentlyExecuting); ``` Additionally adds `ExecutionInterceptor` as a way of injecting wrapping-logic for all executions. ```java CompletionHandler<?> execute( TaskInstance<?> taskInstance, ExecutionContext executionContext, ExecutionChain chain); ``` ## Fixes * #451
Expected Behavior
Micrometer tracing available on each task execution.
Would be great if the ExecutePicked would be wrapped in a tracing context: One traceId, and different spans for
complete
orfailure
or even the same spanId.Current Behavior
No tracing available
The text was updated successfully, but these errors were encountered: