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

tracing-opentelemetry: Docs for otel.kind are unclear about capitalisation #1209

Closed
nikclayton-dfinity opened this issue Jan 26, 2021 · 4 comments · Fixed by #1218
Closed
Labels
crate/opentelemetry Related to the `tracing-opentelemetry` crate.

Comments

@nikclayton-dfinity
Copy link

Bug Report

Version

Git version https://github.com/tokio-rs/tracing/blob/705613c3ef04e334b90a49a60676ff7de8e495bd/tracing-opentelemetry/src/lib.rs

Description

The documentation is unclear / inconsistent about the capitalisation of values for the otel.kind field.

//! * `otel.kind`: Set the span kind to one of the supported OpenTelemetry
//! [span kinds]. The value should be a string of any of the supported values:
//! `SERVER`, `CLIENT`, `PRODUCER`, `CONSUMER` or `INTERNAL`. Other values are
//! silently ignored.
lists the values in ALL-CAPS.

The example code, a few lines below, at

//! `trace_span!("request", "otel.kind" = "client", "http.url" = ..)`, and they
is all lower-case.

The test code in

tracing::debug_span!("request", otel.kind = "Server");
});
let recorded_kind = tracer.0.lock().unwrap().as_ref().unwrap().span_kind.clone();
assert_eq!(recorded_kind, Some(otel::SpanKind::Server))
}
#[test]
fn trace_id_from_existing_context() {
let tracer = TestTracer(Arc::new(Mutex::new(None)));
let subscriber = tracing_subscriber::registry().with(layer().with_tracer(tracer.clone()));
let trace_id = otel::TraceId::from_u128(42);
let existing_cx = OtelContext::current_with_span(TestSpan(otel::SpanContext::new(
trace_id,
otel::SpanId::from_u64(1),
0,
false,
Default::default(),
)));
let _g = existing_cx.attach();
tracing::collect::with_default(subscriber, || {
tracing::debug_span!("request", otel.kind = "Server");
uses Initial case / Sentence case.

The actual implementation appears to be case insensitive,

fn str_to_span_kind(s: &str) -> Option<otel::SpanKind> {
if s.eq_ignore_ascii_case("SERVER") {
Some(otel::SpanKind::Server)
} else if s.eq_ignore_ascii_case("CLIENT") {
Some(otel::SpanKind::Client)
} else if s.eq_ignore_ascii_case("PRODUCER") {
Some(otel::SpanKind::Producer)
} else if s.eq_ignore_ascii_case("CONSUMER") {
Some(otel::SpanKind::Consumer)
} else if s.eq_ignore_ascii_case("INTERNAL") {
Some(otel::SpanKind::Internal)
} else {
None
}
}
.

@morigs
Copy link

morigs commented Jan 27, 2021

I believe the best option is to replace string with enum. According to OTel spec spankind has a fixed number of variants. And the most actual implementation uses enums.

Type system is the best documentation 😄

@nikclayton-dfinity
Copy link
Author

Completely agree -- the equivalent Rust enum is https://github.com/open-telemetry/opentelemetry-rust/blob/45da275bd4d66cf8816eb9f3c7c15961ae2595f0/opentelemetry/src/trace/span.rs#L168-L238. Maybe the documentation could be updated to reflect this as best practice?

@hawkw
Copy link
Member

hawkw commented Jan 28, 2021

cc @jtescher

@hawkw hawkw added the crate/opentelemetry Related to the `tracing-opentelemetry` crate. label Jan 28, 2021
@jtescher
Copy link
Collaborator

Yeah these docs should be updated to use the enum. E.g. trace_span!("request", "otel.kind" = %SpanKind::Client, "http.url" = ..) is a better choice.

hawkw pushed a commit that referenced this issue Jan 30, 2021
This patch resolves the field value capitalization ambiguity currently
in `otel.kind` by instead recommending an enum value. This also brings
type safety to the value, further reducing the risk of typos and other
misuse.

Resolves #1209
hawkw pushed a commit that referenced this issue Feb 4, 2021
This patch resolves the field value capitalization ambiguity currently
in `otel.kind` by instead recommending an enum value. This also brings
type safety to the value, further reducing the risk of typos and other
misuse.

Resolves #1209
hawkw pushed a commit that referenced this issue Feb 4, 2021
This patch resolves the field value capitalization ambiguity currently
in `otel.kind` by instead recommending an enum value. This also brings
type safety to the value, further reducing the risk of typos and other
misuse.

Resolves #1209
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
This patch resolves the field value capitalization ambiguity currently
in `otel.kind` by instead recommending an enum value. This also brings
type safety to the value, further reducing the risk of typos and other
misuse.

Resolves tokio-rs#1209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/opentelemetry Related to the `tracing-opentelemetry` crate.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants