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 without backwards compatibility #159

Merged
merged 10 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ 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_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,prometheus-client-0_21,exemplars-tracing-opentelemetry-0_22
- run: cargo test --features=prometheus-exporter,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 Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
has been improved (#149)
- Fixed missing feature flag for `opentelemetry-otlp` when autometrics feature
`otel-push-exporter` is enabled
- Update to OpenTelemetry v0.21
mellowagain marked this conversation as resolved.
Show resolved Hide resolved

### Autometrics 1.0 compliance

Expand Down
35 changes: 15 additions & 20 deletions autometrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ readme = "README.md"
[features]
# Metrics backends
metrics-0_21 = ["dep:metrics"]
opentelemetry-0_20 = ["opentelemetry_api/metrics", "dep:prometheus"]
opentelemetry-0_21 = ["opentelemetry/metrics", "dep:prometheus"]
prometheus-0_13 = ["dep:prometheus"]
prometheus-client-0_21 = ["dep:prometheus-client"]

# Deprecated feature flags
metrics = ["metrics-0_21"]
opentelemetry = ["opentelemetry-0_20"]
opentelemetry = ["opentelemetry-0_21"]
prometheus = ["prometheus-0_13"]
prometheus-client = ["prometheus-client-0_21"]
exemplars-tracing-opentelemetry = ["exemplars-tracing-opentelemetry-0_20"]
exemplars-tracing-opentelemetry = ["exemplars-tracing-opentelemetry-0_22"]

# Misc
prometheus-exporter = [
Expand All @@ -38,7 +38,7 @@ prometheus-exporter = [

otel-push-exporter = [
"opentelemetry_sdk",
"opentelemetry_api",
"dep:opentelemetry",
"opentelemetry-otlp",
"opentelemetry-otlp/metrics",
"opentelemetry-otlp/tls-roots"
Expand Down Expand Up @@ -71,15 +71,11 @@ otel-push-exporter-async-std = [

# Exemplars
exemplars-tracing = ["tracing", "tracing-subscriber"]
exemplars-tracing-opentelemetry-0_20 = [
"opentelemetry_api/trace",
exemplars-tracing-opentelemetry-0_22 = [
"dep:opentelemetry",
"opentelemetry_sdk/trace",
"tracing",
"dep:tracing-opentelemetry-0-20",
]
exemplars-tracing-opentelemetry-0_21 = [
"opentelemetry_api/trace",
"tracing",
"dep:tracing-opentelemetry-0-21",
"dep:tracing-opentelemetry-0-22",
]

# Custom objectives
Expand All @@ -94,19 +90,19 @@ spez = "0.1.2"
thiserror = "1"

# Used for opentelemetry feature
opentelemetry_api = { version = "0.20", default-features = false, optional = true }
opentelemetry = { version = "0.21", 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 = [
opentelemetry-prometheus = { version = "0.14", optional = true }
opentelemetry_sdk = { version = "0.21", default-features = false, features = [
"metrics",
], optional = true }
opentelemetry-otlp = { version = "0.13.0", default-features = false, optional = true }
opentelemetry-otlp = { version = "0.14.0", default-features = false, optional = true }
prometheus = { version = "0.13", default-features = false, optional = true }

# Used for prometheus-client feature
Expand All @@ -119,16 +115,15 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
], optional = true }

# Used for exemplars-tracing-opentelemetry feature
tracing-opentelemetry-0-20 = { package = "tracing-opentelemetry", version = "0.20.0", default-features = false, optional = true }
tracing-opentelemetry-0-21 = { package = "tracing-opentelemetry", version = "0.21.0", default-features = false, optional = true }
tracing-opentelemetry-0-22 = { package = "tracing-opentelemetry", version = "0.22", default-features = false, optional = true }

[dev-dependencies]
async-trait = "0.1.74"
axum = { version = "0.6", features = ["tokio"] }
criterion = "0.5"
http = "0.2"
opentelemetry = "0.20"
opentelemetry-stdout = { version = "0.1", features = ["trace"] }
opentelemetry = "0.21"
opentelemetry-stdout = { version = "0.2", features = ["trace"] }
prometheus-client = "0.21"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
Expand Down
8 changes: 4 additions & 4 deletions autometrics/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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_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")]
println!("cargo:warning=The `prometheus-client` feature is deprecated and will be removed in the next version. Please use `prometheus-client-0_21` instead.");
#[cfg(feature = "exemplars-tracing-opentelemetry")]
println!("cargo:warning=The `exemplars-tracing-opentelemetry` feature is deprecated and will be removed in the next version. Please use `exemplars-tracing-opentelemetry-0_20` or `exemplars-tracing-opentelemetry-0_21` instead.");
println!("cargo:warning=The `exemplars-tracing-opentelemetry` feature is deprecated and will be removed in the next version. Please use `exemplars-tracing-opentelemetry-0_22` instead.");

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_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 @@ -32,7 +32,7 @@ pub fn main() {
// Exemplars
exemplars: { any(exemplars_tracing, exemplars_tracing_opentelemetry) },
exemplars_tracing: { feature = "exemplars-tracing" },
exemplars_tracing_opentelemetry: { any(feature = "exemplars-tracing-opentelemetry-0_20", feature = "exemplars-tracing-opentelemetry-0_21", feature = "exemplars-tracing-opentelemetry") },
exemplars_tracing_opentelemetry: { any(feature = "exemplars-tracing-opentelemetry-0_22", feature = "exemplars-tracing-opentelemetry") },

// Custom objectives
custom_objective_percentile: { feature = "custom-objective-percentile" },
Expand Down
17 changes: 3 additions & 14 deletions autometrics/src/exemplars/tracing_opentelemetry.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
use super::TraceLabels;
use opentelemetry_api::trace::TraceContextExt;
use opentelemetry::trace::TraceContextExt as _;
use std::iter::FromIterator;
use tracing::Span;

#[cfg(all(
not(doc),
all(
feature = "exemplars-tracing-opentelemetry-0_20",
feature = "exemplars-tracing-opentelemetry-0_21"
)
))]
compile_error!("Only one of the `exemplars-tracing-opentelemetry-0_20` and `exemplars-tracing-opentelemetry-0_21` features can be enabled at a time");
use tracing_opentelemetry_0_22::OpenTelemetrySpanExt;

pub fn get_exemplar() -> Option<TraceLabels> {
// Get the OpenTelemetry Context from the tracing span
#[cfg(feature = "exemplars-tracing-opentelemetry-0_20")]
let context = tracing_opentelemetry_0_20::OpenTelemetrySpanExt::context(&Span::current());
#[cfg(feature = "exemplars-tracing-opentelemetry-0_21")]
let context = tracing_opentelemetry_0_21::OpenTelemetrySpanExt::context(&Span::current());
let context = OpenTelemetrySpanExt::context(&Span::current());

// Now get the OpenTelemetry "span" from the Context
// (it's confusing because the word "span" is used by both tracing and OpenTelemetry
Expand Down
3 changes: 1 addition & 2 deletions autometrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ mod constants;
#[cfg(any(
feature = "exemplars-tracing",
feature = "exemplars-tracing-opentelemetry",
feature = "exemplars-tracing-opentelemetry-0_20",
feature = "exemplars-tracing-opentelemetry-0_21",
feature = "exemplars-tracing-opentelemetry-0_22",
))]
pub mod exemplars;
mod labels;
Expand Down
14 changes: 10 additions & 4 deletions autometrics/src/otel_push_exporter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry_api::metrics::MetricsError;
use opentelemetry::metrics::MetricsError;
use opentelemetry_otlp::OtlpMetricPipeline;
use opentelemetry_otlp::{ExportConfig, Protocol, WithExportConfig};
use opentelemetry_sdk::metrics::MeterProvider;
Expand Down Expand Up @@ -122,7 +122,8 @@ pub fn init_grpc_with_timeout_period(
feature = "otel-push-exporter-async-std"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::Tokio> {
fn runtime(
) -> OtlpMetricPipeline<opentelemetry_sdk::runtime::Tokio, opentelemetry_otlp::NoExporterConfig> {
return opentelemetry_otlp::new_pipeline().metrics(opentelemetry_sdk::runtime::Tokio);
}

Expand All @@ -133,7 +134,10 @@ fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::Tokio> {
feature = "otel-push-exporter-async-std"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::TokioCurrentThread> {
fn runtime() -> OtlpMetricPipeline<
opentelemetry_sdk::runtime::TokioCurrentThread,
opentelemetry_otlp::NoExporterConfig,
> {
return opentelemetry_otlp::new_pipeline()
.metrics(opentelemetry_sdk::runtime::TokioCurrentThread);
}
Expand All @@ -145,7 +149,9 @@ fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::TokioCurrentThrea
feature = "otel-push-exporter-tokio-current-thread"
))
))]
fn runtime() -> OtlpMetricPipeline<opentelemetry_sdk::runtime::AsyncStd> {
fn runtime(
) -> OtlpMetricPipeline<opentelemetry_sdk::runtime::AsyncStd, opentelemetry_otlp::NoExporterConfig>
{
return opentelemetry_otlp::new_pipeline().metrics(opentelemetry_sdk::runtime::AsyncStd);
}

Expand Down
4 changes: 2 additions & 2 deletions autometrics/src/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use http::{header::CONTENT_TYPE, Response};
use metrics_exporter_prometheus::{BuildError, PrometheusBuilder, PrometheusHandle};
use once_cell::sync::OnceCell;
#[cfg(opentelemetry)]
use opentelemetry_api::metrics::MetricsError;
use opentelemetry::metrics::MetricsError;
#[cfg(any(opentelemetry, prometheus))]
use prometheus::TextEncoder;
use thiserror::Error;
Expand Down Expand Up @@ -210,7 +210,7 @@ fn initialize_prometheus_exporter() -> Result<GlobalPrometheus, ExporterInitiali

#[cfg(opentelemetry)]
{
use opentelemetry_api::global;
use opentelemetry::global;
use opentelemetry_prometheus::exporter;
use opentelemetry_sdk::metrics::reader::AggregationSelector;
use opentelemetry_sdk::metrics::{Aggregation, InstrumentKind, MeterProvider};
Expand Down
4 changes: 2 additions & 2 deletions autometrics/src/tracker/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::__private::FunctionDescription;
use crate::labels::{BuildInfoLabels, CounterLabels, GaugeLabels, HistogramLabels, Label};
use crate::{constants::*, tracker::TrackMetrics};
use once_cell::sync::Lazy;
use opentelemetry_api::metrics::{Counter, Histogram, Unit, UpDownCounter};
use opentelemetry_api::{global, KeyValue};
use opentelemetry::metrics::{Counter, Histogram, Unit, UpDownCounter};
use opentelemetry::{global, KeyValue};
use std::{sync::Once, time::Instant};

static SET_BUILD_INFO: Once = Once::new();
Expand Down
9 changes: 4 additions & 5 deletions autometrics/tests/exemplars_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn multiple_fields() {
#[cfg(exemplars_tracing_opentelemetry)]
#[test]
fn tracing_opentelemetry_context() {
use opentelemetry_api::trace::TracerProvider as _;
use opentelemetry::trace::TracerProvider as _;
use opentelemetry_sdk::trace::TracerProvider;
use opentelemetry_stdout::SpanExporter;
use std::io;
Expand All @@ -70,10 +70,9 @@ fn tracing_opentelemetry_context() {
let tracer = provider.tracer("test");

// This adds the OpenTelemetry Context to every tracing Span
#[cfg(feature = "exemplars-tracing-opentelemetry-0_20")]
let otel_layer = tracing_opentelemetry_0_20::layer().with_tracer(tracer);
#[cfg(feature = "exemplars-tracing-opentelemetry-0_21")]
let otel_layer = tracing_opentelemetry_0_21::layer().with_tracer(tracer);
#[cfg(feature = "exemplars-tracing-opentelemetry-0_22")]
let otel_layer = tracing_opentelemetry_0_22::layer().with_tracer(tracer);

let subscriber = Registry::default().with(otel_layer);

#[autometrics]
Expand Down
10 changes: 8 additions & 2 deletions autometrics/tests/result_labels/fail/async_trait_support.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ error: #[async_trait] must be defined BEFORE #[autometrics]
= note: this error originates in the attribute macro `autometrics` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `TestStruct: TestTrait` is not satisfied
--> tests/result_labels/fail/async_trait_support.rs:31:9
--> tests/result_labels/fail/async_trait_support.rs:31:10
|
31 | <TestStruct as TestTrait>::method().await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TestTrait` is not implemented for `TestStruct`
| ^^^^^^^^^^ the trait `TestTrait` is not implemented for `TestStruct`
|
help: this trait has no implementations, consider adding one
--> tests/result_labels/fail/async_trait_support.rs:7:1
|
7 | trait TestTrait {
| ^^^^^^^^^^^^^^^

error[E0599]: no method named `self_method` found for struct `TestStruct` in the current scope
--> tests/result_labels/fail/async_trait_support.rs:32:12
Expand Down
2 changes: 1 addition & 1 deletion autometrics/tests/settings_custom_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn custom_prometheus_registry() {
#[cfg(opentelemetry)]
#[test]
fn custom_opentelemetry_registry() {
use opentelemetry_api::{global, KeyValue};
use opentelemetry::{global, KeyValue};
use prometheus::{Registry, TextEncoder};

// OpenTelemetry uses the `prometheus` crate under the hood
Expand Down
2 changes: 1 addition & 1 deletion examples/exemplars-tracing-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
autometrics = { path = "../../autometrics", features = [
"prometheus-client-0_21",
"prometheus-exporter",
"exemplars-tracing-opentelemetry-0_21",
"exemplars-tracing-opentelemetry-0_22",
] }
autometrics-example-util = { path = "../util" }
axum = { version = "0.6", features = ["json"] }
Expand Down
9 changes: 5 additions & 4 deletions examples/opentelemetry-push-custom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ publish = false
edition = "2021"

[dependencies]
autometrics = { path = "../../autometrics", features = ["opentelemetry-0_20"] }
autometrics = { path = "../../autometrics", features = ["opentelemetry-0_21"] }
autometrics-example-util = { path = "../util" }
# Note that the version of the opentelemetry crate MUST match
# the version used by autometrics
opentelemetry = { version = "0.20", features = ["metrics", "rt-tokio"] }
opentelemetry-otlp = { version = "0.13", features = ["tonic", "metrics"] }
opentelemetry-semantic-conventions = { version = "0.12.0" }
opentelemetry = { version = "0.21", features = ["metrics"] }
opentelemetry_sdk = { version = "0.21.1", features = ["metrics", "rt-tokio"] }
opentelemetry-otlp = { version = "0.14", features = ["tonic", "metrics"] }
opentelemetry-semantic-conventions = { version = "0.13" }
tokio = { version = "1", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/opentelemetry-push/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ publish = false
edition = "2021"

[dependencies]
autometrics = { path = "../../autometrics", features = ["opentelemetry-0_20", "otel-push-exporter-http", "otel-push-exporter-tokio"] }
autometrics = { path = "../../autometrics", features = ["opentelemetry-0_21", "otel-push-exporter-http", "otel-push-exporter-tokio"] }
autometrics-example-util = { path = "../util" }
tokio = { version = "1", features = ["full"] }