Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -14,7 +14,7 @@ license = "MIT"
license-file = "LICENSE.txt"

[workspace.dependencies]
derive_builder = "0.20"
bon = { version = "3", features = ["implied-bounds"] }
derive_more = { version = "2.0", features = [
"constructor",
"display",
Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test-utilities = ["history_builders"]
anyhow = "1.0"
async-trait = "0.1"
base64 = "0.22"
bon = { workspace = true }
dirs = { version = "6.0", optional = true }
derive_builder = { workspace = true }
derive_more = { workspace = true }
opentelemetry = { workspace = true, optional = true }
prost = { workspace = true }
Expand Down
29 changes: 14 additions & 15 deletions crates/common/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ pub trait CoreTelemetry {
fn fetch_buffered_logs(&self) -> Vec<CoreLog>;
}

/// Telemetry configuration options. Construct with [TelemetryOptionsBuilder]
#[derive(Clone, derive_builder::Builder)]
/// Telemetry configuration options. Construct with [TelemetryOptions::builder]
#[derive(Clone, bon::Builder)]
#[non_exhaustive]
pub struct TelemetryOptions {
/// Optional logger - set as None to disable.
#[builder(setter(into, strip_option), default)]
#[builder(into)]
pub logging: Option<Logger>,
/// Optional metrics exporter - set as None to disable.
#[builder(setter(into, strip_option), default)]
#[builder(into)]
pub metrics: Option<Arc<dyn CoreMeter>>,
/// If set true (the default) explicitly attach a `service_name` label to all metrics. Turn this
/// off if your collection system supports the `target_info` metric from the OpenMetrics spec.
/// For more, see
/// [here](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems)
#[builder(default = "true")]
#[builder(default = true)]
pub attach_service_name: bool,
/// A prefix to be applied to all core-created metrics. Defaults to "temporal_".
#[builder(default = "METRIC_PREFIX.to_string()")]
#[builder(default = METRIC_PREFIX.to_string())]
pub metric_prefix: String,
/// If provided, logging config will be ignored and this explicit subscriber will be used for
/// all logging and traces.
#[builder(setter(strip_option), default)]
pub subscriber_override: Option<Arc<dyn Subscriber + Send + Sync>>,
/// See [TaskQueueLabelStrategy].
#[builder(default = "TaskQueueLabelStrategy::UseNormal")]
#[builder(default = TaskQueueLabelStrategy::UseNormal)]
pub task_queue_label_strategy: TaskQueueLabelStrategy,
}
impl Debug for TelemetryOptions {
Expand Down Expand Up @@ -96,19 +95,19 @@ pub enum TaskQueueLabelStrategy {
}

/// Options for exporting to an OpenTelemetry Collector
#[derive(Debug, Clone, derive_builder::Builder)]
#[derive(Debug, Clone, bon::Builder)]
pub struct OtelCollectorOptions {
/// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
/// export to this same collector.
pub url: Url,
/// Optional set of HTTP headers to send to the Collector, e.g for authentication.
#[builder(default = "HashMap::new()")]
#[builder(default = HashMap::new())]
pub headers: HashMap<String, String>,
/// Optionally specify how frequently metrics should be exported. Defaults to 1 second.
#[builder(default = "Duration::from_secs(1)")]
#[builder(default = Duration::from_secs(1))]
pub metric_periodicity: Duration,
/// Specifies the aggregation temporality for metric export. Defaults to cumulative.
#[builder(default = "MetricTemporality::Cumulative")]
#[builder(default = MetricTemporality::Cumulative)]
pub metric_temporality: MetricTemporality,
/// A map of tags to be applied to all metrics
#[builder(default)]
Expand All @@ -120,12 +119,12 @@ pub struct OtelCollectorOptions {
#[builder(default)]
pub histogram_bucket_overrides: HistogramBucketOverrides,
/// Protocol to use for communication with the collector
#[builder(default = "OtlpProtocol::Grpc")]
#[builder(default = OtlpProtocol::Grpc)]
pub protocol: OtlpProtocol,
}

/// Options for exporting metrics to Prometheus
#[derive(Debug, Clone, derive_builder::Builder)]
#[derive(Debug, Clone, bon::Builder)]
pub struct PrometheusExporterOptions {
pub socket_addr: SocketAddr,
// A map of tags to be applied to all metrics
Expand Down Expand Up @@ -205,7 +204,7 @@ pub enum OtlpProtocol {

impl Default for TelemetryOptions {
fn default() -> Self {
TelemetryOptionsBuilder::default().build().unwrap()
TelemetryOptions::builder().build()
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/telemetry/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,16 @@ impl WorkerHeartbeatMetrics {
}
}

#[derive(Debug, Clone, derive_builder::Builder)]
#[derive(Debug, Clone, bon::Builder)]
pub struct MetricParameters {
/// The name for the new metric/instrument
#[builder(setter(into))]
#[builder(into)]
pub name: Cow<'static, str>,
/// A description that will appear in metadata if the backend supports it
#[builder(setter(into), default = "\"\".into()")]
#[builder(into, default = Cow::Borrowed(""))]
pub description: Cow<'static, str>,
/// Unit information that will appear in metadata if the backend supports it
#[builder(setter(into), default = "\"\".into()")]
#[builder(into, default = Cow::Borrowed(""))]
pub unit: Cow<'static, str>,
}
impl From<&'static str> for MetricParameters {
Expand Down
Loading
Loading