mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 14:42:30 +00:00
Hide opentelemetry behind feature flag
This commit is contained in:
22
Cargo.toml
22
Cargo.toml
@@ -16,6 +16,16 @@ repository.workspace = true
|
||||
resolver = "2"
|
||||
publish = false
|
||||
|
||||
[features]
|
||||
debug = ["opentelemetry"]
|
||||
opentelemetry = [
|
||||
"dep:opentelemetry",
|
||||
"dep:opentelemetry-otlp",
|
||||
"dep:opentelemetry_sdk",
|
||||
"dep:opentelemetry-semantic-conventions",
|
||||
"dep:tracing-opentelemetry",
|
||||
]
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
|
||||
@@ -122,12 +132,14 @@ sqlx = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
tracing-actix-web = { workspace = true }
|
||||
|
||||
opentelemetry = "0.27"
|
||||
opentelemetry-otlp = "0.27"
|
||||
opentelemetry_sdk = { version = "0.27", features = ["rt-tokio"] }
|
||||
opentelemetry = { version = "0.27", optional = true }
|
||||
opentelemetry-otlp = { version = "0.27", optional = true }
|
||||
opentelemetry_sdk = { version = "0.27", features = [
|
||||
"rt-tokio",
|
||||
], optional = true }
|
||||
opentelemetry-semantic-conventions = { version = "0.27", optional = true }
|
||||
tracing-opentelemetry = { version = "0.28", optional = true }
|
||||
|
||||
opentelemetry-semantic-conventions = "0.27"
|
||||
tracing-opentelemetry = "0.28"
|
||||
tracing-subscriber = { version = "0.3", features = [
|
||||
"env-filter",
|
||||
"fmt",
|
||||
|
||||
19
README.md
19
README.md
@@ -3,9 +3,9 @@
|
||||
a CalDAV/CardDAV server
|
||||
|
||||
> [!CAUTION]
|
||||
> RustiCal is **not production-ready!**
|
||||
> There can be changes to the database without migrations and there's no guarantee that all endpoints are secured yet.
|
||||
> If you still want to play around with it in its current state, absolutely feel free to do so but know that not even I use it productively yet.
|
||||
> If you're installing RustiCal, you are a very early adopter!
|
||||
>
|
||||
> - You should be unafraid to inspect the SQLite database yourself if something goes wrong in the future
|
||||
|
||||
## Features
|
||||
|
||||
@@ -41,8 +41,7 @@ You can generate a default `config.toml` with
|
||||
rustical gen-config
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> `rustical gen-config` generates a random `frontend.secret_key`.
|
||||
> [!WARNING] > `rustical gen-config` generates a random `frontend.secret_key`.
|
||||
> This secret is used to generate session cookies so if it is leaked an attacker could use it to authenticate to against any endpoint (also when the frontend is disabled).
|
||||
|
||||
You'll have to set your database path to something like `/var/lib/rustical/db.sqlite3`.
|
||||
@@ -82,6 +81,16 @@ Since push messages are currently not encrypted you might potentially want to en
|
||||
allowed_push_servers = ["https://your-instance-ntfy.sh"]
|
||||
```
|
||||
|
||||
## Debugging
|
||||
|
||||
RustiCal supports exporting opentelemetry traces to inspect with tools like [Jaeger](https://www.jaegertracing.io/).
|
||||
To enable you need to compile with the `opentelemtry` (or `debug`) feature and enable opentelemetry in the config with
|
||||
|
||||
```toml
|
||||
[tracing]
|
||||
opentelemetry = true
|
||||
```
|
||||
|
||||
## Relevant RFCs
|
||||
|
||||
- Versioning Extensions to WebDAV: [RFC 3253](https://datatracker.ietf.org/doc/html/rfc3253)
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
use crate::config::TracingConfig;
|
||||
use opentelemetry::global;
|
||||
use opentelemetry::trace::TracerProvider;
|
||||
use opentelemetry::KeyValue;
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use opentelemetry::{global, trace::TracerProvider, KeyValue};
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use opentelemetry_otlp::WithExportConfig;
|
||||
use opentelemetry_sdk::propagation::TraceContextPropagator;
|
||||
use opentelemetry_sdk::trace::Tracer;
|
||||
use opentelemetry_sdk::Resource;
|
||||
use opentelemetry_semantic_conventions::resource::{SERVICE_NAME, SERVICE_VERSION};
|
||||
use opentelemetry_semantic_conventions::SCHEMA_URL;
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Tracer, Resource};
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use opentelemetry_semantic_conventions::{
|
||||
resource::{SERVICE_NAME, SERVICE_VERSION},
|
||||
SCHEMA_URL,
|
||||
};
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use std::time::Duration;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
#[cfg(not(feature = "opentelemetry"))]
|
||||
use tracing::warn;
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
use tracing_opentelemetry::OpenTelemetryLayer;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
pub fn init_tracer() -> Tracer {
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
pub fn init_otel() -> Tracer {
|
||||
let otel_exporter = opentelemetry_otlp::SpanExporter::builder()
|
||||
.with_tonic()
|
||||
.with_timeout(Duration::from_secs(1))
|
||||
@@ -51,8 +58,16 @@ pub fn setup_tracing(config: &TracingConfig) {
|
||||
.with(fmt_layer);
|
||||
|
||||
if config.opentelemetry {
|
||||
global::set_text_map_propagator(TraceContextPropagator::new());
|
||||
registry.with(OpenTelemetryLayer::new(init_tracer())).init();
|
||||
#[cfg(feature = "opentelemetry")]
|
||||
{
|
||||
global::set_text_map_propagator(TraceContextPropagator::new());
|
||||
registry.with(OpenTelemetryLayer::new(init_otel())).init();
|
||||
}
|
||||
#[cfg(not(feature = "opentelemetry"))]
|
||||
{
|
||||
registry.init();
|
||||
warn!("This version of RustiCal is compiled without the opentelemetry feature. tracing.opentelemtry = true has no effect");
|
||||
}
|
||||
} else {
|
||||
registry.init();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user