Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jun 6, 2024
1 parent 4727e12 commit bb02719
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu
**Available configuration options:**

| Setting | Env Var | Type | Default | Description |
| ------------------------------------------------------ | ------------------------------------------------------- | ------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|--------------------------------------------------------|---------------------------------------------------------|---------------------------------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Global** | | | | |
| `agent.host` | `DD_AGENT_HOST` | `String` | `127.0.0.1` | Hostname of Agent to where trace data will be sent. |
| `agent.port` | `DD_TRACE_AGENT_PORT` | `Integer` | `8126` | Port of Agent host to where trace data will be sent. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. |
Expand All @@ -1935,6 +1935,7 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu
| `tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `Array` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. |
| `tracing.enabled` | `DD_TRACE_ENABLED` | `Bool` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. |
| `tracing.header_tags` | `DD_TRACE_HEADER_TAGS` | `Array` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. |
| `tracing.inherit_parent_service` | | `Bool` | `false` | Inherit the parent span's service name when creating a new child span. |
| `tracing.instrument(<integration-name>, <options...>)` | | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. |
| `tracing.log_injection` | `DD_LOGS_INJECTION` | `Bool` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. |
| `tracing.partial_flush.enabled` | | `Bool` | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. |
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/tracing/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def self.extended(base)
# Whether spans inherit their parent's service name, when span `service` is not explicitly set.
# If `true`, the spans will use the service name from its parent span.
# If `false`, the spans will use the global service name (`c.service`).
#
# DEV3.0: All other tracer languages inherit the parent's service by default.
# DEV3.0: This option should be set to `true` by default in the next major version,
# DEV3.0: with a removal deprecation warning, then removed in 4.0.
#
# @default `false`
# @return [Boolean]
option :inherit_parent_service do |o|
Expand Down
8 changes: 6 additions & 2 deletions lib/datadog/tracing/span_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ def message
# it has been finished.
attr_reader \
:events,
:span
:span,
:inherit_parent_service

# Stored only for `service_entry` calculation.
# Use `parent_id` for the effective parent span id.
Expand All @@ -442,8 +443,11 @@ def message
# mutation by reference; when this span is returned,
# we don't want this SpanOperation to modify it further.
def build_span
# Use parent service if no service is set and @inherit_parent_service is set
service = self.service || (@parent&.service if @inherit_parent_service)

service_entry = @parent.nil? || (service && @parent.service != service)

Span.new(
@name,
duration: duration,
Expand All @@ -459,7 +463,7 @@ def build_span
type: @type,
trace_id: @trace_id,
links: @links,
service_entry: @parent.nil? || (service && @parent.service != service)
service_entry: service_entry
)
end

Expand Down
49 changes: 45 additions & 4 deletions spec/datadog/tracing/span_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
end

context 'identifying service_entry_span' do
context 'when service of root and child are `nil`' do
context 'when service of parent and child are `nil`' do
it do
root_span_op = described_class.new('root')
child_span_op = described_class.new('child_1')
Expand All @@ -482,7 +482,7 @@
end
end

context 'when service of root and child are identical' do
context 'when service of parent and child are identical' do
it do
root_span_op = described_class.new('root', service: 'root_service')
child_span_op = described_class.new('child_1', service: root_span_op.service)
Expand All @@ -502,7 +502,7 @@
end
end

context 'when service of root and child are different' do
context 'when service of parent and child are different' do
it do
root_span_op = described_class.new('root')
child_span_op = described_class.new('child_1', service: 'child_service')
Expand All @@ -522,7 +522,7 @@
end
end

context 'when service of root and child are different, overriden within the measure block' do
context 'when service of parent and child are different, overriden within the measure block' do
it do
root_span_op = described_class.new('root')
child_span_op = described_class.new('child_1')
Expand Down Expand Up @@ -806,6 +806,47 @@
expect(span_op.finish).to be(original_span)
end
end

context 'with a parent span' do
let(:parent_span) { described_class.new('parent', service: 'parent_service') }

before do
span_op.send(:parent=, parent_span)
end

context 'with no service set' do
it 'span has no service' do
expect(finish.service).to eq(nil)
end
end

context 'with a service set' do
let(:parent_service) { 'parent_service' }

context 'without inherit_parent_service set' do
it 'span does not inherit the service' do
expect(finish.service).to eq(nil)
end
end

context 'with inherit_parent_service set' do
let(:options) { { inherit_parent_service: true } }

it 'span inherits the service' do
expect(finish.service).to eq('parent_service')
end
end

context 'and child span service set' do
let(:options) { { service: 'child_service' } }

it 'span does not inherit the service' do
expect(finish.service).to eq('child_service')
end
end
end

end
end

describe '#finished?' do
Expand Down
32 changes: 30 additions & 2 deletions spec/datadog/tracing/trace_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
sampled: sampled,
sampling_priority: sampling_priority,
service: service,
default_service: default_service,
profiling_enabled: profiling_enabled,
tags: tags,
metrics: metrics,
trace_state: trace_state,
trace_state_unknown_fields: trace_state_unknown_fields,
remote_parent: remote_parent,
inherit_parent_service: inherit_parent_service
}
end

Expand All @@ -53,6 +55,7 @@
let(:sampled) { true }
let(:sampling_priority) { Datadog::Tracing::Sampling::Ext::Priority::USER_KEEP }
let(:service) { 'billing-api' }
let(:default_service) { 'default-service' }
let(:profiling_enabled) { 'profiling_enabled' }
let(:tags) { { 'foo' => 'bar' }.merge(distributed_tags) }
let(:metrics) { { 'baz' => 42.0 } }
Expand All @@ -61,6 +64,7 @@

let(:distributed_tags) { { '_dd.p.test' => 'value' } }
let(:remote_parent) { true }
let(:inherit_parent_service) { double('inherit_parent_service') }
end

shared_examples 'a span with default events' do
Expand Down Expand Up @@ -236,9 +240,27 @@

context ':service' do
subject(:options) { { service: service } }
let(:service) { 'billing-worker' }

it { expect(trace_op.service).to eq(service) }
context 'with no service set' do
let(:service) { nil }
it { expect(trace_op.service).to eq('default-service') }
end

context 'with a root span with service set' do
let(:service) { nil }

before { trace_op.measure('root', service: 'root-service') {} }

it { expect(trace_op.service).to eq('root-service') }

context 'with a trace service set' do
let(:service) { 'service' }
it { expect(trace_op.service).to eq('service') }
end
end


include_context 'trace attributes'
end

context ':tags' do
Expand Down Expand Up @@ -1221,6 +1243,12 @@
it { expect(span.send(:meta)).to include('foo' => 'bar') }
end
end

context ':inherit_parent_service' do
include_context 'trace attributes'

it { expect(span.send(:inherit_parent_service)).to eq(inherit_parent_service) }
end
end

context 'when the trace' do
Expand Down
13 changes: 13 additions & 0 deletions spec/datadog/tracing/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,22 @@

it 'sets the span name from the name argument' do
trace
TraceOperation
expect(span.name).to eq(name)
end

it 'passes options to the trace operation' do
expect(Datadog::Profiling).to receive(:enabled?).and_return(true)

expect(Datadog::Tracing::TraceOperation).to receive(:new).with(hostname: nil,
profiling_enabled: true,
remote_parent: false,
default_service: tracer.default_service,
inherit_parent_service: false).and_call_original

trace
end

context 'with diagnostics debug enabled' do
include_context 'tracer logging'

Expand Down

0 comments on commit bb02719

Please sign in to comment.