Skip to content

Commit e867805

Browse files
Merge branch 'main' into semconv-readme
2 parents a5e9274 + 3d82438 commit e867805

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

common/lib/opentelemetry/common/utilities.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def timeout_timestamp
4242
Process.clock_gettime(Process::CLOCK_MONOTONIC)
4343
end
4444

45+
# Converts the provided timestamp to nanosecond integer
46+
#
47+
# @param timestamp [Time] the timestamp to convert, defaults to Time.now
48+
# @return [Integer]
49+
def time_in_nanoseconds(timestamp = Time.now)
50+
(timestamp.to_r * 1_000_000_000).to_i
51+
end
52+
4553
# Encodes a string in utf8
4654
#
4755
# @param [String] string The string to be utf8 encoded
@@ -129,7 +137,7 @@ def cleanse_url(url)
129137
# @param default The fallback value to return if the requested
130138
# env var(s) are not present
131139
#
132-
# @returns [String]
140+
# @return [String]
133141
def config_opt(*env_vars, default: nil)
134142
ENV.values_at(*env_vars).compact.fetch(0, default)
135143
end

common/test/opentelemetry/common/utilities_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ def shutdown(timeout: nil); end
3535
end
3636
end
3737

38+
describe '#time_in_nanoseconds' do
39+
it 'returns Time.now in nanoseconds when called without an argument' do
40+
Time.stub :now, Time.at(0) do
41+
expectation = (Time.now.to_r * 1_000_000_000).to_i
42+
assert_equal expectation, common_utils.time_in_nanoseconds
43+
end
44+
end
45+
46+
it 'can accept a timestamp to be converted' do
47+
time = Time.now
48+
expectation = (time.to_r * 1_000_000_000).to_i
49+
assert_equal expectation, common_utils.time_in_nanoseconds(time)
50+
end
51+
end
52+
3853
describe '#utf8_encode' do
3954
it 'happy path' do
4055
str = 'pristine ¬'.encode(Encoding::UTF_8)

metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(
3030

3131
# Initialize asynchronous-specific attributes
3232
@callback = callback
33-
@start_time = now_in_nano
33+
@start_time = OpenTelemetry::Common::Utilities.time_in_nanoseconds
3434
@timeout = timeout
3535
@attributes = attributes
3636
end
@@ -70,10 +70,6 @@ def invoke_callback(timeout, attributes)
7070
end
7171
end
7272
end
73-
74-
def now_in_nano
75-
(Time.now.to_r * 1_000_000_000).to_i
76-
end
7773
end
7874
end
7975
end

metrics_sdk/lib/opentelemetry/sdk/metrics/state/metric_store.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ module State
1515
class MetricStore
1616
def initialize
1717
@mutex = Mutex.new
18-
@epoch_start_time = now_in_nano
18+
@epoch_start_time = OpenTelemetry::Common::Utilities.time_in_nanoseconds
1919
@epoch_end_time = nil
2020
@metric_streams = []
2121
end
2222

2323
def collect
2424
@mutex.synchronize do
25-
@epoch_end_time = now_in_nano
25+
@epoch_end_time = OpenTelemetry::Common::Utilities.time_in_nanoseconds
2626
snapshot = @metric_streams.flat_map { |ms| ms.collect(@epoch_start_time, @epoch_end_time) }
2727
@epoch_start_time = @epoch_end_time
2828

@@ -36,12 +36,6 @@ def add_metric_stream(metric_stream)
3636
nil
3737
end
3838
end
39-
40-
private
41-
42-
def now_in_nano
43-
(Time.now.to_r * 1_000_000_000).to_i
44-
end
4539
end
4640
end
4741
end

semantic_conventions/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History: opentelemetry-semantic_conventions
22

3+
### v1.36.0 / 2025-09-16
4+
5+
* ADDED: Update to v1.36 in a non-breaking way
6+
37
### v1.11.0 / 2025-02-25
48

59
- ADDED: Support 3.1 Min Version

test_helpers/lib/opentelemetry/test_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def with_test_logger
4242
end
4343

4444
def exportable_timestamp(time = Time.now)
45-
(time.to_r * 1_000_000_000).to_i
45+
OpenTelemetry::Common::Utilities.time_in_nanoseconds(time)
4646
end
4747

4848
def with_env(new_env)

0 commit comments

Comments
 (0)