Skip to content

Commit 8f44895

Browse files
miryfbogsany
andauthored
refactor: Remove duplication logic in start_span (#1281)
* refactor: Remove duplication logic in start_span There are 2 places where checked mostly the same: parent span id and trace id base on parent_span. Because there is no other places in gems, that use method `internal_start_span`, leave that logic there and removed unused attributes. * Remove extract to constant default name * Applied proposal from github comments * Changed variable name to fit param name * Remove extra blank line Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent 3ec7d8a commit 8f44895

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

sdk/lib/opentelemetry/sdk/trace/tracer.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kin
2929

3030
def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
3131
name ||= 'empty'
32-
32+
kind ||= :internal
3333
with_parent ||= Context.current
34-
parent_span = OpenTelemetry::Trace.current_span(with_parent)
35-
parent_span_context = OpenTelemetry::Trace.current_span(with_parent).context
36-
if parent_span_context.valid?
37-
parent_span_id = parent_span_context.span_id
38-
trace_id = parent_span_context.trace_id
39-
end
4034

41-
@tracer_provider.internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent, parent_span, @instrumentation_library)
35+
@tracer_provider.internal_create_span(name, kind, attributes, links, start_timestamp, with_parent, @instrumentation_library)
4236
end
4337
end
4438
end

sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ def add_span_processor(span_processor)
126126
end
127127

128128
# @api private
129-
def internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context, parent_span, instrumentation_library) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
129+
def internal_create_span(name, kind, attributes, links, start_timestamp, parent_context, instrumentation_library) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
130+
parent_span = OpenTelemetry::Trace.current_span(parent_context)
130131
parent_span_context = parent_span.context
132+
131133
if parent_span_context.valid?
132134
parent_span_id = parent_span_context.span_id
133135
trace_id = parent_span_context.trace_id
134136
end
135-
name ||= 'empty'
137+
136138
trace_id ||= @id_generator.generate_trace_id
137-
kind ||= :internal
138139
result = @sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
139140
span_id = @id_generator.generate_span_id
140141
if result.recording? && !@stopped

0 commit comments

Comments
 (0)