Skip to content

Commit

Permalink
Clean up api/trace exports
Browse files Browse the repository at this point in the history
Clean up api/trace exports to be flattened under api/trace instead of
just api.
  • Loading branch information
Andreas Wiede committed Oct 6, 2020
1 parent b631751 commit e6021e9
Show file tree
Hide file tree
Showing 52 changed files with 541 additions and 463 deletions.
6 changes: 4 additions & 2 deletions examples/actix-http/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use actix_service::Service;
use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use opentelemetry::api::trace::futures::FutureExt;
use opentelemetry::api::{Key, TraceContextExt, Tracer};
use opentelemetry::api::{
trace::{FutureExt, TraceContextExt, Tracer},
Key,
};
use opentelemetry::{global, sdk};
use std::error::Error;

Expand Down
6 changes: 4 additions & 2 deletions examples/actix-udp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use actix_service::Service;
use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use opentelemetry::api::trace::futures::FutureExt;
use opentelemetry::api::{Key, TraceContextExt, Tracer};
use opentelemetry::api::{
trace::{FutureExt, TraceContextExt, Tracer},
Key,
};
use opentelemetry::{global, sdk};
use std::error::Error;

Expand Down
5 changes: 4 additions & 1 deletion examples/async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
//!
//! [`hello_world`]: https://github.com/tokio-rs/tokio/blob/132e9f1da5965530b63554d7a1c59824c3de4e30/tokio/examples/hello_world.rs
use opentelemetry::{
api::{trace::futures::FutureExt, Context, TraceContextExt, Tracer},
api::{
trace::{FutureExt, TraceContextExt, Tracer},
Context,
},
global, sdk,
};
use std::{error::Error, io, net::SocketAddr};
Expand Down
11 changes: 9 additions & 2 deletions examples/aws-xray/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use hyper::{body::Body, Client};
use opentelemetry::api::{Context, TraceContextExt, Tracer};
use opentelemetry::{api, exporter::trace::stdout, global, sdk};
use opentelemetry::{
api::{
self,
trace::{TraceContextExt, Tracer},
Context,
},
exporter::trace::stdout,
global, sdk,
};
use opentelemetry_contrib::{XrayIdGenerator, XrayTraceContextPropagator};

fn init_tracer() -> (sdk::trace::Tracer, stdout::Uninstall) {
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-xray/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use opentelemetry::{
api::{Span, Tracer},
api::trace::{Span, Tracer},
exporter::trace::stdout,
global, sdk,
};
Expand Down
7 changes: 5 additions & 2 deletions examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use futures::stream::{Stream, StreamExt};
use opentelemetry::api::metrics::{self, MetricsError, ObserverResult};
use opentelemetry::api::{BaggageExt, Context, Key, KeyValue, TraceContextExt, Tracer};
use opentelemetry::api::{
metrics::{self, MetricsError, ObserverResult},
trace::{TraceContextExt, Tracer},
BaggageExt, Context, Key, KeyValue,
};
use opentelemetry::exporter;
use opentelemetry::sdk::metrics::PushController;
use opentelemetry::{global, sdk};
Expand Down
7 changes: 5 additions & 2 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use futures::stream::{Stream, StreamExt};
use opentelemetry::api::metrics::{self, MetricsError, ObserverResult};
use opentelemetry::api::{BaggageExt, Context, Key, KeyValue, TraceContextExt, Tracer};
use opentelemetry::api::{
metrics::{self, MetricsError, ObserverResult},
trace::{TraceContextExt, Tracer},
BaggageExt, Context, Key, KeyValue,
};
use opentelemetry::exporter;
use opentelemetry::sdk::metrics::PushController;
use opentelemetry::{global, sdk};
Expand Down
5 changes: 4 additions & 1 deletion examples/datadog/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use opentelemetry::api::{Key, Span, TraceContextExt, Tracer};
use opentelemetry::api::{
trace::{Span, TraceContextExt, Tracer},
Key,
};
use opentelemetry::global;
use opentelemetry_contrib::datadog::ApiVersion;
use std::thread;
Expand Down
3 changes: 2 additions & 1 deletion examples/grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use hello_world::greeter_client::GreeterClient;
use hello_world::HelloRequest;
use opentelemetry::api::{
Context, KeyValue, TextMapFormat, TraceContextExt, TraceContextPropagator, Tracer,
trace::{TraceContextExt, TraceContextPropagator, Tracer},
Context, KeyValue, TextMapFormat,
};
use opentelemetry::sdk;
use std::error::Error;
Expand Down
8 changes: 6 additions & 2 deletions examples/grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use tonic::{transport::Server, Request, Response, Status};

use hello_world::greeter_server::{Greeter, GreeterServer};
use hello_world::{HelloReply, HelloRequest};
use opentelemetry::api::{self, KeyValue, Span, TextMapFormat, Tracer};
use opentelemetry::api::{
self,
trace::{Span, Tracer},
KeyValue, TextMapFormat,
};
use opentelemetry::global;
use opentelemetry::sdk;
use std::error::Error;
Expand All @@ -20,7 +24,7 @@ impl Greeter for MyGreeter {
&self,
request: Request<HelloRequest>, // Accept request of type HelloRequest
) -> Result<Response<HelloReply>, Status> {
let propagator = api::TraceContextPropagator::new();
let propagator = api::trace::TraceContextPropagator::new();
let parent_cx = propagator.extract(request.metadata());
let span = global::tracer("greeter").start_from_context("Processing reply", &parent_cx);
span.set_attribute(KeyValue::new("request", format!("{:?}", request)));
Expand Down
7 changes: 5 additions & 2 deletions examples/http/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use hyper::{body::Body, Client};
use opentelemetry::api::{Context, TextMapFormat, TraceContextExt, Tracer};
use opentelemetry::api::{
trace::{TraceContextExt, Tracer},
Context, TextMapFormat,
};
use opentelemetry::{api, exporter::trace::stdout, global, sdk};

fn init_tracer() -> (sdk::trace::Tracer, stdout::Uninstall) {
Expand All @@ -19,7 +22,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sy
let _guard = init_tracer();

let client = Client::new();
let propagator = api::TraceContextPropagator::new();
let propagator = api::trace::TraceContextPropagator::new();
let span = global::tracer("example/client").start("say hello");
let cx = Context::current_with_span(span);

Expand Down
8 changes: 6 additions & 2 deletions examples/http/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use opentelemetry::{
api::{self, Span, TextMapFormat, Tracer},
api::{
self,
trace::{Span, Tracer},
TextMapFormat,
},
exporter::trace::stdout,
global, sdk,
};
use std::{convert::Infallible, net::SocketAddr};

async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {
let propagator = api::TraceContextPropagator::new();
let propagator = api::trace::TraceContextPropagator::new();
let parent_cx = propagator.extract(req.headers());
let span = global::tracer("example/server").start_from_context("hello", &parent_cx);
span.add_event("handling this...".to_string(), Vec::new());
Expand Down
2 changes: 1 addition & 1 deletion examples/stdout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use opentelemetry::{
api::Tracer,
api::trace::Tracer,
exporter::trace::stdout,
sdk::trace::{self, Sampler},
};
Expand Down
2 changes: 1 addition & 1 deletion examples/zipkin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry::api::{Span, Tracer};
use opentelemetry::api::trace::{Span, Tracer};
use opentelemetry::global;
use std::thread;
use std::time::Duration;
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-contrib/src/datadog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! [`DatadogPipelineBuilder`]: struct.DatadogPipelineBuilder.html
//!
//! ```no_run
//! use opentelemetry::api::{KeyValue, Tracer};
//! use opentelemetry::api::{KeyValue, trace::Tracer};
//! use opentelemetry::sdk::{trace::{self, IdGenerator, Sampler}, Resource};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -86,7 +86,7 @@ mod model;
pub use model::ApiVersion;

use async_trait::async_trait;
use opentelemetry::{api::TracerProvider, exporter::trace, global, sdk};
use opentelemetry::{api::trace::TracerProvider, exporter::trace, global, sdk};
use reqwest::header::CONTENT_TYPE;
use reqwest::Url;
use std::error::Error;
Expand Down
14 changes: 7 additions & 7 deletions opentelemetry-contrib/src/datadog/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ mod tests {
let trace_id = 7;
let span_id = 99;

let span_context = api::SpanContext::new(
api::TraceId::from_u128(trace_id),
api::SpanId::from_u64(span_id),
let span_context = api::trace::SpanContext::new(
api::trace::TraceId::from_u128(trace_id),
api::trace::SpanId::from_u64(span_id),
0,
false,
api::TraceState::default(),
api::trace::TraceState::default(),
);

let start_time = SystemTime::UNIX_EPOCH;
Expand All @@ -95,15 +95,15 @@ mod tests {

let span_data = trace::SpanData {
span_context,
parent_span_id: api::SpanId::from_u64(parent_span_id),
span_kind: api::SpanKind::Client,
parent_span_id: api::trace::SpanId::from_u64(parent_span_id),
span_kind: api::trace::SpanKind::Client,
name: "resource".to_string(),
start_time,
end_time,
attributes,
message_events,
links,
status_code: api::StatusCode::OK,
status_code: api::trace::StatusCode::OK,
status_message: String::new(),
resource: Arc::new(sdk::Resource::default()),
instrumentation_lib: InstrumentationLibrary::new("component", None),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry::api::{IdGenerator, SpanId, TraceId};
use opentelemetry::api::trace::{IdGenerator, SpanId, TraceId};
use opentelemetry::sdk;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

Expand All @@ -24,9 +24,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
///
/// ```
/// extern crate opentelemetry;
/// use opentelemetry::api::NoopSpanExporter;
/// use opentelemetry::sdk::trace::Config;
/// use opentelemetry::sdk::trace::TracerProvider;
/// use opentelemetry::api::trace::NoopSpanExporter;
/// use opentelemetry::sdk::trace::{Config, TracerProvider};
/// use opentelemetry_contrib::XrayIdGenerator;
///
/// let _provider: TracerProvider = TracerProvider::builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use opentelemetry::api::trace::span_context::TraceState;
use opentelemetry::api::{
Context, Extractor, FieldIter, Injector, SpanContext, SpanId, TextMapFormat, TraceContextExt,
TraceId, TRACE_FLAG_DEFERRED, TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED,
trace::{
SpanContext, SpanId, TraceContextExt, TraceId, TraceState, TRACE_FLAG_DEFERRED,
TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED,
},
Context, Extractor, FieldIter, Injector, TextMapFormat,
};

const AWS_XRAY_TRACE_HEADER: &str = "x-amzn-trace-id";
Expand Down Expand Up @@ -234,7 +236,7 @@ fn title_case(s: &str) -> String {
mod tests {
use super::*;
use opentelemetry::api;
use opentelemetry::api::trace::span_context::TraceState;
use opentelemetry::api::trace::TraceState;
use std::collections::HashMap;
use std::str::FromStr;
use std::time::SystemTime;
Expand Down Expand Up @@ -298,7 +300,7 @@ mod tests {
#[derive(Debug)]
struct TestSpan(SpanContext);

impl api::Span for TestSpan {
impl api::trace::Span for TestSpan {
fn add_event_with_timestamp(
&self,
_name: String,
Expand All @@ -313,7 +315,7 @@ mod tests {
false
}
fn set_attribute(&self, _attribute: api::KeyValue) {}
fn set_status(&self, _code: api::StatusCode, _message: String) {}
fn set_status(&self, _code: api::trace::StatusCode, _message: String) {}
fn update_name(&self, _new_name: String) {}
fn end_with_timestamp(&self, _timestamp: SystemTime) {}
}
Expand Down
Loading

0 comments on commit e6021e9

Please sign in to comment.