Skip to content

Commit be309d1

Browse files
authored
Support HTTP protocol for OTel metrics (#230)
Fixes #196
1 parent 5d692ab commit be309d1

File tree

7 files changed

+24
-10
lines changed

7 files changed

+24
-10
lines changed

temporalio/ext/src/runtime.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::{future::Future, sync::Arc};
1212
use temporal_sdk_core::telemetry::{build_otlp_metric_exporter, start_prometheus_metric_exporter};
1313
use temporal_sdk_core::{CoreRuntime, TokioRuntimeBuilder};
1414
use temporal_sdk_core_api::telemetry::{
15-
Logger, MetricTemporality, OtelCollectorOptionsBuilder, PrometheusExporterOptionsBuilder,
16-
TelemetryOptionsBuilder,
15+
Logger, MetricTemporality, OtelCollectorOptionsBuilder, OtlpProtocol,
16+
PrometheusExporterOptionsBuilder, TelemetryOptionsBuilder,
1717
};
1818
use tracing::error as log_error;
1919
use url::Url;
@@ -117,6 +117,9 @@ impl Runtime {
117117
if let Some(global_tags) = metrics.member::<Option<HashMap<String, String>>>(id!("global_tags"))? {
118118
opts_build.global_tags(global_tags);
119119
}
120+
if opentelemetry.member::<bool>(id!("http"))? {
121+
opts_build.protocol(OtlpProtocol::Http);
122+
}
120123
let opts = opts_build
121124
.build()
122125
.map_err(|err| error!("Invalid OpenTelemetry options: {}", err))?;

temporalio/lib/temporalio/activity/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def self._activity_definition_details
9090
{
9191
activity_name:,
9292
activity_executor: @activity_executor || :default,
93-
activity_cancel_raise: @activity_cancel_raise.nil? ? true : @activity_cancel_raise,
93+
activity_cancel_raise: @activity_cancel_raise.nil? || @activity_cancel_raise,
9494
activity_raw_args: @activity_raw_args.nil? ? false : @activity_raw_args
9595
}
9696
end

temporalio/lib/temporalio/internal/bridge/runtime.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Runtime
3737
:metric_periodicity, # Optional
3838
:metric_temporality_delta,
3939
:durations_as_seconds,
40+
:http,
4041
keyword_init: true
4142
)
4243

temporalio/lib/temporalio/runtime.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def _to_bridge
164164
:headers,
165165
:metric_periodicity,
166166
:metric_temporality,
167-
:durations_as_seconds
167+
:durations_as_seconds,
168+
:http
168169
)
169170

170171
# Options for exporting metrics to OpenTelemetry.
@@ -181,6 +182,8 @@ def _to_bridge
181182
# @!attribute durations_as_seconds
182183
# @return [Boolean] Whether to use float seconds instead of integer milliseconds for durations, default is
183184
# +false+.
185+
# @!attribute http
186+
# @return [Boolean] True if the protocol is HTTP, false if gRPC (the default).
184187
class OpenTelemetryMetricsOptions
185188
# OpenTelemetry metric temporality.
186189
module MetricTemporality
@@ -196,12 +199,14 @@ module MetricTemporality
196199
# @param metric_temporality [MetricTemporality] How frequently metrics should be exported.
197200
# @param durations_as_seconds [Boolean] Whether to use float seconds instead of integer milliseconds for
198201
# durations.
202+
# @param http [Boolean] True if the protocol is HTTP, false if gRPC (the default).
199203
def initialize(
200204
url:,
201205
headers: nil,
202206
metric_periodicity: nil,
203207
metric_temporality: MetricTemporality::CUMULATIVE,
204-
durations_as_seconds: false
208+
durations_as_seconds: false,
209+
http: false
205210
)
206211
super
207212
end
@@ -218,7 +223,8 @@ def _to_bridge
218223
when MetricTemporality::DELTA then true
219224
else raise 'Unrecognized metric temporality'
220225
end,
221-
durations_as_seconds:
226+
durations_as_seconds:,
227+
http:
222228
)
223229
end
224230
end

temporalio/lib/temporalio/workflow/future.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ module Workflow
88
# workflows.
99
class Future
1010
# Return a future that completes when any of the given futures complete. The returned future will return the first
11-
# completed futures value or raise the first completed futures exception. To not raise the exception, see
11+
# completed future's value or raise the first completed future's exception. To not raise the exception, see
1212
# {try_any_of}.
1313
#
1414
# @param futures [Array<Future<Object>>] Futures to wait for the first to complete.
1515
# @return [Future<Object>] Future that relays the first completed future's result/failure.
1616
def self.any_of(*futures)
1717
Future.new do
1818
Workflow.wait_condition(cancellation: nil) { futures.any?(&:done?) }
19-
# We know a future is always returned from find, the & just helps type checker
19+
# We know a future is always returned from find, the || just helps type checker
2020
(futures.find(&:done?) || raise).wait
2121
end
2222
end

temporalio/sig/temporalio/internal/bridge/runtime.rbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ module Temporalio
4848
attr_accessor metric_periodicity: Float?
4949
attr_accessor metric_temporality_delta: bool
5050
attr_accessor durations_as_seconds: bool
51+
attr_accessor http: bool
5152

5253
def initialize: (
5354
url: String,
5455
headers: Hash[String, String]?,
5556
metric_periodicity: Float?,
5657
metric_temporality_delta: bool,
57-
durations_as_seconds: bool
58+
durations_as_seconds: bool,
59+
http: bool
5860
) -> void
5961
end
6062

temporalio/sig/temporalio/runtime.rbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ module Temporalio
6767
attr_reader metric_periodicity: Float?
6868
attr_reader metric_temporality: MetricTemporality
6969
attr_reader durations_as_seconds: bool
70+
attr_reader http: bool
7071

7172
def initialize: (
7273
url: String,
7374
?headers: Hash[String, String]?,
7475
?metric_periodicity: Float?,
7576
?metric_temporality: MetricTemporality,
76-
?durations_as_seconds: bool
77+
?durations_as_seconds: bool,
78+
?http: bool
7779
) -> void
7880

7981
def _to_bridge: -> Internal::Bridge::Runtime::OpenTelemetryMetricsOptions

0 commit comments

Comments
 (0)