Skip to content

Commit

Permalink
Merge branch 'main' into issue-1244-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Feb 14, 2024
2 parents 1765fe7 + 49f1be6 commit 4b8f83e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
**/*.rs.bk
Cargo.lock
/.idea/

.cosine
4 changes: 2 additions & 2 deletions opentelemetry-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "opentelemetry-http"
version = "0.10.0"
description = "Helper implementations for exchange of traces and metrics over HTTP"
description = "Helper implementations for sending HTTP requests. Uses include propagating and extracting context over http, exporting telemetry, requesting sampling strategies."
homepage = "https://github.com/open-telemetry/opentelemetry-rust"
repository = "https://github.com/open-telemetry/opentelemetry-rust"
keywords = ["opentelemetry", "tracing", "metrics"]
keywords = ["opentelemetry", "tracing", "context", "propagation"]
license = "Apache-2.0"
edition = "2021"
rust-version = "1.65"
Expand Down
12 changes: 11 additions & 1 deletion opentelemetry-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pub use bytes::Bytes;
pub use http::{Request, Response};
use opentelemetry::propagation::{Extractor, Injector};

/// Helper for injecting headers into HTTP Requests. This is used for OpenTelemetry context
/// propagation over HTTP.
/// See [this](https://github.com/open-telemetry/opentelemetry-rust/blob/main/examples/tracing-http-propagator/README.md)
/// for example usage.
pub struct HeaderInjector<'a>(pub &'a mut http::HeaderMap);

impl<'a> Injector for HeaderInjector<'a> {
Expand All @@ -20,6 +24,10 @@ impl<'a> Injector for HeaderInjector<'a> {
}
}

/// Helper for extracting headers from HTTP Requests. This is used for OpenTelemetry context
/// propagation over HTTP.
/// See [this](https://github.com/open-telemetry/opentelemetry-rust/blob/main/examples/tracing-http-propagator/README.md)
/// for example usage.
pub struct HeaderExtractor<'a>(pub &'a http::HeaderMap);

impl<'a> Extractor for HeaderExtractor<'a> {
Expand All @@ -39,7 +47,9 @@ impl<'a> Extractor for HeaderExtractor<'a> {

pub type HttpError = Box<dyn std::error::Error + Send + Sync + 'static>;

/// A minimal interface necessary for export spans over HTTP.
/// A minimal interface necessary for sending requests over HTTP.
/// Used primarily for exporting telemetry over HTTP. Also used for fetching
/// sampling strategies for JaegerRemoteSampler
///
/// Users sometime choose HTTP clients that relay on a certain async runtime. This trait allows
/// users to bring their choice of HTTP client.
Expand Down
9 changes: 6 additions & 3 deletions opentelemetry-sdk/src/propagation/trace_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ impl TraceContextPropagator {
// supported sampling bit.
let trace_flags = TraceFlags::new(opts) & TraceFlags::SAMPLED;

let trace_state: TraceState =
TraceState::from_str(extractor.get(TRACESTATE_HEADER).unwrap_or(""))
.unwrap_or_else(|_| TraceState::default());
let trace_state = match extractor.get(TRACESTATE_HEADER) {
Some(trace_state_str) => {
TraceState::from_str(trace_state_str).unwrap_or_else(|_| TraceState::default())
}
None => TraceState::default(),
};

// create context
let span_context = SpanContext::new(trace_id, span_id, trace_flags, true, trace_state);
Expand Down

0 comments on commit 4b8f83e

Please sign in to comment.