Skip to content

Commit

Permalink
🐛 fix build of contributions (upgrade of opentelemetry, fake collecto…
Browse files Browse the repository at this point in the history
…r for logs,...)
  • Loading branch information
davidB committed Aug 25, 2024
1 parent 1a4d0cc commit 8e8e5f1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 47 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ opentelemetry = { version = "0.24", features = [
opentelemetry_sdk = { version = "0.24.1", default-features = false, features = [
"rt-tokio",
] }
opentelemetry-aws = { version = "0.11", default-features = false }
opentelemetry-aws = { version = "0.12", default-features = false }
opentelemetry-jaeger = { version = "0.22", default-features = false }
opentelemetry-jaeger-propagator = { version = "0.2", default-features = false }
opentelemetry-resource-detectors = { version = "0.2.0", default-features = false }
opentelemetry-semantic-conventions = { version = "0.15", default-features = false }
opentelemetry-zipkin = { version = "0.21", default-features = false }
opentelemetry-jaeger-propagator = { version = "0.3", default-features = false }
opentelemetry-resource-detectors = { version = "0.3", default-features = false }
opentelemetry-semantic-conventions = { version = "0.16", default-features = false }
opentelemetry-zipkin = { version = "0.22", default-features = false }
opentelemetry-otlp = { version = "0.17", default-features = false }
opentelemetry-proto = { version = "0.6", default-features = false }
opentelemetry-stdout = { version = "0.4" }
tonic = { version = "0.11", default-features = false } #should be sync with opentelemetry-proto
opentelemetry-proto = { version = "0.7", default-features = false }
opentelemetry-stdout = { version = "0.5" }
tonic = { version = "0.12", default-features = false } #should be sync with opentelemetry-proto
tracing = "0.1"
tracing-opentelemetry = "0.25"

Expand Down
16 changes: 6 additions & 10 deletions axum-tracing-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ opentelemetry = { workspace = true, features = [
"trace",
], default-features = false }
pin-project-lite = "0.2"
tower = "0.4"
tower = "0.5"
tracing = { workspace = true }
tracing-opentelemetry = { workspace = true }

instrumentation-sdk-trace = { package = "tracing-opentelemetry-instrumentation-sdk", path = "../tracing-opentelemetry-instrumentation-sdk", features = [
"http",
], version = "0.18", optional = true }

instrumentation-sdk-info = { package = "tracing-opentelemetry-instrumentation-sdk", path = "../tracing-opentelemetry-instrumentation-sdk", features = [
tracing-opentelemetry-instrumentation-sdk = { path = "../tracing-opentelemetry-instrumentation-sdk", features = [
"http",
"tracing_level_info",
], version = "0.19", optional = true }
], version = "0.19" }

[dev-dependencies]
fake-opentelemetry-collector = { path = "../fake-opentelemetry-collector" }
Expand Down Expand Up @@ -69,4 +63,6 @@ opentelemetry_sdk = { workspace = true, features = [

[features]
# to use level `info` instead of `trace` to create otel span
tracing_level_info = ["tracing-opentelemetry-instrumentation-sdk/tracing_level_info"]
tracing_level_info = [
"tracing-opentelemetry-instrumentation-sdk/tracing_level_info",
]
17 changes: 7 additions & 10 deletions examples/axum-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ init-tracing-opentelemetry = { path = "../../init-tracing-opentelemetry", featur
"otlp",
"tracing_subscriber_ext",
] }
opentelemetry = "0.23"
opentelemetry-otlp = { version = "0.16", optional = true }
opentelemetry = "0.24"
opentelemetry-otlp = { version = "*", default-features = false, features = [
"reqwest-client",
"reqwest-rustls",
"http-proto",
"tls",
] }
serde_json = "1.0.79"
tokio = { version = "1.0", features = ["full"] }
tracing = "0.1"
tracing-opentelemetry-instrumentation-sdk = { path = "../../tracing-opentelemetry-instrumentation-sdk" }

[features]
otlp-over-http = [
"opentelemetry-otlp/reqwest-client",
"opentelemetry-otlp/reqwest-rustls",
"opentelemetry-otlp/http-proto",
"opentelemetry-otlp/tls",
]
18 changes: 13 additions & 5 deletions fake-opentelemetry-collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@ license.workspace = true
futures = "0.3"
hex = "0.4"
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "trace", "logs"] }
opentelemetry-proto = { workspace = true, features = ["gen-tonic"] }
opentelemetry-otlp = { workspace = true, features = [
"grpc-tonic",
"logs",
"trace",
] }
opentelemetry-proto = { workspace = true, features = [
"gen-tonic",
"logs",
"trace",
] }
# need tokio runtime to run smoke tests.
opentelemetry_sdk = { workspace = true, features = [
"trace",
"rt-tokio",
"testing",
] }
serde = { version = "1.0.136", features = ["derive"] }
tokio = { version = "1.27", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.39", features = ["full"] }
tokio-stream = { version = "0.1", features = ["net"] }
tonic = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
assert2 = "0.3"
insta = { version = "1.29.0", features = ["yaml", "redactions"] }
insta = { version = "1.39.0", features = ["yaml", "redactions"] }
2 changes: 2 additions & 0 deletions fake-opentelemetry-collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use trace::*;
use std::net::SocketAddr;

use futures::StreamExt;
use opentelemetry::trace::TracerProvider;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_proto::tonic::collector::logs::v1::logs_service_server::LogsServiceServer;
use opentelemetry_proto::tonic::collector::trace::v1::trace_service_server::TraceServiceServer;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub async fn setup_tracer(fake_server: &FakeCollectorServer) -> opentelemetry_sd
)
.install_batch(opentelemetry_sdk::runtime::Tokio)
.expect("failed to install tracer")
.tracer("")
}

pub async fn setup_logger(
Expand Down
1 change: 0 additions & 1 deletion fake-opentelemetry-collector/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::common::cnv_attributes;
use opentelemetry_proto::tonic::collector::logs::v1::{
logs_service_server::LogsService, ExportLogsServiceRequest, ExportLogsServiceResponse,
};
use opentelemetry_proto::tonic::common::v1::AnyValue;
use serde::Serialize;
use std::collections::BTreeMap;
use std::sync::{mpsc, Mutex};
Expand Down
17 changes: 8 additions & 9 deletions init-tracing-opentelemetry/src/otlp.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::{collections::HashMap, str::FromStr};

use opentelemetry::trace::{TraceError, TracerProvider};
use opentelemetry::trace::TraceError;
use opentelemetry_otlp::SpanExporterBuilder;
use opentelemetry_sdk::{
trace::{Sampler, Tracer},
Resource,
};
use opentelemetry_sdk::{trace::Sampler, trace::TracerProvider, Resource};
#[cfg(feature = "tls")]
use tonic::transport::ClientTlsConfig;

Expand All @@ -17,7 +14,10 @@ pub fn identity(
}

// see https://opentelemetry.io/docs/reference/specification/protocol/exporter/
pub fn init_tracer<F>(resource: Resource, transform: F) -> Result<Tracer, TraceError>
pub fn init_tracerprovider<F>(
resource: Resource,
transform: F,
) -> Result<TracerProvider, TraceError>
where
F: FnOnce(
opentelemetry_otlp::OtlpTracePipeline<SpanExporterBuilder>,
Expand Down Expand Up @@ -57,9 +57,8 @@ where
.with_sampler(read_sampler_from_env()),
);
pipeline = transform(pipeline);
let provider = pipeline.install_batch(opentelemetry_sdk::runtime::Tokio);
opentelemetry::global::set_tracer_provider(provider.clone());
provider.tracer()
let provider = pipeline.install_batch(opentelemetry_sdk::runtime::Tokio)?;
Ok(provider)
}

/// turn a string of "k1=v1,k2=v2,..." into an iterator of (key, value) tuples
Expand Down
11 changes: 7 additions & 4 deletions init-tracing-opentelemetry/src/tracing_subscriber_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry::trace::TraceError;
use opentelemetry::trace::{TraceError, TracerProvider};
use opentelemetry_sdk::trace::Tracer;
use tracing::{info, Subscriber};
use tracing_opentelemetry::OpenTelemetryLayer;
Expand Down Expand Up @@ -68,11 +68,12 @@ where
otlp,
resource::DetectResource,
};
use opentelemetry::global;
let otel_rsrc = DetectResource::default()
//.with_fallback_service_name(env!("CARGO_PKG_NAME"))
//.with_fallback_service_version(env!("CARGO_PKG_VERSION"))
.build();
let otel_tracer = otlp::init_tracer(otel_rsrc, otlp::identity)?;
let tracerprovider = otlp::init_tracerprovider(otel_rsrc, otlp::identity)?;
// to not send trace somewhere, but continue to create and propagate,...
// then send them to `axum_tracing_opentelemetry::stdio::WriteNoWhere::default()`
// or to `std::io::stdout()` to print
Expand All @@ -83,9 +84,11 @@ where
// stdio::WriteNoWhere::default(),
// )?;
init_propagator()?;
Ok(tracing_opentelemetry::layer()
let layer = tracing_opentelemetry::layer()
.with_error_records_to_exceptions(true)
.with_tracer(otel_tracer))
.with_tracer(tracerprovider.tracer(""));
global::set_tracer_provider(tracerprovider);
Ok(layer)
}

pub fn init_subscribers() -> Result<(), Error> {
Expand Down

0 comments on commit 8e8e5f1

Please sign in to comment.