Skip to content

Commit

Permalink
opentelemetry: dissolve api module in favor of top-level modules (#412)
Browse files Browse the repository at this point in the history
This makes the source tree less nested and makes the internal API and
filesystem more similar to the public API exposed by the crate.
  • Loading branch information
djc authored Jan 5, 2021
1 parent 3ad24f0 commit aae3f4e
Show file tree
Hide file tree
Showing 39 changed files with 50 additions and 62 deletions.
43 changes: 0 additions & 43 deletions opentelemetry/src/api/mod.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 28 additions & 1 deletion opentelemetry/src/global/error_handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
use crate::api::Error;
use std::sync::PoisonError;
use std::sync::RwLock;

#[cfg(feature = "metrics")]
use crate::metrics::MetricsError;
#[cfg(feature = "trace")]
use crate::trace::TraceError;

lazy_static::lazy_static! {
/// The global error handler.
static ref GLOBAL_ERROR_HANDLER: RwLock<Option<ErrorHandler>> = RwLock::new(None);
}

/// Wrapper for error from both tracing and metrics part of open telemetry.
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[cfg(feature = "trace")]
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
#[error(transparent)]
Trace(#[from] TraceError),
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
#[error(transparent)]
Metric(#[from] MetricsError),
#[error("{0}")]
Other(String),
}

impl<T> From<PoisonError<T>> for Error {
fn from(err: PoisonError<T>) -> Self {
Error::Other(err.to_string())
}
}

struct ErrorHandler(Box<dyn Fn(Error) + Send + Sync>);

/// Handle error using the globally configured error handler.
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 15 additions & 10 deletions opentelemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,34 @@
)]
#![cfg_attr(test, deny(warnings))]

mod api;
pub mod global;
pub mod sdk;

#[cfg(feature = "testing")]
#[allow(missing_docs)]
pub mod testing;

pub mod baggage;

mod context;
pub use context::{Context, ContextGuard};

mod core;
pub use crate::core::{Array, Key, KeyValue, Unit, Value};

#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub use api::labels;
pub mod labels;

#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub use api::metrics;
pub mod metrics;

pub mod propagation;

#[cfg(feature = "trace")]
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
pub use api::trace;
pub use api::{
baggage,
context::{Context, ContextGuard},
core::{Array, Key, KeyValue, Unit, Value},
propagation,
};
pub mod trace;

#[cfg(any(feature = "metrics", feature = "trace"))]
pub(crate) mod time {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions opentelemetry/src/sdk/export/trace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Trace exporters
use crate::api::trace::TraceError;
#[cfg(all(feature = "http", any(feature = "surf", feature = "reqwest")))]
use crate::sdk::export::ExportError;
use crate::{
sdk,
trace::{Event, Link, SpanContext, SpanId, SpanKind, StatusCode},
trace::{Event, Link, SpanContext, SpanId, SpanKind, StatusCode, TraceError},
};
use async_trait::async_trait;
#[cfg(feature = "http")]
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry/src/sdk/trace/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! is possible to change its name, set its `Attributes`, and add `Links` and `Events`.
//! These cannot be changed after the `Span`'s end time has been set.
use crate::trace::{Event, SpanContext, SpanId, SpanKind, StatusCode};
use crate::{api, sdk, KeyValue};
use crate::{sdk, trace, KeyValue};
use std::sync::{Arc, Mutex};
use std::time::SystemTime;

Expand Down Expand Up @@ -42,9 +42,9 @@ pub(crate) struct SpanData {
/// Span attributes
pub(crate) attributes: sdk::trace::EvictedHashMap,
/// Span Message events
pub(crate) message_events: sdk::trace::EvictedQueue<api::trace::Event>,
pub(crate) message_events: sdk::trace::EvictedQueue<trace::Event>,
/// Span Links
pub(crate) links: sdk::trace::EvictedQueue<api::trace::Link>,
pub(crate) links: sdk::trace::EvictedQueue<trace::Link>,
/// Span status code
pub(crate) status_code: StatusCode,
/// Span status message
Expand Down Expand Up @@ -223,7 +223,7 @@ fn build_export_data(
#[cfg(test)]
mod tests {
use super::*;
use crate::{api, api::core::KeyValue, api::trace::Span as _, api::trace::TracerProvider};
use crate::{core::KeyValue, trace::Span as _, trace::TracerProvider};
use std::time::Duration;

fn init() -> (sdk::trace::Tracer, SpanData) {
Expand All @@ -232,7 +232,7 @@ mod tests {
let tracer = provider.get_tracer("opentelemetry", Some(env!("CARGO_PKG_VERSION")));
let data = SpanData {
parent_span_id: SpanId::from_u64(0),
span_kind: api::trace::SpanKind::Internal,
span_kind: trace::SpanKind::Internal,
name: "opentelemetry".to_string(),
start_time: crate::time::now(),
end_time: crate::time::now(),
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry/src/sdk/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ use futures::{
FutureExt, Stream, StreamExt,
};

use crate::api::trace::{TraceError, TraceResult};
use crate::global;
use crate::sdk::trace::Span;
use crate::{
sdk::export::trace::{ExportResult, SpanData, SpanExporter},
trace::{TraceError, TraceResult},
Context,
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit aae3f4e

Please sign in to comment.