Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update opentelemetry to 0.21 #158

Closed
wants to merge 11 commits into from
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ jobs:
- run: cargo clippy --features=metrics-0_21,prometheus-exporter
- run: cargo clippy --features=prometheus-0_13
- run: cargo clippy --features=prometheus-client-0_21
- run: cargo clippy --features=opentelemetry-0_20
- run: "" #cargo clippy --features=opentelemetry-0_20
- run: "" #cargo clippy --features=opentelemetry-0_21

# Run the tests with each of the different metrics libraries
- run: cargo test --features=prometheus-exporter
- run: cargo test --features=prometheus-exporter,metrics-0_21
- run: cargo test --features=prometheus-exporter,prometheus-0_13
- run: cargo test --features=prometheus-exporter,prometheus-client-0_21,exemplars-tracing
- run: cargo test --features=prometheus-exporter,prometheus-client-0_21,exemplars-tracing-opentelemetry-0_20
- run: cargo test --features=prometheus-exporter,prometheus-client-0_21,exemplars-tracing-opentelemetry-0_21
- run: cargo test --features=prometheus-exporter,opentelemetry-0_20
- run: cargo test --features=prometheus-exporter-otel-0_20
- run: cargo test --features=prometheus-exporter-otel-0_21
- run: cargo test --features=prometheus-exporter-otel-0_20,metrics-0_21
- run: cargo test --features=prometheus-exporter-otel-0_21,metrics-0_21
- run: cargo test --features=prometheus-exporter-otel-0_20,prometheus-0_13
- run: cargo test --features=prometheus-exporter-otel-0_21,prometheus-0_13
- run: cargo test --features=prometheus-exporter-otel-0_20,prometheus-client-0_21,exemplars-tracing
- run: cargo test --features=prometheus-exporter-otel-0_21,prometheus-client-0_21,exemplars-tracing
- run: cargo test --features=prometheus-exporter-otel-0_20,prometheus-client-0_21,exemplars-tracing-opentelemetry-0_20
- run: cargo test --features=prometheus-exporter-otel-0_20,prometheus-client-0_21,exemplars-tracing-opentelemetry-0_21
- run: cargo test --features=prometheus-exporter-otel-0_20,opentelemetry-0_20
- run: cargo test --features=prometheus-exporter-otel-0_21,opentelemetry-0_21

# Build the crate using the other optional features
- run: cargo build --features=metrics-0_21,custom-objective-percentile,custom-objective-latency
Expand All @@ -45,6 +51,5 @@ jobs:
- run: cargo build --package example-full-api
- run: cargo build --package example-opentelemetry-push


# Make sure the docs can be built
- run: cargo doc --all-features
63 changes: 41 additions & 22 deletions autometrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ readme = "README.md"
[features]
# Metrics backends
metrics-0_21 = ["dep:metrics"]
opentelemetry-0_20 = ["opentelemetry_api/metrics", "dep:prometheus"]
opentelemetry-0_20 = ["dep:opentelemetry-0-20", "opentelemetry-0-20/metrics", "dep:prometheus"]
opentelemetry-0_21 = ["dep:opentelemetry-0-21", "opentelemetry-0-21/metrics", "dep:prometheus"]
prometheus-0_13 = ["dep:prometheus"]
prometheus-client-0_21 = ["dep:prometheus-client"]

Expand All @@ -25,59 +26,71 @@ opentelemetry = ["opentelemetry-0_20"]
prometheus = ["prometheus-0_13"]
prometheus-client = ["prometheus-client-0_21"]
exemplars-tracing-opentelemetry = ["exemplars-tracing-opentelemetry-0_20"]
prometheus-exporter = ["prometheus-exporter-otel-0_20"]

# Misc
prometheus-exporter = [
prometheus-exporter-otel-0_20 = [
"prometheus-exporter-parent",
"dep:opentelemetry-prometheus-0-13",
"dep:opentelemetry-sdk-0-20",
]

prometheus-exporter-otel-0_21 = [
"prometheus-exporter-parent",
"dep:opentelemetry-prometheus-0-14",
"dep:opentelemetry-sdk-0-21",
]

prometheus-exporter-parent = [
"http",
"metrics-exporter-prometheus",
"opentelemetry-prometheus",
"opentelemetry_sdk",
"dep:prometheus",
"dep:prometheus-client",
]

otel-push-exporter = [
"opentelemetry_sdk",
"opentelemetry_api",
"opentelemetry-otlp",
"opentelemetry-otlp/metrics",
"opentelemetry-otlp/tls-roots"
"dep:opentelemetry-sdk-0-21",
"dep:opentelemetry-0-21",
"dep:opentelemetry-otlp-0-21",
"opentelemetry-otlp-0-21/metrics",
"opentelemetry-otlp-0-21/tls-roots"
]

otel-push-exporter-http = [
"otel-push-exporter",
"opentelemetry-otlp/http-proto"
"opentelemetry-otlp-0-21/http-proto",
"opentelemetry-otlp-0-21/reqwest-client"
]

otel-push-exporter-grpc = [
"otel-push-exporter",
"opentelemetry-otlp/grpc-tonic"
"opentelemetry-otlp-0-21/grpc-tonic"
]

otel-push-exporter-tokio = [
"otel-push-exporter",
"opentelemetry_sdk/rt-tokio"
"opentelemetry-sdk-0-21/rt-tokio"
]

otel-push-exporter-tokio-current-thread = [
"otel-push-exporter",
"opentelemetry_sdk/rt-tokio-current-thread"
"opentelemetry-sdk-0-21/rt-tokio-current-thread"
]

otel-push-exporter-async-std = [
"otel-push-exporter",
"opentelemetry_sdk/rt-async-std"
"opentelemetry-sdk-0-21/rt-async-std"
]

# Exemplars
exemplars-tracing = ["tracing", "tracing-subscriber"]
exemplars-tracing-opentelemetry-0_20 = [
"opentelemetry_api/trace",
"opentelemetry-0-20/trace",
"tracing",
"dep:tracing-opentelemetry-0-20",
]
exemplars-tracing-opentelemetry-0_21 = [
"opentelemetry_api/trace",
"opentelemetry-0-20/trace", # yea for some reason they use otel 0.20 with tracing-opentelemetry 0.21. only 0.22 is updated w/ otel 0.21
"tracing",
"dep:tracing-opentelemetry-0-21",
]
Expand All @@ -94,19 +107,25 @@ spez = "0.1.2"
thiserror = "1"

# Used for opentelemetry feature
opentelemetry_api = { version = "0.20", default-features = false, optional = true }
## The opentelemetry_api crate has been incorperated into `opentelemetry` as of v0.21 so the `package` directives are different
opentelemetry-0-20 = { package = "opentelemetry_api", version = "0.20", default-features = false, optional = true }
opentelemetry-0-21 = { package = "opentelemetry", version = "0.21", default-features = false, optional = true }

opentelemetry-prometheus-0-13 = { package = "opentelemetry-prometheus", version = "0.13", optional = true } # otel 0.20
opentelemetry-prometheus-0-14 = { package = "opentelemetry-prometheus", version = "0.14", optional = true } # otel 0.21

opentelemetry-sdk-0-20 = { package = "opentelemetry_sdk", version = "0.20", default-features = false, features = ["metrics"], optional = true }
opentelemetry-sdk-0-21 = { package = "opentelemetry_sdk", version = "0.21", default-features = false, features = ["metrics"], optional = true }

opentelemetry-otlp-0-20 = { package = "opentelemetry-otlp", version = "0.13", default-features = false, optional = true }
opentelemetry-otlp-0-21 = { package = "opentelemetry-otlp", version = "0.14", default-features = false, optional = true }

# Use for metrics feature
metrics = { version = "0.21", default-features = false, optional = true }

# Used for prometheus-exporter feature
http = { version = "0.2", optional = true }
metrics-exporter-prometheus = { version = "0.12", default-features = false, optional = true }
opentelemetry-prometheus = { version = "0.13.0", optional = true }
opentelemetry_sdk = { version = "0.20", default-features = false, features = [
"metrics",
], optional = true }
opentelemetry-otlp = { version = "0.13.0", default-features = false, optional = true }
prometheus = { version = "0.13", default-features = false, optional = true }

# Used for prometheus-client feature
Expand Down
6 changes: 3 additions & 3 deletions autometrics/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn main() {
#[cfg(feature = "metrics")]
println!("cargo:warning=The `metrics` feature is deprecated and will be removed in the next version. Please use `metrics-0_21` instead.");
#[cfg(feature = "opentelemetry")]
println!("cargo:warning=The `opentelemetry` feature is deprecated and will be removed in the next version. Please use `opentelemetry-0_20` instead.");
println!("cargo:warning=The `opentelemetry` feature is deprecated and will be removed in the next version. Please use `opentelemetry-0_20` or `opentelemetry-0_21` instead.");
#[cfg(feature = "prometheus")]
println!("cargo:warning=The `prometheus` feature is deprecated and will be removed in the next version. Please use `prometheus-0_13` instead.");
#[cfg(feature = "prometheus-client")]
Expand All @@ -17,7 +17,7 @@ pub fn main() {
cfg_aliases! {
// Backends
metrics: { any(feature = "metrics", feature = "metrics-0_21") },
opentelemetry: { any(feature = "opentelemetry", feature = "opentelemetry-0_20") },
opentelemetry: { any(feature = "opentelemetry", feature = "opentelemetry-0_20", feature = "opentelemetry-0_21") },
prometheus: { any(feature = "prometheus", feature = "prometheus-0_13") },
prometheus_client_feature: { any(feature = "prometheus-client", feature = "prometheus-client-0_21") },
default_backend: { all(
Expand All @@ -27,7 +27,7 @@ pub fn main() {
prometheus_client: { any(prometheus_client_feature, default_backend) },

// Misc
prometheus_exporter: { feature = "prometheus-exporter" },
prometheus_exporter: { any(feature = "prometheus-exporter", feature = "prometheus-exporter-otel-0_20", feature = "prometheus-exporter-otel-0_21") },

// Exemplars
exemplars: { any(exemplars_tracing, exemplars_tracing_opentelemetry) },
Expand Down
2 changes: 1 addition & 1 deletion autometrics/src/exemplars/tracing_opentelemetry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::TraceLabels;
use opentelemetry_api::trace::TraceContextExt;
use opentelemetry_0_20::trace::TraceContextExt;
use std::iter::FromIterator;
use tracing::Span;

Expand Down
6 changes: 5 additions & 1 deletion autometrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ mod labels;
pub mod objectives;
#[cfg(feature = "otel-push-exporter")]
pub mod otel_push_exporter;
#[cfg(feature = "prometheus-exporter")]
#[cfg(any(
feature = "prometheus-exporter",
feature = "prometheus-exporter-otel-0_20",
feature = "prometheus-exporter-otel-0_21"
))]
pub mod prometheus_exporter;
pub mod settings;
mod task_local;
Expand Down
98 changes: 49 additions & 49 deletions autometrics/src/otel_push_exporter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
use opentelemetry_api::metrics::MetricsError;
use opentelemetry_otlp::OtlpMetricPipeline;
use opentelemetry_otlp::{ExportConfig, Protocol, WithExportConfig};
use opentelemetry_sdk::metrics::MeterProvider;
#[cfg(all(not(doc), feature = "opentelemetry-0_20"))]
use opentelemetry_0_20::metrics::MetricsError;
#[cfg(feature = "opentelemetry-0_21")]
use opentelemetry_0_21::metrics::MetricsError;
#[cfg(all(not(doc), feature = "opentelemetry-0_20"))]
use opentelemetry_otlp_0_20::{
new_exporter, new_pipeline, ExportConfig, OtlpMetricPipeline, Protocol, WithExportConfig,
};
#[cfg(feature = "opentelemetry-0_21")]
use opentelemetry_otlp_0_21::{
new_exporter, new_pipeline, ExportConfig, OtlpMetricPipeline, Protocol, WithExportConfig,
};
#[cfg(all(not(doc), feature = "opentelemetry-0_20"))]
use opentelemetry_sdk_0_20::{metrics::MeterProvider, runtime};
#[cfg(feature = "opentelemetry-0_21")]
use opentelemetry_sdk_0_21::{metrics::MeterProvider, runtime};
use std::ops::Deref;
use std::time::Duration;

Expand Down Expand Up @@ -34,15 +46,11 @@ impl Drop for OtelMeterProvider {
#[cfg(feature = "otel-push-exporter-http")]
pub fn init_http(url: impl Into<String>) -> Result<OtelMeterProvider, MetricsError> {
runtime()
.with_exporter(
opentelemetry_otlp::new_exporter()
.http()
.with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::HttpBinary,
..Default::default()
}),
)
.with_exporter(new_exporter().http().with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::HttpBinary,
..Default::default()
}))
.build()
.map(OtelMeterProvider)
}
Expand All @@ -55,16 +63,12 @@ pub fn init_http_with_timeout_period(
period: Duration,
) -> Result<OtelMeterProvider, MetricsError> {
runtime()
.with_exporter(
opentelemetry_otlp::new_exporter()
.http()
.with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::HttpBinary,
timeout,
..Default::default()
}),
)
.with_exporter(new_exporter().http().with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::HttpBinary,
timeout,
..Default::default()
}))
.with_period(period)
.build()
.map(OtelMeterProvider)
Expand All @@ -79,15 +83,11 @@ pub fn init_http_with_timeout_period(
#[cfg(feature = "otel-push-exporter-grpc")]
pub fn init_grpc(url: impl Into<String>) -> Result<OtelMeterProvider, MetricsError> {
runtime()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::Grpc,
..Default::default()
}),
)
.with_exporter(new_exporter().tonic().with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::Grpc,
..Default::default()
}))
.build()
.map(OtelMeterProvider)
}
Expand All @@ -100,30 +100,31 @@ pub fn init_grpc_with_timeout_period(
period: Duration,
) -> Result<OtelMeterProvider, MetricsError> {
runtime()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::Grpc,
timeout,
..Default::default()
}),
)
.with_exporter(new_exporter().tonic().with_export_config(ExportConfig {
endpoint: url.into(),
protocol: Protocol::Grpc,
timeout,
..Default::default()
}))
.with_period(period)
.build()
.map(OtelMeterProvider)
}

#[cfg(all(not(doc), feature = "opentelemetry-0_20"))]
type MetricPipeline<T> = OtlpMetricPipeline<T>;
#[cfg(all(not(doc), feature = "opentelemetry-0_21"))]
type MetricPipeline<T> = OtlpMetricPipeline<T, opentelemetry_otlp_0_21::NoExporterConfig>;

#[cfg(all(
feature = "otel-push-exporter-tokio",
not(any(
feature = "otel-push-exporter-tokio-current-thread",
feature = "otel-push-exporter-async-std"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::Tokio> {
return opentelemetry_otlp::new_pipeline().metrics(opentelemetry_sdk::runtime::Tokio);
fn runtime() -> MetricPipeline<runtime::Tokio> {
return new_pipeline().metrics(runtime::Tokio);
}

#[cfg(all(
Expand All @@ -133,9 +134,8 @@ fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::Tokio> {
feature = "otel-push-exporter-async-std"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::TokioCurrentThread> {
return opentelemetry_otlp::new_pipeline()
.metrics(opentelemetry_sdk::runtime::TokioCurrentThread);
fn runtime() -> MetricPipeline<runtime::TokioCurrentThread> {
return new_pipeline().metrics(runtime::TokioCurrentThread);
}

#[cfg(all(
Expand All @@ -145,8 +145,8 @@ fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::TokioCurrentThrea
feature = "otel-push-exporter-tokio-current-thread"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::AsyncStd> {
return opentelemetry_otlp::new_pipeline().metrics(opentelemetry_sdk::runtime::AsyncStd);
fn runtime() -> MetricPipeline<runtime::AsyncStd> {
return new_pipeline().metrics(runtime::AsyncStd);
}

#[cfg(not(any(
Expand Down
Loading
Loading