Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ client.query("SELECT * FROM users WHERE group='x'")
| `enabled` | `DD_TRACE_MYSQL2_ENABLED` | `Bool` | Whether the integration should create spans. | `true` |
| `service_name` | `DD_TRACE_MYSQL2_SERVICE_NAME` | `String` | Name of application running the `mysql2` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `mysql2` |
| `peer_service` | `DD_TRACE_MYSQL2_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `full`). <br /><br />**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `dynamic_service` \| `full`). <br /><br />**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` |
| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` |
| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |

Expand Down Expand Up @@ -1407,7 +1407,7 @@ end
| `enabled` | `DD_TRACE_PG_ENABLED` | `true` | Whether the integration should create spans. | `true` |
| `service_name` | `DD_TRACE_PG_SERVICE_NAME` | `String` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `pg` |
| `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `full`). <br /><br />**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `dynamic_service` \| `full`). <br /><br />**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` |
| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` |
| `on_error` | | `Proc` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |

Expand Down Expand Up @@ -2135,7 +2135,7 @@ client.query("SELECT * FROM users WHERE group='x'")
| `enabled` | `DD_TRACE_TRILOGY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` |
| `service_name` | `DD_TRACE_TRILOGY_SERVICE_NAME` | `String` | Name of application running the `trilogy` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `trilogy` |
| `peer_service` | `DD_TRACE_TRILOGY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `full`). <br /><br />**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` |
| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring. <br />(example: `disabled` \| `service`\| `dynamic_service` \| `full`). <br /><br />**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` |
| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` |
| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |

Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module Ext
# The `service` mode propagates service configuration
SERVICE = 'service'

# The `dynamic_service` mode propagates service configuration + DBM service hash
DYNAMIC_SERVICE = 'dynamic_service'

# The `full` mode propagates service configuration + trace context
FULL = 'full'

Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def enabled?
end

def service?
mode == Ext::SERVICE
mode == Ext::SERVICE || mode == Ext::DYNAMIC_SERVICE
end

def full?
Expand All @@ -26,7 +26,7 @@ def append?
end

def inject_sql_basehash?
inject_sql_basehash
inject_sql_basehash || mode == Ext::DYNAMIC_SERVICE
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Datadog
KEY_HOSTNAME: string
KEY_PEER_SERVICE: string
SERVICE: "service"
DYNAMIC_SERVICE: "dynamic_service"
FULL: "full"
TAG_DBM_TRACE_INJECTED: "_dd.dbm_trace_injected"
TAG_PROPAGATED_HASH: "_dd.propagated_hash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[
['disabled', false],
['service', true],
['dynamic_service', true],
['full', true],
['undefined', false]
].each do |string, result|
Expand All @@ -22,6 +23,7 @@
[
['disabled', false],
['service', true],
['dynamic_service', true],
['full', false],
['undefined', false]
].each do |string, result|
Expand All @@ -36,6 +38,7 @@
[
['disabled', false],
['service', false],
['dynamic_service', false],
['full', true],
['undefined', false]
].each do |string, result|
Expand All @@ -60,11 +63,13 @@

describe '#inject_sql_basehash?' do
[
[false, false],
[true, true]
].each do |value, result|
context "when given `#{value}`" do
subject { described_class.new('service', false, value).inject_sql_basehash? }
['service', false, false],
['service', true, true],
['dynamic_service', false, true],
['dynamic_service', true, true]
].each do |mode, value, result|
context "when given mode `#{mode}` and inject_sql_basehash `#{value}`" do
subject { described_class.new(mode, false, value).inject_sql_basehash? }
it { is_expected.to be result }
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/datadog/tracing/contrib/propagation/sql_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
end
end

context 'when `dynamic_service` mode' do
let(:mode) { 'dynamic_service' }

before do
allow(Datadog.configuration).to receive(:experimental_propagate_process_tags_enabled).and_return(true)
allow(agent_info).to receive(:propagation_checksum).and_return(1234567890)
end

it 'sets the propagated hash and does not mark full trace injection' do
described_class.annotate!(span_op, propagation_mode)

expect(span_op.get_tag('_dd.propagated_hash')).to eq('1234567890')
expect(span_op.get_tag('_dd.dbm_trace_injected')).to be_nil
end
end

context 'when `full` mode' do
let(:mode) { 'full' }

Expand Down Expand Up @@ -265,6 +281,21 @@
end
end

context 'when `dynamic_service` mode' do
let(:mode) { 'dynamic_service' }

before do
Datadog.configuration.experimental_propagate_process_tags_enabled = true
allow(agent_info).to receive(:propagation_checksum).and_return(1234567890)
end

it 'includes service metadata and the propagation hash in the SQL comment' do
is_expected.to eq(
"/*dde='dev',ddps='api',ddpv='1.2',ddsh='1234567890',dddbs='db_service'*/ #{sql_statement}"
)
end
end

context 'when `full` mode' do
let(:mode) { 'full' }
let(:traceparent) { '00-00000000000000000000000000c0ffee-0000000000000bee-fe' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
end
end

%w[disabled service full].each do |mode|
context 'when ENV variable `DD_DBM_PROPAGATION_MODE` is set to dynamic_service' do
with_env 'DD_DBM_PROPAGATION_MODE' => 'dynamic_service'

it_behaves_like 'propagates with sql comment', mode: 'dynamic_service', span_op_name: span_op_name, error: error do
let(:propagation_mode) { Datadog::Tracing::Contrib::Propagation::SqlComment::Mode.new('dynamic_service', append_comment, inject_sql_basehash) }
end
end

%w[disabled service dynamic_service full].each do |mode|
context "when `comment_propagation` is configured to #{mode}" do
let(:configuration_options) do
{comment_propagation: mode, service_name: service_name}
Expand Down Expand Up @@ -183,4 +191,22 @@
expect(span.get_tag('_dd.propagated_hash')).to be_nil
end
end

context 'when comment_propagation is dynamic_service and experimental_propagate_process_tags_enabled is true' do
before do
allow(Datadog.configuration).to receive(:experimental_propagate_process_tags_enabled).and_return(true)
end

let(:configuration_options) do
{comment_propagation: 'dynamic_service', service_name: service_name}
end

it 'injects base hash in the _dd.propagated_hash span tag' do
subject

span = spans.find { |s| s.name == span_op_name }
expect(span).not_to be_nil
expect(span.get_tag('_dd.propagated_hash')).to eq('1234567890')
end
end
end
Loading