Skip to content

opentelemetry: set span kind through otel.kind #890

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

Merged
merged 3 commits into from
Aug 5, 2020

Conversation

frigus02
Copy link
Contributor

@frigus02 frigus02 commented Aug 5, 2020

Motivation

Some distributed tracing providers use information such as the span kind to enrich their UIs. The issue frigus02/opentelemetry-application-insights#5 shows an example with Azure Application Insights, which builds an application map based on client/server spans sent from multiple applications.

In order to make use of this with a combination of this tracing crate, together with OpenTelemetry exporters, we need a way of setting the span kind through the OpenTelemetry layer.

Solution

This solves the issue by adding support for the special attribute otel.kind to the OpenTelemetry layer. If set to SERVER, CLIENT, PRODUCER, CONSUMER or INTERNAL it sets the span kind of the internal OpenTelemetry span.

This follows the convention introduced with the otel.name attribute, which sets the name of the internal OpenTelemetry span.

OpenTelemetry supports a span kind as special metadata to spans. The
span kind defines relationships between spans (e.g. server vs client).
Some distributed tracing providers use this information to enrich their
UIs.

This makes it possible to set the span kind by adding a special
attribute called `otel.kind`, similar to the existing `otel.name`.
@frigus02 frigus02 requested review from jtescher and a team as code owners August 5, 2020 18:51
Copy link
Collaborator

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Thanks @frigus02, this looks good to me. Could you also update the doc comments that currently reference span.kind in https://github.com/tokio-rs/tracing/blob/master/tracing-opentelemetry/src/lib.rs#L26?

Change references of span.kind in the docs for the OpenTelemetry layer
to otel.kind.
@frigus02
Copy link
Contributor Author

frigus02 commented Aug 5, 2020

Oh yes, for sure. Good catch.

I am wondering about the casing of the values. Should we use uppercase, lowercase or allow both?

@jtescher
Copy link
Collaborator

jtescher commented Aug 5, 2020

Case insensitive matching may make sense here? Could also wait for #811 but if a user currently does otel.kind = "client" they may be confused when nothing happens.

@jtescher
Copy link
Collaborator

jtescher commented Aug 5, 2020

Yeah same thought, probably accepting both is the least confusing

@frigus02
Copy link
Contributor Author

frigus02 commented Aug 5, 2020

Agree, case insensitive matching sounds like the best option. I'm going to change that. Just need to look for the best way to do that 🙂

People may spell the span kind in different ways, e.g.: SERVER, server
or Server. Using case insensitive matching is hopefully the least
confusing.
@frigus02
Copy link
Contributor Author

frigus02 commented Aug 5, 2020

Okay, here we go. I'm not sure if that's the best way, but it feels good enough.

Copy link
Collaborator

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Great thanks @frigus02, lgtm

@jtescher jtescher merged commit 002497b into tokio-rs:master Aug 5, 2020
@frigus02 frigus02 deleted the otel-kind branch August 5, 2020 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants