Skip to content

Commit

Permalink
correct my lambda syntax usage
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 25, 2024
1 parent 3afa46f commit 6e4db87
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu
| `service` | `DD_SERVICE` | `String` | _Ruby filename_ | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. |
| `tags` | `DD_TAGS` | `Hash` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. |
| `time_now_provider` | | `Proc` | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. |
| `get_time_provider` | | `Proc` | `lambda { \|unit = :float_second\| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }` | Changes how monotonic time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. |
| `get_time_provider` | | `Proc` | `->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }` | Changes how monotonic time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. |
| `version` | `DD_VERSION` | `String` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. |
| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `Bool` | `true` | Allows you to enable sending telemetry data to Datadog. Can be disabled, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). |
| **Tracing** | | | | |
Expand Down Expand Up @@ -2668,7 +2668,7 @@ configure the following:
```ruby
Datadog.configure do |c|
# For Timecop, for example, `::Process.clock_gettime_without_mock` allows the tracer to use the real monotonic time.
c.get_time_provider = lambda { |unit = :float_second| ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }
c.get_time_provider = ->(unit = :float_second) { ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }
end
```

Expand Down
9 changes: 5 additions & 4 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,11 @@ def initialize(*_)
# When testing, it can be helpful to use a different monotonic clock time provider.
#
# For [Timecop](https://rubygems.org/gems/timecop), for example,
# `lambda { |unit = :float_second| ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }`
# allows Datadog features to use the real monotonic time when time is frozen with `Timecop.mock_process_clock = true`.
# `->(unit = :float_second) { ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }`
# allows Datadog features to use the real monotonic time when time is frozen with
# `Timecop.mock_process_clock = true`.
#
# @default `lambda { |unit = :float_second| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit)}`
# @default `->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit)}`
# @return [Proc<Numeric>]
option :get_time_provider do |o|
o.default_proc { |unit = :float_second| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }
Expand All @@ -674,7 +675,7 @@ def initialize(*_)
end

o.resetter do |_value|
lambda { |unit = :float_second| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit)}.tap do |default|
->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }.tap do |default|
Core::Utils::Time.get_time_provider = default
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/core/utils/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ def now_provider=(block)
define_singleton_method(:now, &block)
end


# Overrides the implementation of `#get_time
# with the provided callable.
#
# Overriding the method `#get_time` instead of
# indirectly calling `block` removes
# one level of method call overhead.
#
# @param block [Proc] block that accepts unit and returns timestamp in the requested unit, since some unspecified starting point
# @param block [Proc] block that accepts unit and returns timestamp in the requested unit
def get_time_provider=(block)
define_singleton_method(:get_time, &block)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
new_milliseconds = get_time_new_milliseconds # Capture for closure
new_seconds = get_time_new_seconds # Capture for closure

lambda { |unit| if unit == :float_millisecond then new_milliseconds else new_seconds end}
->(unit) { unit == :float_millisecond ? new_milliseconds : new_seconds }
end

context 'when default' do
Expand All @@ -1422,14 +1422,14 @@
context 'when given a value' do
before { set_get_time_provider }

context "when unit is :float_second" do
context 'when unit is :float_second' do
it 'returns the provided time in float seconds' do
expect(settings.get_time_provider.call(unit)).to eq(get_time_new_seconds)
expect(Datadog::Core::Utils::Time.get_time(unit)).to eq(get_time_new_seconds)
end
end

context "when unit is :float_millisecond" do
context 'when unit is :float_millisecond' do
let(:unit) { :float_millisecond }

it 'returns the provided time in float milliseconds' do
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/span_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@
clock_time = clock_increment
Datadog.configure do |c|
# Use a custom clock provider that increments by `clock_increment`
c.get_time_provider = lambda { |_unit = :float_second| clock_time += incr }
c.get_time_provider = ->(_unit = :float_second) { clock_time += incr }
end
end

Expand Down

0 comments on commit 6e4db87

Please sign in to comment.