Skip to content

Commit c9a58c4

Browse files
jtescherhawkw
authored andcommitted
opentelemetry: clarify otel.kind field usage in docs (#1218)
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
1 parent a018071 commit c9a58c4

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

tracing-opentelemetry/src/layer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ impl Timings {
585585
#[cfg(test)]
586586
mod tests {
587587
use super::*;
588+
use opentelemetry::trace::SpanKind;
588589
use std::sync::{Arc, Mutex};
589590
use std::time::SystemTime;
590591
use tracing_subscriber::prelude::*;
@@ -656,7 +657,7 @@ mod tests {
656657
let subscriber = tracing_subscriber::registry().with(layer().with_tracer(tracer.clone()));
657658

658659
tracing::subscriber::with_default(subscriber, || {
659-
tracing::debug_span!("request", otel.kind = "Server");
660+
tracing::debug_span!("request", otel.kind = %SpanKind::Server);
660661
});
661662

662663
let recorded_kind = tracer.0.lock().unwrap().as_ref().unwrap().span_kind.clone();
@@ -678,7 +679,7 @@ mod tests {
678679
let _g = existing_cx.attach();
679680

680681
tracing::subscriber::with_default(subscriber, || {
681-
tracing::debug_span!("request", otel.kind = "Server");
682+
tracing::debug_span!("request", otel.kind = %SpanKind::Server);
682683
});
683684

684685
let recorded_trace_id = tracer

tracing-opentelemetry/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222
//! * `otel.name`: Override the span name sent to OpenTelemetry exporters.
2323
//! Setting this field is useful if you want to display non-static information
2424
//! in your span name.
25-
//! * `otel.kind`: Set the span kind to one of the supported OpenTelemetry
26-
//! [span kinds]. The value should be a string of any of the supported values:
27-
//! `SERVER`, `CLIENT`, `PRODUCER`, `CONSUMER` or `INTERNAL`. Other values are
28-
//! silently ignored.
25+
//! * `otel.kind`: Set the span kind to one of the supported OpenTelemetry [span kinds].
2926
//!
30-
//! [span kinds]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#spankind
27+
//! [span kinds]: https://docs.rs/opentelemetry/latest/opentelemetry/trace/enum.SpanKind.html
3128
//!
3229
//! ### Semantic Conventions
3330
//!
3431
//! OpenTelemetry defines conventional names for attributes of common
3532
//! operations. These names can be assigned directly as fields, e.g.
36-
//! `trace_span!("request", "otel.kind" = "client", "http.url" = ..)`, and they
33+
//! `trace_span!("request", "otel.kind" = %SpanKind::Client, "http.url" = ..)`, and they
3734
//! will be passed through to your configured OpenTelemetry exporter. You can
3835
//! find the full list of the operations and their expected field names in the
3936
//! [semantic conventions] spec.

0 commit comments

Comments
 (0)