Skip to content

Add Traceable interface#80788

Merged
elasticsearchmachine merged 4 commits intoelastic:feature/apm-integrationfrom
ywangd:apm/add-traceable-interface
Nov 17, 2021
Merged

Add Traceable interface#80788
elasticsearchmachine merged 4 commits intoelastic:feature/apm-integrationfrom
ywangd:apm/add-traceable-interface

Conversation

@ywangd
Copy link
Copy Markdown
Member

@ywangd ywangd commented Nov 17, 2021

Task now implements the Traceable interface. This allows other traceable
entities to be developed.

Task now implements the Traceable interface. This allows other traceable
entities to be developed.
@ywangd ywangd added >enhancement :Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. labels Nov 17, 2021
@elasticmachine elasticmachine added the Team:Distributed Meta label for distributed team. label Nov 17, 2021
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Comment on lines +67 to +84
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() + "]"
);
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe registered/unregistered is still related to the task naming.
Should generic methods be called onSpanStarted/onStarted or something similar?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks. I changed the method names to onTraceStarted and onTraceStopped.

@ywangd ywangd requested a review from idegtiarenko November 17, 2021 11:07
Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM

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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks I updated as suggested.

Copy link
Copy Markdown
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM

@ywangd ywangd added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Nov 17, 2021
@elasticsearchmachine elasticsearchmachine merged commit 34239d4 into elastic:feature/apm-integration Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >enhancement Team:Distributed Meta label for distributed team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants