mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 15:05:40 +00:00
a2a594b763
* Create example for apub lib * some rewriting of apub lib * Add LocalInstance struct for apub lib to avoid using Lemmy Settings * Move ActorType trait to lemmy_apub, because its not needed in library * Use reqwest_retry instead of custom impl, dont specify timeout on every send() * Some improvements to example * Moved inbox handling to library * bug fixes * Move context and serde helpers into library * wip: example changes * Add lemmy_utils feature to build only LemmyError * Rename to activitypub_federation * Remove lemmy_utils dep from activitypub_federation using generic error type * Finish activitypub example * Cleanup and fix tests * Reorganize library files * Remove ApubObject.to_tombstone() * Extract activitypub library into separate git repository
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use console_subscriber::ConsoleLayer;
|
|
use lemmy_utils::error::LemmyError;
|
|
use opentelemetry::{
|
|
sdk::{propagation::TraceContextPropagator, Resource},
|
|
KeyValue,
|
|
};
|
|
use opentelemetry_otlp::WithExportConfig;
|
|
use tracing::{subscriber::set_global_default, Subscriber};
|
|
use tracing_subscriber::{filter::Targets, layer::SubscriberExt, registry::LookupSpan, Layer};
|
|
|
|
pub fn init_tracing<S>(
|
|
opentelemetry_url: &str,
|
|
subscriber: S,
|
|
targets: Targets,
|
|
) -> Result<(), LemmyError>
|
|
where
|
|
S: Subscriber + for<'a> LookupSpan<'a> + Send + Sync + 'static,
|
|
{
|
|
opentelemetry::global::set_text_map_propagator(TraceContextPropagator::new());
|
|
|
|
let console_layer = ConsoleLayer::builder()
|
|
.with_default_env()
|
|
.server_addr(([0, 0, 0, 0], 6669))
|
|
.event_buffer_capacity(1024 * 1024)
|
|
.spawn();
|
|
|
|
let subscriber = subscriber.with(console_layer);
|
|
|
|
let tracer = opentelemetry_otlp::new_pipeline()
|
|
.tracing()
|
|
.with_trace_config(
|
|
opentelemetry::sdk::trace::config()
|
|
.with_resource(Resource::new(vec![KeyValue::new("service.name", "lemmy")])),
|
|
)
|
|
.with_exporter(
|
|
opentelemetry_otlp::new_exporter()
|
|
.tonic()
|
|
.with_endpoint(opentelemetry_url),
|
|
)
|
|
.install_batch(opentelemetry::runtime::Tokio)?;
|
|
|
|
let otel_layer = tracing_opentelemetry::layer()
|
|
.with_tracer(tracer)
|
|
.with_filter(targets);
|
|
|
|
let subscriber = subscriber.with(otel_layer);
|
|
|
|
set_global_default(subscriber)?;
|
|
|
|
Ok(())
|
|
}
|