Skip to content

Commit

Permalink
Upgrade to using latest open telemetry sdk (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbhattaccmu authored Dec 10, 2024
1 parent 39eb007 commit b06d05c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 110 deletions.
82 changes: 38 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ warp = "0.3.6"
futures = { version = "0.3.15", default-features = false, features = ["std", "async-await"] }

# OpenTelemetry
opentelemetry = "0.24.0"
opentelemetry-otlp = { version = "0.17.0", features = ["grpc-tonic", "metrics"] }
opentelemetry_sdk = { version = "0.24.1", features = ["metrics", "rt-tokio"] }
opentelemetry = "0.27.1"
opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "metrics"] }
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }

[profile.debug-fast]
inherits = "release"
Expand Down
1 change: 1 addition & 0 deletions bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [0.4.1](https://github.com/availproject/avail-light/releases/tag/avail-light-bootstrap-v0.4.1) - 2024-11-29

- Update opentelemetry sdk version
- Decrease connection idle timeout to 10s

## [0.4.0](https://github.com/availproject/avail-light/releases/tag/avail-light-bootstrap-v0.4.0) - 2024-11-05
Expand Down
48 changes: 29 additions & 19 deletions bootstrap/src/telemetry/otlp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use anyhow::{Error, Ok, Result};
use async_trait::async_trait;
use opentelemetry::{global, metrics::Meter, KeyValue};
use opentelemetry_otlp::{ExportConfig, Protocol, WithExportConfig};
use opentelemetry_otlp::{MetricExporter, Protocol, WithExportConfig};
use opentelemetry_sdk::{
metrics::{PeriodicReader, SdkMeterProvider},
runtime::Tokio,
Resource,
};
use std::time::Duration;
use tokio::sync::RwLock;

Expand All @@ -27,12 +32,13 @@ impl Metrics {
}

async fn record_u64(&self, name: &'static str, value: u64) -> Result<()> {
let instrument = self.meter.u64_observable_gauge(name).try_init()?;
let attributes = self.attributes().await;
self.meter
.register_callback(&[instrument.as_any()], move |observer| {
observer.observe_u64(&instrument, value, &attributes)
})?;
.u64_observable_gauge(name)
.with_callback(move |observer| {
observer.observe(value, &attributes);
})
.build();
Ok(())
}

Expand Down Expand Up @@ -68,22 +74,26 @@ pub fn initialize(
origin: String,
network: String,
) -> Result<Metrics, Error> {
let export_config = ExportConfig {
endpoint,
timeout: Duration::from_secs(10),
protocol: Protocol::Grpc,
};
let provider = opentelemetry_otlp::new_pipeline()
.metrics(opentelemetry_sdk::runtime::Tokio)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(export_config),
)
.with_period(Duration::from_secs(10))
.with_timeout(Duration::from_secs(15))
let exporter = MetricExporter::builder()
.with_tonic()
.with_endpoint(&endpoint)
.with_protocol(Protocol::Grpc)
.with_timeout(Duration::from_secs(30))
.build()?;

let reader = PeriodicReader::builder(exporter, Tokio)
.with_interval(Duration::from_secs(30))
.with_timeout(Duration::from_secs(30))
.build();

let provider = SdkMeterProvider::builder()
.with_reader(reader)
.with_resource(Resource::new(vec![KeyValue::new(
"service.name",
"bootstrap".to_string(),
)]))
.build();

global::set_meter_provider(provider);
let meter = global::meter("avail_light_bootstrap");

Expand Down
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.1.0

- Update opentelemetry sdk version to 0.27.1
- Enable WASM compilation of the network, light_client and related mods

## [1.0.5](https://github.com/availproject/avail-light/tree/avail-light-core-v1.0.5) - 2024-11-29
Expand Down
Loading

0 comments on commit b06d05c

Please sign in to comment.