Skip to content

Commit

Permalink
Remove serialize feature
Browse files Browse the repository at this point in the history
Removes non-spec serialization support to reduce public API surface
area.
  • Loading branch information
jtescher committed Feb 19, 2022
1 parent dacd75a commit 11e88a0
Show file tree
Hide file tree
Showing 23 changed files with 8 additions and 148 deletions.
2 changes: 1 addition & 1 deletion examples/basic-otlp-http/Cargo.toml
Expand Up @@ -5,6 +5,6 @@ edition = "2018"
publish = false

[dependencies]
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] }
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics"] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["http-proto", "reqwest-client"] }
tokio = { version = "1.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/basic-otlp-with-selector/Cargo.toml
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
futures-util = { version = "0.3", default-features = false, features = ["std"] }
lazy_static = "1.4"
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] }
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics"] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["tonic", "metrics"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/basic-otlp/Cargo.toml
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
futures-util = { version = "0.3", default-features = false, features = ["std"] }
lazy_static = "1.4"
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] }
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics"] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["tonic", "metrics"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
3 changes: 1 addition & 2 deletions examples/basic/Cargo.toml
Expand Up @@ -7,8 +7,7 @@ publish = false
[dependencies]
futures-util = { version = "0.3", default-features = false, features = ["std"] }
lazy_static = "1.4"
opentelemetry = { path = "../../opentelemetry", features = ["serialize", "rt-tokio", "metrics"] }
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics"] }
opentelemetry-jaeger = { path = "../../opentelemetry-jaeger", features = ["rt-tokio"] }
serde_json = "1.0"
thrift = "0.13"
tokio = { version = "1.0", features = ["full"] }
10 changes: 2 additions & 8 deletions examples/basic/src/main.rs
Expand Up @@ -6,7 +6,7 @@ use opentelemetry::sdk::{metrics::PushController, trace as sdktrace, Resource};
use opentelemetry::trace::TraceError;
use opentelemetry::{
baggage::BaggageExt,
metrics::{MetricsError, ObserverResult},
metrics::ObserverResult,
trace::{TraceContextExt, Tracer},
Context, Key, KeyValue,
};
Expand All @@ -29,13 +29,7 @@ fn delayed_interval(duration: Duration) -> impl Stream<Item = tokio::time::Insta
}

fn init_meter() -> PushController {
opentelemetry::sdk::export::metrics::stdout(tokio::spawn, delayed_interval)
.with_formatter(|batch| {
serde_json::to_value(batch)
.map(|value| value.to_string())
.map_err(|err| MetricsError::Other(err.to_string()))
})
.init()
opentelemetry::sdk::export::metrics::stdout(tokio::spawn, delayed_interval).init()
}

const FOO_KEY: Key = Key::from_static_str("ex.com/foo");
Expand Down
2 changes: 1 addition & 1 deletion examples/dynatrace/Cargo.toml
Expand Up @@ -8,7 +8,7 @@ publish = false
futures = "0.3"
http = "0.2"
lazy_static = "1.4"
opentelemetry = { path = "../../opentelemetry", default-features = false, features = ["trace", "serialize"] }
opentelemetry = { path = "../../opentelemetry", default-features = false, features = ["trace"] }
opentelemetry-dynatrace = { path = "../../opentelemetry-dynatrace" }
opentelemetry-http = { path = "../../opentelemetry-http", default-features = false }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", default-features = false, features = ["http-proto", "reqwest-client"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/external-otlp-tonic-tokio/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
publish = false

[dependencies]
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] }
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics"] }
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["tonic", "tls", "tls-roots"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-api/Cargo.toml
Expand Up @@ -9,7 +9,6 @@ futures-channel = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["std", "sink"] }
lazy_static = "1.4"
pin-project = { version = "1.0.2", optional = true }
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
thiserror = "1"
tokio-stream = { version = "0.1", optional = true }

Expand All @@ -24,5 +23,4 @@ js-sys = "0.3"
default = ["trace"]
trace = ["pin-project"]
metrics = ["fnv"]
serialize = ["serde"]
testing = ["trace"]
4 changes: 0 additions & 4 deletions opentelemetry-api/src/baggage.rs
Expand Up @@ -12,8 +12,6 @@
//! [`BaggagePropagator`]: crate::sdk::propagation::BaggagePropagator
//! [W3C Baggage]: https://w3c.github.io/baggage
use crate::{Context, Key, KeyValue, Value};
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::collections::{hash_map, HashMap};
use std::iter::FromIterator;

Expand Down Expand Up @@ -375,7 +373,6 @@ impl BaggageExt for Context {
/// `BaggageMetadata` can be added to values in the form of a property set,
/// represented as semi-colon `;` delimited list of names and/or name-value
/// pairs, e.g. `;k1=v1;k2;k3=v3`.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialOrd, PartialEq, Default)]
pub struct BaggageMetadata(String);

Expand All @@ -399,7 +396,6 @@ impl From<&str> for BaggageMetadata {
}

/// [`Baggage`] name-value pairs with their associated metadata.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct KeyValueMetadata {
/// Dimension or event key
Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-api/src/common.rs
@@ -1,10 +1,7 @@
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt;

/// Key used for metric `AttributeSet`s and trace `Span` attributes.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Key(Cow<'static, str>);

Expand Down Expand Up @@ -93,7 +90,6 @@ impl fmt::Display for Key {
}

/// Array of homogeneous values
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub enum Array {
/// Array of bools
Expand Down Expand Up @@ -157,7 +153,6 @@ into_array!(
);

/// Value types for use in `KeyValue` pairs.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
/// bool values
Expand Down Expand Up @@ -237,7 +232,6 @@ impl fmt::Display for Value {
}

/// `KeyValue` pairs are used by `AttributeSet`s and `Span` attributes.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct KeyValue {
/// Dimension or event key
Expand Down
4 changes: 0 additions & 4 deletions opentelemetry-api/src/trace/mod.rs
Expand Up @@ -150,8 +150,6 @@
//! ```

use futures_channel::{mpsc::TrySendError, oneshot::Canceled};
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt;
use std::time;
Expand Down Expand Up @@ -242,7 +240,6 @@ pub trait IdGenerator: Send + Sync + fmt::Debug {

/// A `Span` has the ability to add events. Events have a time associated
/// with the moment when they are added to the `Span`.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Event {
/// Event name
Expand Down Expand Up @@ -284,7 +281,6 @@ impl Event {

/// During the `Span` creation user MUST have the ability to record links to other `Span`s. Linked
/// `Span`s can be from the same or a different trace.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Link {
span_context: SpanContext,
Expand Down
4 changes: 0 additions & 4 deletions opentelemetry-api/src/trace/span.rs
Expand Up @@ -16,8 +16,6 @@
//! implementations MUST NOT allow callers to create Spans directly. All `Span`s MUST be created
//! via a Tracer.
use crate::{trace::SpanContext, KeyValue};
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -212,7 +210,6 @@ pub trait Span {
/// | `Producer` | | yes | | yes |
/// | `Consumer` | | yes | yes | |
/// | `Internal` | | | | |
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub enum SpanKind {
/// Indicates that the span describes a synchronous request to
Expand Down Expand Up @@ -254,7 +251,6 @@ impl fmt::Display for SpanKind {
/// The `StatusCode` interface represents the status of a finished `Span`.
/// It's composed of a canonical code in conjunction with an optional
/// descriptive message.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq, Copy)]
pub enum StatusCode {
/// The default status.
Expand Down
7 changes: 0 additions & 7 deletions opentelemetry-api/src/trace/span_context.rs
Expand Up @@ -10,8 +10,6 @@
//! The spec can be viewed here: <https://github.com/open-telemetry/opentelemetry-specification/blob/v1.3.0/specification/trace/api.md#spancontext>
//!
//! [w3c TraceContext specification]: https://www.w3.org/TR/trace-context/
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::collections::VecDeque;
use std::fmt;
use std::hash::Hash;
Expand All @@ -27,7 +25,6 @@ use thiserror::Error;
/// See the W3C TraceContext specification's [trace-flags] section for more details.
///
/// [trace-flags]: https://www.w3.org/TR/trace-context/#trace-flags
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Copy, Hash)]
pub struct TraceFlags(u8);

Expand Down Expand Up @@ -98,7 +95,6 @@ impl fmt::LowerHex for TraceFlags {
/// A 16-byte value which identifies a given trace.
///
/// The id is valid if it contains at least one non-zero byte.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
pub struct TraceId(pub(crate) u128);

Expand Down Expand Up @@ -160,7 +156,6 @@ impl fmt::LowerHex for TraceId {
/// An 8-byte value which identifies a given span.
///
/// The id is valid if it contains at least one non-zero byte.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
pub struct SpanId(pub(crate) u64);

Expand Down Expand Up @@ -226,7 +221,6 @@ impl fmt::LowerHex for SpanId {
/// Please review the [W3C specification] for details on this field.
///
/// [W3C specification]: https://www.w3.org/TR/trace-context/#tracestate-header
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
pub struct TraceState(Option<VecDeque<(String, String)>>);

Expand Down Expand Up @@ -445,7 +439,6 @@ pub enum TraceStateError {
///
/// Spans that do not have the `sampled` flag set in their [`TraceFlags`] will
/// be ignored by most tracing tools.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
pub struct SpanContext {
trace_id: TraceId,
Expand Down
1 change: 0 additions & 1 deletion opentelemetry-sdk/Cargo.toml
Expand Up @@ -35,7 +35,6 @@ rand_distr = "0.4.0"
default = ["trace"]
trace = ["opentelemetry-api/trace", "crossbeam-channel", "rand", "pin-project", "async-trait", "percent-encoding"]
metrics = ["opentelemetry-api/metrics", "dashmap", "fnv"]
serialize = ["opentelemetry-api/serialize", "serde"]
testing = ["opentelemetry-api/testing", "trace", "metrics", "rt-async-std", "rt-tokio", "rt-tokio-current-thread", "tokio/macros", "tokio/rt-multi-thread"]
rt-tokio = ["tokio", "tokio-stream"]
rt-tokio-current-thread = ["tokio", "tokio-stream"]
Expand Down
22 changes: 0 additions & 22 deletions opentelemetry-sdk/src/export/metrics/stdout.rs
Expand Up @@ -20,8 +20,6 @@ use opentelemetry_api::{
metrics::{Descriptor, MetricsError, Result},
KeyValue,
};
#[cfg(feature = "serialize")]
use serde::{Serialize, Serializer};
use std::fmt;
use std::io;
use std::iter;
Expand Down Expand Up @@ -53,29 +51,20 @@ pub struct StdoutExporter<W> {
}

/// A collection of exported lines
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Default, Debug)]
pub struct ExportBatch {
#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
timestamp: Option<SystemTime>,
lines: Vec<ExportLine>,
}

#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Default, Debug)]
struct ExportLine {
name: String,
#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
min: Option<ExportNumeric>,
#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
max: Option<ExportNumeric>,
#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
sum: Option<ExportNumeric>,
count: u64,
#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
last_value: Option<ExportNumeric>,

#[cfg_attr(feature = "serialize", serde(skip_serializing_if = "Option::is_none"))]
timestamp: Option<SystemTime>,
}

Expand All @@ -88,17 +77,6 @@ impl fmt::Debug for ExportNumeric {
}
}

#[cfg(feature = "serialize")]
impl Serialize for ExportNumeric {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
let s = format!("{:?}", self);
serializer.serialize_str(&s)
}
}

impl<W> Exporter for StdoutExporter<W>
where
W: fmt::Debug + io::Write,
Expand Down
64 changes: 0 additions & 64 deletions opentelemetry-sdk/src/export/trace/mod.rs
Expand Up @@ -3,8 +3,6 @@ use async_trait::async_trait;
use opentelemetry_api::trace::{
Event, Link, SpanContext, SpanId, SpanKind, StatusCode, TraceError,
};
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt::Debug;
use std::sync::Arc;
Expand Down Expand Up @@ -54,7 +52,6 @@ pub trait SpanExporter: Send + Debug {

/// `SpanData` contains all the information collected by a `Span` and can be used
/// by exporters as a standard input.
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct SpanData {
/// Exportable `SpanContext`
Expand Down Expand Up @@ -82,66 +79,5 @@ pub struct SpanData {
/// Resource contains attributes representing an entity that produced this span.
pub resource: Option<Arc<crate::Resource>>,
/// Instrumentation library that produced this span
#[cfg_attr(feature = "serialize", serde(skip))]
pub instrumentation_lib: crate::InstrumentationLibrary,
}

#[cfg(feature = "serialize")]
#[cfg(test)]
mod tests {
use super::*;
use opentelemetry_api::trace::{TraceFlags, TraceId, TraceState};

#[test]
fn test_serialise() {
let trace_id = 7;
let span_id = 99;

let trace_flags = TraceFlags::default();
let remote = false;
let span_context = SpanContext::new(
TraceId::from_u128(trace_id),
SpanId::from_u64(span_id),
trace_flags,
remote,
TraceState::default(),
);

let parent_span_id = 1;
let span_kind = SpanKind::Client;
let name = "foo/bar baz 人?!".into();
let start_time = opentelemetry_api::time::now();
let end_time = opentelemetry_api::time::now();

let capacity = 3;
let attributes = crate::trace::EvictedHashMap::new(capacity, 0);
let events = crate::trace::EvictedQueue::new(capacity);
let links = crate::trace::EvictedQueue::new(capacity);

let status_code = StatusCode::Ok;
let status_message = "".into();
let resource = None;

let span_data = SpanData {
span_context,
parent_span_id: SpanId::from_u64(parent_span_id),
span_kind,
name,
start_time,
end_time,
attributes,
events,
links,
status_code,
status_message,
resource,
instrumentation_lib: crate::InstrumentationLibrary::new("", None),
};

let encoded: Vec<u8> = bincode::serialize(&span_data).unwrap();

let decoded: SpanData = bincode::deserialize(&encoded[..]).unwrap();

assert_eq!(span_data, decoded);
}
}

0 comments on commit 11e88a0

Please sign in to comment.