Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpanContext implements serde::Serialize, Deserialize
Browse files Browse the repository at this point in the history
shaun-cox committed May 23, 2023
1 parent 0a893ce commit e03e474
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions opentelemetry-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ futures-util = { version = "0.3", default-features = false, features = ["std", "
indexmap = "1.8"
once_cell = "1.12.0"
pin-project-lite = { version = "0.2", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
thiserror = "1"
tokio-stream = { version = "0.1", optional = true }
urlencoding = "2.1.2"
7 changes: 7 additions & 0 deletions opentelemetry-api/src/trace/span_context.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ use std::num::ParseIntError;
use std::ops::{BitAnd, BitOr, Not};
use std::str::FromStr;
use thiserror::Error;
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

/// Flags that can be set on a [`SpanContext`].
///
@@ -17,6 +19,7 @@ use thiserror::Error;
///
/// [trace-flags]: https://www.w3.org/TR/trace-context/#trace-flags
#[derive(Clone, Debug, Default, PartialEq, Eq, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TraceFlags(u8);

impl TraceFlags {
@@ -87,6 +90,7 @@ impl fmt::LowerHex for TraceFlags {
///
/// The id is valid if it contains at least one non-zero byte.
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TraceId(u128);

impl TraceId {
@@ -148,6 +152,7 @@ impl fmt::LowerHex for TraceId {
///
/// The id is valid if it contains at least one non-zero byte.
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SpanId(u64);

impl SpanId {
@@ -213,6 +218,7 @@ impl fmt::LowerHex for SpanId {
///
/// [W3C specification]: https://www.w3.org/TR/trace-context/#tracestate-header
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TraceState(Option<VecDeque<(String, String)>>);

impl TraceState {
@@ -448,6 +454,7 @@ impl From<TraceStateError> for TraceError {
/// [`Span`]: crate::trace::Span
/// [W3C TraceContext specification]: https://www.w3.org/TR/trace-context
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SpanContext {
trace_id: TraceId,
span_id: SpanId,

0 comments on commit e03e474

Please sign in to comment.