From 576eaa512684b0f0b93dede0e7a10d248bf691a6 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 5 Jun 2024 12:36:36 -0700 Subject: [PATCH] wip Signed-off-by: Marco Costa --- lib/datadog/tracing/span_operation.rb | 2 +- lib/datadog/tracing/tracer.rb | 7 +++++-- spec/datadog/tracing/tracer_spec.rb | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/datadog/tracing/span_operation.rb b/lib/datadog/tracing/span_operation.rb index cb3edde7862..88a38c293d0 100644 --- a/lib/datadog/tracing/span_operation.rb +++ b/lib/datadog/tracing/span_operation.rb @@ -448,7 +448,7 @@ def build_span metrics: Core::Utils::SafeDup.frozen_or_dup(metrics), parent_id: @parent_id, resource: @resource, - service: @service, + service: @service || @parent&.service, start_time: @start_time, status: @status, type: @type, diff --git a/lib/datadog/tracing/tracer.rb b/lib/datadog/tracing/tracer.rb index b9f076bb346..b5d3398cc29 100644 --- a/lib/datadog/tracing/tracer.rb +++ b/lib/datadog/tracing/tracer.rb @@ -321,6 +321,7 @@ def build_trace(digest = nil) id: digest.trace_id, origin: digest.trace_origin, parent_span_id: digest.span_id, + service: @default_service, sampling_priority: digest.trace_sampling_priority, # Distributed tags are just regular trace tags with special meaning to Datadog tags: digest.trace_distributed_tags, @@ -332,6 +333,7 @@ def build_trace(digest = nil) TraceOperation.new( hostname: hostname, profiling_enabled: profiling_enabled, + service: @default_service, remote_parent: false, ) end @@ -341,12 +343,13 @@ def bind_trace_events!(trace_op) events = trace_op.send(:events) events.span_before_start.subscribe do |event_span_op, event_trace_op| - event_trace_op.service ||= @default_service - event_span_op.service ||= @default_service sample_trace(event_trace_op) if event_span_op && event_span_op.parent_id == 0 end events.span_finished.subscribe do |event_span, event_trace_op| + # Fallback in case the service was never set + event_span.service ||= @default_service + sample_span(event_trace_op, event_span) flush_trace(event_trace_op) end diff --git a/spec/datadog/tracing/tracer_spec.rb b/spec/datadog/tracing/tracer_spec.rb index cbed78e91f5..79ae0e09f05 100644 --- a/spec/datadog/tracing/tracer_spec.rb +++ b/spec/datadog/tracing/tracer_spec.rb @@ -275,7 +275,7 @@ expect(child1.parent_id).to be(parent.id) expect(child1.name).to eq('child1') - expect(child1.service).to eq(tracer.default_service) + expect(child1.service).to eq('service-parent') expect(child1.get_tag('tag')).to eq('tag_1') expect(child2.parent_id).to be(parent.id)