Skip to content

Commit baccb1b

Browse files
committed
More documentation
1 parent 85de5a9 commit baccb1b

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

sdk/core/azure_core/src/http/policies/request_instrumentation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ mod tests {
560560
assert_eq!(req.method(), &Method::Get);
561561
assert_eq!(
562562
req.headers()
563-
.get_optional_str(HeaderName::from_static("traceparent")),
563+
.get_optional_str(&HeaderName::from_static("traceparent")),
564564
Some("00-<trace_id>-<span_id>-01")
565565
);
566566
Ok(RawResponse::from_bytes(

sdk/core/azure_core_opentelemetry/src/span.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
//! OpenTelemetry implementation of typespec_client_core tracing traits.
55
66
use crate::attributes::AttributeValue as ConversionAttributeValue;
7-
use azure_core::{
8-
tracing::{AsAny, AttributeValue, Span, SpanGuard, SpanStatus},
9-
Result,
10-
};
7+
use azure_core::tracing::{AsAny, AttributeValue, Span, SpanGuard, SpanStatus};
118
use opentelemetry::{propagation::TextMapPropagator, trace::TraceContextExt};
129
use opentelemetry_http::HeaderInjector;
1310
use opentelemetry_sdk::propagation::TraceContextPropagator;
@@ -132,9 +129,8 @@ struct OpenTelemetrySpanGuard {
132129
}
133130

134131
impl SpanGuard for OpenTelemetrySpanGuard {
135-
fn end(self) -> Result<()> {
132+
fn end(self) {
136133
// The span is ended when the guard is dropped, so no action needed here.
137-
Ok(())
138134
}
139135
}
140136

sdk/typespec/typespec_client_core/src/tracing/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ pub enum SpanKind {
136136

137137
pub trait SpanGuard {
138138
/// Ends the span when dropped.
139-
fn end(self) -> crate::Result<()>;
139+
fn end(self);
140140
}
141141

142+
/// A trait that represents a span in distributed tracing.
143+
///
144+
/// This trait defines the methods that a span must implement to be used in distributed tracing.
145+
/// It includes methods for setting attributes, recording errors, and managing the span's lifecycle.
142146
pub trait Span: AsAny + Send + Sync {
143147
fn is_recording(&self) -> bool;
144148

@@ -158,6 +162,11 @@ pub trait Span: AsAny + Send + Sync {
158162
fn set_status(&self, status: SpanStatus);
159163

160164
/// Sets an attribute on the current span.
165+
///
166+
/// # Arguments
167+
/// - `key`: The key of the attribute to set.
168+
/// - `value`: The value of the attribute to set.
169+
///
161170
fn set_attribute(&self, key: &'static str, value: attributes::AttributeValue);
162171

163172
/// Records a Rust standard error on the current span.
@@ -171,6 +180,7 @@ pub trait Span: AsAny + Send + Sync {
171180
fn record_error(&self, error: &dyn std::error::Error);
172181

173182
/// Temporarily sets the span as the current active span in the context.
183+
///
174184
/// # Arguments
175185
/// - `context`: The context in which to set the current span.
176186
///
@@ -182,6 +192,15 @@ pub trait Span: AsAny + Send + Sync {
182192
///
183193
fn set_current(&self, context: &Context) -> crate::Result<Box<dyn SpanGuard>>;
184194

195+
/// Adds telemetry headers to the request for distributed tracing.
196+
///
197+
/// # Arguments
198+
/// - `request`: A mutable reference to the request to which headers will be added.
199+
///
200+
/// This method should be called before sending the request to ensure that the tracing information
201+
/// is included in the request headers. It typically adds the [W3C Distributed Tracing](https://www.w3.org/TR/trace-context/)
202+
/// headers to the request.
203+
///
185204
fn propagate_headers(&self, request: &mut Request);
186205
}
187206

0 commit comments

Comments
 (0)