Skip to content

Commit cd83132

Browse files
committed
Increase type checking coverage
1 parent 08743d9 commit cd83132

File tree

22 files changed

+400
-151
lines changed

22 files changed

+400
-151
lines changed

Steepfile

+5-26
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,12 @@ target :datadog do
127127
ignore 'lib/datadog/tracing/sampling/rule.rb'
128128
ignore 'lib/datadog/tracing/sampling/rule_sampler.rb'
129129
ignore 'lib/datadog/tracing/sampling/span/rule.rb'
130-
ignore 'lib/datadog/tracing/span.rb'
131-
ignore 'lib/datadog/tracing/span_operation.rb'
132130
ignore 'lib/datadog/tracing/sync_writer.rb'
133131
ignore 'lib/datadog/tracing/trace_operation.rb'
134132
ignore 'lib/datadog/tracing/tracer.rb'
135133
ignore 'lib/datadog/tracing/transport/http.rb'
136134
ignore 'lib/datadog/tracing/transport/http/api.rb'
137-
ignore 'lib/datadog/tracing/transport/http/builder.rb'
138135
ignore 'lib/datadog/tracing/transport/http/client.rb'
139-
ignore 'lib/datadog/tracing/transport/http/statistics.rb'
140136
ignore 'lib/datadog/tracing/transport/http/traces.rb'
141137
ignore 'lib/datadog/tracing/transport/io/client.rb'
142138
ignore 'lib/datadog/tracing/transport/io/traces.rb'
@@ -161,30 +157,13 @@ target :datadog do
161157
library 'digest'
162158
library 'zlib'
163159
library 'time'
160+
library 'pp'
164161

162+
# Load all dependency signatures from the `vendor/rbs` directory
165163
repo_path 'vendor/rbs'
166-
library 'cucumber'
167-
library 'jruby'
168-
library 'gem'
169-
library 'rails'
170-
library 'spring'
171-
library 'sinatra'
172-
library 'google-protobuf'
173-
library 'protobuf-cucumber'
174-
library 'minitest'
175-
library 'mysql2'
176-
library 'mysql2-aurora'
177-
library 'concurrent-ruby'
178-
library 'faraday'
179-
library 'seahorse'
180-
library 'excon'
181-
library 'grpc'
182-
library 'delayed_job'
183-
library 'opentelemetry-api'
184-
library 'passenger'
185-
library 'webmock'
186-
library 'graphql'
187-
library 'datadog-ci'
164+
Dir.children('vendor/rbs').each do |vendor_gem|
165+
library vendor_gem
166+
end
188167

189168
# ffi version 1.17 was shipped with invalid rbs types:
190169
# https://github.com/ffi/ffi/issues/1107

lib/datadog/tracing/span.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def stopped?
112112

113113
def duration
114114
return @duration if @duration
115-
return @end_time - @start_time if @start_time && @end_time
115+
116+
start_time = @start_time
117+
end_time = @end_time
118+
end_time - start_time if start_time && end_time
116119
end
117120

118121
def set_error(e)
@@ -135,6 +138,8 @@ def to_s
135138
# TODO: Change this to reflect attributes when serialization
136139
# isn't handled by this method.
137140
def to_hash
141+
@meta['events'] = @events.map(&:to_hash).to_json unless @events.empty?
142+
138143
h = {
139144
error: @status,
140145
meta: @meta,
@@ -154,8 +159,6 @@ def to_hash
154159
h[:duration] = duration_nano
155160
end
156161

157-
h[:meta]['events'] = @events.map(&:to_hash).to_json unless @events.empty?
158-
159162
h
160163
end
161164

@@ -196,12 +199,17 @@ def pretty_print(q)
196199
# Used for serialization
197200
# @return [Integer] in nanoseconds since Epoch
198201
def start_time_nano
199-
@start_time.to_i * 1000000000 + @start_time.nsec
202+
return unless (start_time = @start_time)
203+
204+
start_time.to_i * 1000000000 + start_time.nsec
200205
end
201206

202207
# Used for serialization
203208
# @return [Integer] in nanoseconds since Epoch
204209
def duration_nano
210+
duration = self.duration
211+
return unless duration
212+
205213
(duration * 1e9).to_i
206214
end
207215

lib/datadog/tracing/span_operation.rb

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def start(start_time = nil)
199199
end
200200

201201
# Mark the span stopped at the current time
202+
#
203+
# steep:ignore:start
204+
# Steep issue fixed in https://github.com/soutaro/steep/pull/1467
202205
def stop(stop_time = nil)
203206
# A span should not be stopped twice. Note that this is not thread-safe,
204207
# stop is called from multiple threads, a given span might be stopped
@@ -221,6 +224,7 @@ def stop(stop_time = nil)
221224

222225
self
223226
end
227+
# steep:ignore:end
224228

225229
# Return whether the duration is started or not
226230
def started?

sig/datadog/core/configuration.rbs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Datadog
22
module Core
33
module Configuration
4+
def health_metrics: -> Diagnostics::Health::Metrics
5+
46
def tracer: () -> Datadog::Tracing::Tracer
57

68
def logger: () -> Datadog::Core::Logger

sig/datadog/core/diagnostics/health.rbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Datadog
33
module Diagnostics
44
module Health
55
class Metrics < Core::Metrics::Client
6-
extend Tracing::Diagnostics::Health::Metrics
6+
include Tracing::Diagnostics::Health::Metrics
77
end
88
end
99
end

sig/datadog/tracing.rbs

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ module Datadog
44

55
def self.active_trace: -> TraceSegment?
66
def self.active_span: -> SpanOperation?
7+
8+
type on_error = ^(SpanOperation span_op, Exception error) -> void
79
end
810
end

sig/datadog/tracing/contrib/resque/resque_job.rbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Datadog
1818

1919
def forked?: () -> untyped
2020

21-
def span_options: () -> { service: untyped, on_error: untyped }
21+
def span_options: () -> { service: untyped, on_error: on_error }
2222

2323
def datadog_configuration: () -> untyped
2424
end

sig/datadog/tracing/diagnostics/health.rbs

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@ module Datadog
33
module Diagnostics
44
module Health
55
module Metrics
6-
def self.extended: (untyped base) -> untyped
6+
def api_errors: (untyped ?value) ?{ (untyped) -> untyped } -> void
7+
def api_requests: (untyped ?value) ?{ (untyped) -> untyped } -> void
8+
def api_responses: (untyped ?value) ?{ (untyped) -> untyped } -> void
9+
def error_context_overflow: (untyped ?value) ?{ (untyped) -> untyped } -> void
10+
def error_instrumentation_patch: (untyped ?value) ?{ (untyped) -> untyped } -> void
11+
def error_span_finish: (untyped ?value) ?{ (untyped) -> untyped } -> void
12+
def error_unfinished_spans: (untyped ?value) ?{ (untyped) -> untyped } -> void
13+
def instrumentation_patched: (untyped ?value) ?{ (untyped) -> untyped } -> void
14+
def queue_accepted: (untyped ?value) ?{ (untyped) -> untyped } -> void
15+
def queue_accepted_lengths: (untyped ?value) ?{ (untyped) -> untyped } -> void
16+
def queue_dropped: (untyped ?value) ?{ (untyped) -> untyped } -> void
17+
def traces_filtered: (untyped ?value) ?{ (untyped) -> untyped } -> void
18+
def transport_trace_too_large: (untyped ?value) ?{ (untyped) -> untyped } -> void
19+
def transport_chunked: (untyped ?value) ?{ (untyped) -> untyped } -> void
20+
def writer_cpu_time: (untyped ?value) ?{ (untyped) -> untyped } -> void
21+
def queue_length: (untyped ?value) ?{ (untyped) -> untyped } -> void
22+
def queue_max_length: (untyped ?value) ?{ (untyped) -> untyped } -> void
23+
def queue_spans: (untyped ?value) ?{ (untyped) -> untyped } -> void
24+
def sampling_service_cache_length: (untyped ?value) ?{ (untyped) -> untyped } -> void
725
end
826
end
927
end

sig/datadog/tracing/metadata.rbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module Datadog
22
module Tracing
33
module Metadata
4-
def self.included: (untyped base) -> untyped
4+
include Metadata::Tagging
5+
include Metadata::Errors
6+
prepend Metadata::Analytics
57
end
68
end
79
end

sig/datadog/tracing/span.rbs

+52-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
module Datadog
22
module Tracing
33
class Span
4-
attr_accessor span_id: Integer
4+
include Metadata
55

6-
def set_tag: (String key, ?untyped? value) -> void
6+
attr_accessor end_time: (Time | nil)
7+
attr_accessor id: Integer
8+
attr_accessor meta: Hash[String, String]
9+
attr_accessor metrics: Hash[String, Float]
10+
attr_accessor name: String
11+
attr_accessor parent_id: Integer
12+
attr_accessor resource: String
13+
attr_accessor service: (String | nil)
14+
attr_accessor links: Array[untyped]
15+
attr_accessor events: Array[untyped]
16+
attr_accessor type: (String | nil)
17+
attr_accessor start_time: (Time | nil)
18+
attr_accessor status: Integer
19+
attr_accessor trace_id: Integer
20+
attr_writer duration: (Float | nil)
21+
22+
def initialize: (
23+
String name,
24+
?duration: (Float | nil),
25+
?end_time: (Time | nil),
26+
?id: (Integer | nil),
27+
?meta: (Hash[String, String] | nil),
28+
?metrics: (Hash[String, Float] | nil),
29+
?parent_id: Integer,
30+
?resource: String,
31+
?service: (String | nil),
32+
?start_time: (Time | nil),
33+
?status: Integer,
34+
?type: (String | nil),
35+
?trace_id: (Integer | nil),
36+
?service_entry: (bool | nil),
37+
?links: (Array[untyped] | nil),
38+
?events: (Array[untyped] | nil)
39+
) -> void
40+
41+
def started?: -> bool
42+
def stopped?: -> bool
43+
def duration: -> (Float | nil)
44+
def set_error: (Exception e) -> void
45+
def ==: (Span other) -> bool
46+
def to_s: -> String
47+
def to_hash: -> Hash[Symbol, untyped]
48+
def pretty_print: (PP q) -> void
49+
50+
private
51+
52+
def duration_nano: -> Integer?
53+
54+
def service_entry?: -> bool
55+
56+
def start_time_nano: -> Integer?
757
end
858
end
959
end
10-

sig/datadog/tracing/span_operation.rbs

+21-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Datadog
1010

1111
attr_reader span_events: untyped
1212

13-
attr_reader end_time: untyped
13+
attr_reader end_time: ::Time
1414

1515
attr_reader id: untyped
1616

@@ -22,15 +22,29 @@ module Datadog
2222

2323
attr_reader service: untyped
2424

25-
attr_reader start_time: untyped
25+
attr_reader start_time: ::Time
2626

2727
attr_reader trace_id: untyped
2828

2929
attr_reader type: untyped
3030

3131
attr_accessor status: untyped
3232

33-
def initialize: (untyped name, ?child_of: untyped?, ?events: untyped?, ?on_error: untyped?, ?parent_id: ::Integer, ?resource: untyped, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?trace_id: untyped?, ?type: untyped?, ?links: untyped?, ?span_events: untyped?) -> void
33+
def initialize: (
34+
String name,
35+
?events: Events,
36+
?on_error: on_error,
37+
?parent_id: Integer,
38+
?resource: String,
39+
?service: (String | nil),
40+
?start_time: (Time | nil),
41+
?tags: (Hash[String, (String|Numeric)] | nil),
42+
?trace_id: (Integer | nil),
43+
?type: (String | nil),
44+
?links: (Array[SpanLink] | nil),
45+
?span_events: (Array[SpanEvent] | nil),
46+
?id: (Integer | nil)
47+
) -> void
3448

3549
def name=: (untyped name) -> untyped
3650

@@ -44,7 +58,7 @@ module Datadog
4458

4559
def start: (?untyped? start_time) -> self
4660

47-
def stop: (?untyped? stop_time) -> (nil | self)
61+
def stop: (?untyped? stop_time) -> self?
4862

4963
def started?: () -> untyped
5064

@@ -71,17 +85,17 @@ module Datadog
7185
class Events
7286
include Tracing::Events
7387

74-
DEFAULT_ON_ERROR: untyped
88+
DEFAULT_ON_ERROR: on_error
7589

7690
attr_reader after_finish: untyped
7791

7892
attr_reader after_stop: untyped
7993

8094
attr_reader before_start: untyped
8195

82-
def initialize: (?on_error: untyped?) -> void
96+
def initialize: (?on_error: on_error) -> void
8397

84-
def on_error: () -> untyped
98+
def on_error: () -> OnError
8599

86100
class AfterFinish < Tracing::Event
87101
def initialize: () -> void

sig/datadog/tracing/trace_operation.rbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module Datadog
3535
def resource: () -> untyped
3636
def resource_override?: () -> bool
3737
def service: () -> untyped
38-
def measure: (untyped op_name, ?events: untyped?, ?on_error: untyped?, ?resource: untyped?, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?type: untyped?) { (untyped, untyped) -> untyped } -> untyped
39-
def build_span: (untyped op_name, ?events: untyped?, ?on_error: untyped?, ?resource: untyped?, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?type: untyped?) -> untyped
38+
def measure: (untyped op_name, ?events: untyped?, ?on_error: on_error, ?resource: untyped?, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?type: untyped?) { (untyped, untyped) -> untyped } -> untyped
39+
def build_span: (untyped op_name, ?events: untyped?, ?on_error: on_error, ?resource: untyped?, ?service: untyped?, ?start_time: untyped?, ?tags: untyped?, ?type: untyped?) -> untyped
4040
def flush!: () { (untyped) -> untyped } -> untyped
4141
def to_digest: () -> untyped
4242
def fork_clone: () -> untyped

sig/datadog/tracing/transport/http/api.rbs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module Datadog
2-
module Transport
3-
module HTTP
4-
module API
5-
V4: "v0.4"
2+
module Tracing
3+
module Transport
4+
module HTTP
5+
module API
6+
V4: "v0.4"
67

7-
V3: "v0.3"
8+
V3: "v0.3"
89

9-
def self?.defaults: () -> untyped
10+
def self?.defaults: () -> untyped
11+
end
1012
end
1113
end
1214
end

0 commit comments

Comments
 (0)