-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from GPeaky/207-implementing-metrics
207 implementing metrics
- Loading branch information
Showing
8 changed files
with
79 additions
and
25 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "metrics" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[lib] | ||
path = "src/metrics.rs" | ||
doctest = false | ||
|
||
[dependencies] | ||
opentelemetry.workspace = true | ||
opentelemetry_sdk.workspace = true | ||
tracing-opentelemetry.workspace = true | ||
opentelemetry-otlp.workspace = true | ||
tracing-subscriber.workspace = true | ||
tracing-log.workspace = true | ||
tracing.workspace = true |
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,49 @@ | ||
use opentelemetry::global; | ||
use opentelemetry::KeyValue; | ||
use opentelemetry_otlp::WithExportConfig; | ||
use opentelemetry_sdk::{ | ||
runtime::Tokio, | ||
trace::{self, Tracer}, | ||
Resource, | ||
}; | ||
use tracing_log::LogTracer; | ||
use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry}; | ||
|
||
pub fn initialize_tracing_and_telemetry( | ||
) -> Result<Tracer, Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
global::set_text_map_propagator(opentelemetry_sdk::propagation::TraceContextPropagator::new()); | ||
|
||
let tracer = opentelemetry_otlp::new_pipeline() | ||
.tracing() | ||
.with_exporter( | ||
opentelemetry_otlp::new_exporter() | ||
.tonic() | ||
.with_endpoint("http://localhost:4317"), | ||
) | ||
.with_trace_config( | ||
trace::config().with_resource(Resource::new(vec![KeyValue::new( | ||
"service.name", | ||
"intelli-api", | ||
)])), | ||
) | ||
.install_batch(Tokio)?; | ||
|
||
let filter = EnvFilter::try_from_default_env() | ||
.or_else(|_| EnvFilter::try_new("info")) | ||
.unwrap(); | ||
|
||
let fmt_layer = fmt::layer().with_ansi(true).compact(); | ||
|
||
let telemetry_layer = tracing_opentelemetry::layer().with_tracer(tracer.clone()); | ||
|
||
let subscriber = Registry::default() | ||
.with(filter) | ||
.with(fmt_layer) | ||
.with(telemetry_layer); | ||
|
||
LogTracer::init()?; | ||
|
||
tracing::subscriber::set_global_default(subscriber)?; | ||
|
||
Ok(tracer) | ||
} |
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