Skip to content
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

Add Traceable interface #80788

Conversation

ywangd
Copy link
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 Indexing/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 (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Nov 17, 2021
@elasticmachine
Copy link
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
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 onTaskUnregistered(Task task);
void onUnregistered(Traceable traceable);
Copy link
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
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
Contributor

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

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
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
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 Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >enhancement Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants