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

chore(opentelemetry): update to 0.27 #87

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
27 changes: 14 additions & 13 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 @@ -62,9 +62,9 @@ libc = "^0.2"
chrono = "^0.4"
nix = "^0.29"
clap = "^4"
opentelemetry-otlp = "^0.25"
opentelemetry = "^0.25"
opentelemetry_sdk = "^0.25"
opentelemetry-otlp = "^0.27"
opentelemetry = "^0.27"
opentelemetry_sdk = "^0.27"
rinfluxdb = "0.2.0"
tonic = "^0.12"
tonic-build = "0.12"
Expand Down
8 changes: 4 additions & 4 deletions src/otlp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl From<OtlpConfig> for ExportConfig {
panic!("Not support protocol, just support Grpc, HttpBinary, HttpJson")
};
Self {
endpoint: val.endpoint,
endpoint: Some(val.endpoint),
protocol,
timeout: val.timeout,
}
Expand All @@ -74,7 +74,7 @@ impl From<&OtlpConfig> for ExportConfig {
panic!("Not support protocol, just support Grpc, HttpBinary, HttpJson")
};
Self {
endpoint: val.endpoint.clone(),
endpoint: Some(val.endpoint.clone()),
protocol,
timeout: val.timeout,
}
Expand Down Expand Up @@ -154,7 +154,7 @@ nanos = 0
"Grpc".to_owned(),
);
let export_config = ExportConfig {
endpoint: "http://localhost:4317".to_owned(),
endpoint: Some("http://localhost:4317".to_owned()),
timeout: Duration::from_secs(3),
protocol: Protocol::Grpc,
};
Expand All @@ -167,7 +167,7 @@ nanos = 0
"HttpJson".to_owned(),
);
let export_config = ExportConfig {
endpoint: "http://localhost:7878".to_owned(),
endpoint: Some("http://localhost:7878".to_owned()),
timeout: Duration::new(2, 20),
protocol: Protocol::HttpJson,
};
Expand Down
2 changes: 1 addition & 1 deletion src/otlp/gauges/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ pub fn start(
});
}
})
.try_init()?;
.build();
Ok(gauge)
}
2 changes: 1 addition & 1 deletion src/otlp/gauges/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ pub fn start(
}
}
})
.try_init()?;
.build();
Ok(gauge)
}
2 changes: 1 addition & 1 deletion src/otlp/gauges/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ pub fn start(
gauge.observe(m, &[KeyValue::new("token", token.clone()), kv]);
})
})
.try_init()?;
.build();
Ok(gauge)
}
2 changes: 1 addition & 1 deletion src/otlp/gauges/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ pub fn start(
})
}
})
.try_init()?;
.build();
Ok(gauge)
}
32 changes: 15 additions & 17 deletions src/otlp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,33 @@ use std::time::Duration;

use anyhow::Result;
use opentelemetry::{metrics::MeterProvider, KeyValue};
use opentelemetry_otlp::{ExportConfig, WithExportConfig};
use opentelemetry_otlp::{ExportConfig, MetricExporter, WithExportConfig, WithTonicConfig};
use opentelemetry_sdk::{
metrics::{
reader::{DefaultAggregationSelector, DefaultTemporalitySelector},
SdkMeterProvider,
},
metrics::{PeriodicReader, SdkMeterProvider},
runtime, Resource,
};
use tonic::{metadata::MetadataMap, transport::ClientTlsConfig};

pub fn meter_provider(export_config: ExportConfig, token: String) -> Result<SdkMeterProvider> {
let mut meta = MetadataMap::new();
meta.insert("authorization", format!("Bearer {}", token).parse()?);
let otlp_exporter = opentelemetry_otlp::new_exporter()
.tonic()
let otlp_exporter = MetricExporter::builder()
.with_tonic()
.with_tls_config(ClientTlsConfig::new().with_native_roots())
.with_metadata(meta)
.with_export_config(export_config);
.with_timeout(Duration::from_secs(10))
.with_export_config(export_config)
.build()?;
let reader = PeriodicReader::builder(otlp_exporter, runtime::Tokio)
.with_interval(Duration::from_secs(1))
.build();

opentelemetry_otlp::new_pipeline()
.metrics(runtime::Tokio)
.with_exporter(otlp_exporter)
let a = SdkMeterProvider::builder()
.with_reader(reader)
.with_resource(Resource::new(vec![KeyValue::new("service.name", "PSH")]))
.with_period(Duration::from_secs(1))
.with_timeout(Duration::from_secs(10))
.with_aggregation_selector(DefaultAggregationSelector::new())
.with_temporality_selector(DefaultTemporalitySelector::new())
.build()
.map_err(Into::into)
.build();

Ok(a)
}

pub async fn otlp_tasks(export_config: ExportConfig, token: String) -> anyhow::Result<()> {
Expand Down
Loading