Skip to content

Support HTTP protocol for OTel metrics #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
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
7 changes: 5 additions & 2 deletions temporalio/ext/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::{future::Future, sync::Arc};
use temporal_sdk_core::telemetry::{build_otlp_metric_exporter, start_prometheus_metric_exporter};
use temporal_sdk_core::{CoreRuntime, TokioRuntimeBuilder};
use temporal_sdk_core_api::telemetry::{
Logger, MetricTemporality, OtelCollectorOptionsBuilder, PrometheusExporterOptionsBuilder,
TelemetryOptionsBuilder,
Logger, MetricTemporality, OtelCollectorOptionsBuilder, OtlpProtocol,
PrometheusExporterOptionsBuilder, TelemetryOptionsBuilder,
};
use tracing::error as log_error;
use url::Url;
Expand Down Expand Up @@ -117,6 +117,9 @@ impl Runtime {
if let Some(global_tags) = metrics.member::<Option<HashMap<String, String>>>(id!("global_tags"))? {
opts_build.global_tags(global_tags);
}
if opentelemetry.member::<bool>(id!("http"))? {
opts_build.protocol(OtlpProtocol::Http);
}
let opts = opts_build
.build()
.map_err(|err| error!("Invalid OpenTelemetry options: {}", err))?;
Expand Down
2 changes: 1 addition & 1 deletion temporalio/lib/temporalio/activity/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self._activity_definition_details
{
activity_name:,
activity_executor: @activity_executor || :default,
activity_cancel_raise: @activity_cancel_raise.nil? ? true : @activity_cancel_raise,
activity_cancel_raise: @activity_cancel_raise.nil? || @activity_cancel_raise,
activity_raw_args: @activity_raw_args.nil? ? false : @activity_raw_args
}
end
Expand Down
1 change: 1 addition & 0 deletions temporalio/lib/temporalio/internal/bridge/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Runtime
:metric_periodicity, # Optional
:metric_temporality_delta,
:durations_as_seconds,
:http,
keyword_init: true
)

Expand Down
12 changes: 9 additions & 3 deletions temporalio/lib/temporalio/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def _to_bridge
:headers,
:metric_periodicity,
:metric_temporality,
:durations_as_seconds
:durations_as_seconds,
:http
)

# Options for exporting metrics to OpenTelemetry.
Expand All @@ -181,6 +182,8 @@ def _to_bridge
# @!attribute durations_as_seconds
# @return [Boolean] Whether to use float seconds instead of integer milliseconds for durations, default is
# +false+.
# @!attribute http
# @return [Boolean] True if the protocol is HTTP, false if gRPC (the default).
class OpenTelemetryMetricsOptions
# OpenTelemetry metric temporality.
module MetricTemporality
Expand All @@ -196,12 +199,14 @@ module MetricTemporality
# @param metric_temporality [MetricTemporality] How frequently metrics should be exported.
# @param durations_as_seconds [Boolean] Whether to use float seconds instead of integer milliseconds for
# durations.
# @param http [Boolean] True if the protocol is HTTP, false if gRPC (the default).
def initialize(
url:,
headers: nil,
metric_periodicity: nil,
metric_temporality: MetricTemporality::CUMULATIVE,
durations_as_seconds: false
durations_as_seconds: false,
http: false
)
super
end
Expand All @@ -218,7 +223,8 @@ def _to_bridge
when MetricTemporality::DELTA then true
else raise 'Unrecognized metric temporality'
end,
durations_as_seconds:
durations_as_seconds:,
http:
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions temporalio/lib/temporalio/workflow/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module Workflow
# workflows.
class Future
# Return a future that completes when any of the given futures complete. The returned future will return the first
# completed futures value or raise the first completed futures exception. To not raise the exception, see
# completed future's value or raise the first completed future's exception. To not raise the exception, see
# {try_any_of}.
#
# @param futures [Array<Future<Object>>] Futures to wait for the first to complete.
# @return [Future<Object>] Future that relays the first completed future's result/failure.
def self.any_of(*futures)
Future.new do
Workflow.wait_condition(cancellation: nil) { futures.any?(&:done?) }
# We know a future is always returned from find, the & just helps type checker
# We know a future is always returned from find, the || just helps type checker
(futures.find(&:done?) || raise).wait
end
end
Expand Down
4 changes: 3 additions & 1 deletion temporalio/sig/temporalio/internal/bridge/runtime.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ module Temporalio
attr_accessor metric_periodicity: Float?
attr_accessor metric_temporality_delta: bool
attr_accessor durations_as_seconds: bool
attr_accessor http: bool

def initialize: (
url: String,
headers: Hash[String, String]?,
metric_periodicity: Float?,
metric_temporality_delta: bool,
durations_as_seconds: bool
durations_as_seconds: bool,
http: bool
) -> void
end

Expand Down
4 changes: 3 additions & 1 deletion temporalio/sig/temporalio/runtime.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ module Temporalio
attr_reader metric_periodicity: Float?
attr_reader metric_temporality: MetricTemporality
attr_reader durations_as_seconds: bool
attr_reader http: bool

def initialize: (
url: String,
?headers: Hash[String, String]?,
?metric_periodicity: Float?,
?metric_temporality: MetricTemporality,
?durations_as_seconds: bool
?durations_as_seconds: bool,
?http: bool
) -> void

def _to_bridge: -> Internal::Bridge::Runtime::OpenTelemetryMetricsOptions
Expand Down
Loading