Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ opentelemetry-otlp = { version = "0.31.0", features = [
"http-proto",
"reqwest-blocking-client",
] }
opentelemetry-semantic-conventions = "0.31.0"
opentelemetry-semantic-conventions = { version = "0.31.0", features = ["semconv_experimental"] }
opentelemetry_sdk = "0.31.0"
pallas-addresses = "0.34.0"
pallas-codec = "0.34.0" # When updating, double check that minicbor doesn't need to be updated too (see https://github.com/txpipe/pallas/blob/v0.32.0/pallas-codec/Cargo.toml#L22)
Expand Down
20 changes: 12 additions & 8 deletions crates/amaru/src/observability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use std::{
env::VarError,
env::{VarError, var},
error::Error,
fmt,
io::{self, IsTerminal},
Expand All @@ -25,7 +25,7 @@ use std::{
use opentelemetry::trace::TracerProvider;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{metrics::SdkMeterProvider, trace::SdkTracerProvider};
use opentelemetry_semantic_conventions::resource::SERVICE_NAME;
use opentelemetry_semantic_conventions::resource::{SERVICE_INSTANCE_ID, SERVICE_NAME};
use tracing::{Metadata, Subscriber, info, level_filters::LevelFilter, span, subscriber::Interest, warn};
use tracing_subscriber::{
EnvFilter, Registry,
Expand Down Expand Up @@ -267,17 +267,21 @@ impl Default for OpenTelemetryHandle {
}
}

pub const DEFAULT_OTLP_SERVICE_NAME: &str = "amaru";

pub const DEFAULT_OTLP_METRIC_URL: &str = "http://localhost:4318/v1/metrics";
const DEFAULT_OTLP_SERVICE_NAME: &str = "amaru";
const DEFAULT_OTLP_METRIC_URL: &str = "http://localhost:4318/v1/metrics";

#[expect(clippy::panic)]
pub fn setup_open_telemetry(subscriber: &mut TracingSubscriber<Registry>) -> (OpenTelemetryHandle, DelayedWarning) {
use opentelemetry::KeyValue;
use opentelemetry_sdk::{Resource, metrics::Temporality};

let service_name = std::env::var("OTEL_SERVICE_NAME").unwrap_or_else(|_| DEFAULT_OTLP_SERVICE_NAME.to_string());
let resource = Resource::builder().with_attribute(KeyValue::new(SERVICE_NAME, service_name)).build();
let service_name = var("OTEL_SERVICE_NAME").unwrap_or_else(|_| DEFAULT_OTLP_SERVICE_NAME.to_string());
let service_instance_id = var("OTEL_SERVICE_INSTANCE_ID").ok();
let mut attributes = vec![KeyValue::new(SERVICE_NAME, service_name.clone())];
if let Some(id) = service_instance_id {
attributes.push(KeyValue::new(SERVICE_INSTANCE_ID, id));
}
let resource = Resource::builder().with_attributes(attributes).build();

// Traces & span
let opentelemetry_provider = SdkTracerProvider::builder()
Expand Down Expand Up @@ -313,7 +317,7 @@ pub fn setup_open_telemetry(subscriber: &mut TracingSubscriber<Registry>) -> (Op
opentelemetry::global::set_meter_provider(metrics_provider.clone());

// Subscriber
let opentelemetry_tracer = opentelemetry_provider.tracer(DEFAULT_OTLP_SERVICE_NAME);
let opentelemetry_tracer = opentelemetry_provider.tracer(service_name);
let (default_filter, warning) = new_default_filter(AMARU_TRACE_VAR, DEFAULT_AMARU_TRACE_FILTER);

let opentelemetry_layer =
Expand Down
3 changes: 2 additions & 1 deletion monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Coming soon.

Amaru recognizes standard OpenTelemetry env variable for its configuration:

- `OTEL_SERVICE_NAME`: Sets the `service.name` key used to identify metrics and traces. This is useful when a single OTLP service stack collects telemetry from several Amaru instances
- `OTEL_SERVICE_NAME`: Sets the [service.name](https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-name) key used to identify metrics and traces. Defaults to `amaru`.
- `OTEL_SERVICE_INSTANCE_ID`: Sets the [service.instance.id](https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/#service-instance-id) key used to identify this specific amaru instance
- `OTEL_EXPORTER_OTLP_ENDPOINT`: Sets the endpoint used to send spans, defaults to `http://localhost:4317`
- `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`: Sets the endpoint used to send metrics, defaults to `http://localhost:4318/v1/metrics`

Expand Down
Loading