-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(otel_metrics): OTEL first draft * feat(otel_metrics): Removed unused deps * feat(otel_metrics): Taplo linters * feat(otel_metrics): Added env for compose * feat(otel_metrics): otel endpoint
- Loading branch information
Showing
47 changed files
with
789 additions
and
438 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ authors = ["Pragma Labs <[email protected]>"] | |
color-eyre = "0.6" | ||
aws-config = { version = "1.5.1", features = ["behavior-version-latest"] } | ||
aws-sdk-secretsmanager = "1.32.0" | ||
axum = { version = "0.6", features = ["macros", "ws", "tokio"] } | ||
axum = { version = "0.7.7", features = ["macros", "ws", "tokio"] } | ||
axum-macros = "0.3" | ||
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.5", features = [ | ||
"abigen-rs", | ||
"abigen-rs", | ||
] } | ||
diesel = { version = "2.1", features = [ | ||
"postgres", | ||
|
@@ -42,8 +42,7 @@ chrono = { version = "0.4.26", features = ["serde"] } | |
lazy_static = "1.4.0" | ||
serde = { version = "1.0.204", features = ["derive"] } | ||
moka = { version = "0.12", features = ["future"] } | ||
opentelemetry = { version = "0.22" } | ||
prometheus = "0.13.4" | ||
opentelemetry = { version = "0.26.0", features = ["metrics", "logs"] } | ||
nonzero_ext = { version = "0.3.0" } | ||
serde_json = { version = "1.0.122", features = ["arbitrary_precision"] } | ||
starknet = "0.12.0" | ||
|
@@ -58,14 +57,33 @@ strum = { version = "0.26", features = ["derive"] } | |
tracing = "0.1.4" | ||
tracing-test = "0.2.5" | ||
url = "2.5.0" | ||
tower-http = { version = "0.4.0", features = ["fs", "trace", "cors"] } | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
tokio = { version = "1.11.0", features = ["full"] } | ||
tower-http = { version = "0.6.2", features = ["fs", "trace", "cors"] } | ||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
tokio = { version = "~1.38.0", features = ["full"] } | ||
toml = "0.8.8" | ||
utoipa = { version = "4", features = ["axum_extras", "chrono", "uuid"] } | ||
utoipa = { version = "5.0.0", features = ["axum_extras", "chrono", "uuid"] } | ||
utoipauto = "0.1.14" | ||
utoipa-swagger-ui = { version = "4", features = ["axum"] } | ||
utoipa-swagger-ui = { version = "8.0.3", features = ["axum"] } | ||
uuid = { version = "1.4", features = ["fast-rng", "v4", "serde"] } | ||
init-tracing-opentelemetry = { version = "0.22.0", features = [ | ||
"otlp", | ||
"tracing_subscriber_ext", | ||
] } | ||
axum-tracing-opentelemetry = "0.21.1" | ||
opentelemetry-otlp = { version = "0.26.0", features = [ | ||
"metrics", | ||
"tonic", | ||
"logs", | ||
] } | ||
tracing-opentelemetry-instrumentation-sdk = "0.21.0" | ||
opentelemetry_sdk = { version = "0.26.0", features = [ | ||
"metrics", | ||
"rt-tokio", | ||
"logs", | ||
] } | ||
tracing-opentelemetry = "0.27.0" | ||
opentelemetry-appender-tracing = "0.26.0" | ||
opentelemetry-semantic-conventions = "0.26.0" | ||
|
||
pragma-monitoring = { git = "https://github.com/astraly-labs/pragma-monitoring" } | ||
|
||
|
@@ -80,6 +98,3 @@ testcontainers-modules = { version = "0.9.0", features = [ | |
"http_wait", | ||
] } | ||
pretty_assertions = "1.4.0" | ||
|
||
[workspace.patch.crates-io] | ||
quote = { version = "1.0.37" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod errors; | ||
pub mod hash; | ||
pub mod tracing; | ||
pub mod telemetry; | ||
pub mod types; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use color_eyre::eyre::Result; | ||
use init_tracing_opentelemetry::tracing_subscriber_ext::build_otel_layer; | ||
use opentelemetry::trace::TracerProvider; | ||
use opentelemetry::{global, KeyValue}; | ||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||
use opentelemetry_otlp::WithExportConfig; | ||
use opentelemetry_sdk::logs::{BatchConfig, LoggerProvider}; | ||
use opentelemetry_sdk::metrics::reader::DefaultTemporalitySelector; | ||
use opentelemetry_sdk::metrics::{MeterProviderBuilder, PeriodicReader}; | ||
use opentelemetry_sdk::{runtime, trace::BatchConfigBuilder}; | ||
use opentelemetry_sdk::{ | ||
trace::{Config, Tracer}, | ||
Resource, | ||
}; | ||
use opentelemetry_semantic_conventions::resource::SERVICE_NAME; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing::Level; | ||
use tracing_opentelemetry::OpenTelemetryLayer; | ||
use tracing_subscriber::layer::SubscriberExt; | ||
use tracing_subscriber::util::SubscriberInitExt; | ||
|
||
pub fn init_telemetry( | ||
app_name: String, | ||
collection_endpoint: String, | ||
log_level: Option<Level>, | ||
) -> Result<()> { | ||
let tracing_subscriber = tracing_subscriber::registry() | ||
.with(build_otel_layer()?) | ||
.with(LevelFilter::from_level(log_level.unwrap_or(Level::INFO))) | ||
.with( | ||
tracing_subscriber::fmt::layer() | ||
.with_target(false) | ||
.with_file(false) | ||
.with_line_number(false) | ||
.pretty(), | ||
); | ||
|
||
let tracer_provider = init_tracer_provider(&app_name, &collection_endpoint)?; | ||
let logger_provider = init_logs_provider(&app_name, &collection_endpoint)?; | ||
init_meter_provider(&app_name, &collection_endpoint)?; | ||
|
||
tracing_subscriber | ||
.with(OpenTelemetryLayer::new(tracer_provider)) | ||
.with(OpenTelemetryTracingBridge::new(&logger_provider)) | ||
.init(); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn init_tracer_provider(app_name: &str, collection_endpoint: &str) -> Result<Tracer> { | ||
let provider = opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_batch_config(BatchConfigBuilder::default().build()) | ||
.with_trace_config( | ||
Config::default().with_resource(Resource::new(vec![KeyValue::new( | ||
SERVICE_NAME, | ||
format!("{app_name}-trace-service"), | ||
)])), | ||
) | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint(collection_endpoint), | ||
) | ||
.install_batch(runtime::Tokio) | ||
.expect("Failed to install tracer provider"); | ||
|
||
global::set_tracer_provider(provider.clone()); | ||
Ok(provider.tracer(format!("{app_name}-subscriber"))) | ||
} | ||
|
||
fn init_logs_provider(app_name: &str, collection_endpoint: &str) -> Result<LoggerProvider> { | ||
let logger = opentelemetry_otlp::new_pipeline() | ||
.logging() | ||
.with_batch_config(BatchConfig::default()) | ||
.with_resource(Resource::new(vec![KeyValue::new( | ||
SERVICE_NAME, | ||
format!("{app_name}-logs-service"), | ||
)])) | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint(collection_endpoint), | ||
) | ||
.install_batch(runtime::Tokio)?; | ||
|
||
Ok(logger) | ||
} | ||
|
||
pub fn init_meter_provider(app_name: &str, collection_endpoint: &str) -> Result<()> { | ||
let exporter = opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint(collection_endpoint) | ||
.build_metrics_exporter(Box::new(DefaultTemporalitySelector::new()))?; | ||
|
||
let reader = PeriodicReader::builder(exporter, runtime::Tokio) | ||
.with_interval(std::time::Duration::from_secs(5)) | ||
.build(); | ||
|
||
let metrics_provider = MeterProviderBuilder::default() | ||
.with_reader(reader) | ||
.with_resource(Resource::new(vec![KeyValue::new( | ||
SERVICE_NAME, | ||
format!("{app_name}-meter-service"), | ||
)])) | ||
.build(); | ||
|
||
// Set the global meter provider | ||
global::set_meter_provider(metrics_provider); | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.