Add Traceable interface#80788
Add Traceable interface#80788elasticsearchmachine merged 4 commits intoelastic:feature/apm-integrationfrom
Conversation
Task now implements the Traceable interface. This allows other traceable entities to be developed.
|
Pinging @elastic/es-distributed (Team:Distributed) |
| for (Map.Entry<String, Object> entry : traceable.getAttributes().entrySet()) { | ||
| final Object value = entry.getValue(); | ||
| if (value instanceof String) { | ||
| span.setAttribute(entry.getKey(), (String) value); | ||
| } else if (value instanceof Long) { | ||
| span.setAttribute(entry.getKey(), (Long) value); | ||
| } else if (value instanceof Integer) { | ||
| span.setAttribute(entry.getKey(), (Integer) value); | ||
| } else if (value instanceof Double) { | ||
| span.setAttribute(entry.getKey(), (Double) value); | ||
| } else if (value instanceof Boolean) { | ||
| span.setAttribute(entry.getKey(), (Boolean) value); | ||
| } else { | ||
| throw new IllegalArgumentException( | ||
| "span attributes do not support value type of [" + value.getClass().getCanonicalName() + "]" | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
This is not pretty. But it does the job for now and keep other parts unware of the opentelemetry dependencies. We can improve it once we know more about what other things needed by the new Traceable interface.
| void onRegistered(Traceable traceable); | ||
|
|
||
| void onTaskUnregistered(Task task); | ||
| void onUnregistered(Traceable traceable); |
There was a problem hiding this comment.
I believe registered/unregistered is still related to the task naming.
Should generic methods be called onSpanStarted/onStarted or something similar?
There was a problem hiding this comment.
Thanks. I changed the method names to onTraceStarted and onTraceStopped.
…m/add-traceable-interface
| final Span span = tracer.spanBuilder(task.getAction()).startSpan(); | ||
| span.setAttribute("es.task.id", task.getId()); | ||
| spans.computeIfAbsent(traceable.getSpanId(), spanId -> { | ||
| final Span span = tracer.spanBuilder(traceable.getSpanName()).startSpan(); |
There was a problem hiding this comment.
When setting attributes while creating the span, it's common to use SpanBuilder.setAttribute(key, value). It would look like:
SpanBuilder spanBuilder = tracer.spanBuilder(traceable.getSpanName());
for (Map.Entry<String, Object> entry : traceable.getAttributes().entrySet()) {
Object value = entry.getValue();
if (value instanceof String) {
spanBuilder.setAttribute(entry.getKey(), (String) value);
} else if (value instanceof Long) {
spanBuilder.setAttribute(entry.getKey(), (Long) value);
} else if (value instanceof Integer) {
spanBuilder.setAttribute(entry.getKey(), (Integer) value);
} else if (value instanceof Double) {
spanBuilder.setAttribute(entry.getKey(), (Double) value);
} else if (value instanceof Boolean) {
spanBuilder.setAttribute(entry.getKey(), (Boolean) value);
} else {
throw new IllegalArgumentException(
"span attributes do not support value type of [" + value.getClass().getCanonicalName() + "]"
);
}
return spanBuilder.startSpan();There was a problem hiding this comment.
Thanks I updated as suggested.
Task now implements the Traceable interface. This allows other traceable
entities to be developed.