Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hyper = { workspace = true, features = ["full"] }
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, features = ["tls-roots"] }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] }
tonic = { workspace = true }
tonic = { workspace = true, features = ["tls-roots"] }
tracing = { workspace = true }
tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true, default-features = true, features = ["fmt", "json"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use opentelemetry::KeyValue;
use opentelemetry::trace::TracerProvider;
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace::Tracer;
use opentelemetry_sdk::trace::{BatchConfigBuilder, Tracer};
use opentelemetry_sdk::{runtime, Resource};
use std::time::Duration;
use tonic::metadata::MetadataMap;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down Expand Up @@ -41,10 +42,16 @@ pub fn init_tracer() -> Tracer {
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_tls_config(tonic::transport::ClientTlsConfig::new().with_native_roots())
.with_endpoint("https://api.honeycomb.io/api/traces")
.with_timeout(std::time::Duration::from_secs(5))
.with_metadata(map),
)
.with_batch_config(
BatchConfigBuilder::default()
.with_scheduled_delay(Duration::from_millis(100))
.build(),
)
.install_batch(runtime::Tokio)
.unwrap()
.tracer("rust-telemetry-workshop")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use opentelemetry::global::shutdown_tracer_provider;
use opentelemetry_training::init_test_subscriber;
use std::time::Duration;

#[tokio::test]
async fn failure() {
Expand All @@ -8,6 +9,9 @@ async fn failure() {

opentelemetry_training::get_total(&order_numbers).unwrap_err();

// Wait for the batch exporter to export all spans before the test is finished
tokio::time::sleep(Duration::from_secs(2)).await;

// Ensure all spans are exported
tokio::task::spawn_blocking(|| shutdown_tracer_provider())
.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use opentelemetry::global::shutdown_tracer_provider;
use opentelemetry_training::init_test_subscriber;
use std::time::Duration;

#[tokio::test]
async fn success() {
Expand All @@ -11,6 +12,9 @@ async fn success() {
// Check that the total is correct.
assert_eq!(total, 3117);

// Wait for the batch exporter to export all spans before the test is finished
tokio::time::sleep(Duration::from_secs(2)).await;

// Ensure all spans are exported
tokio::task::spawn_blocking(|| shutdown_tracer_provider())
.await
Expand Down