Skip to content

Commit

Permalink
Environment variable service_name for mysql2
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Dec 6, 2022
1 parent 6e70ec1 commit b7133eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/datadog/tracing/contrib/mysql2/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ class Settings < Contrib::Configuration::Settings
o.lazy
end

option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
option :service_name do |o|
o.default do
ENV.fetch(Ext::ENV_SERVICE_NAME) do
Ext::DEFAULT_PEER_SERVICE_NAME
end
end
o.lazy
end

option :comment_propagation do |o|
o.default do
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/mysql2/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Mysql2
# @public_api Changing resource names, tag names, or environment variables creates breaking changes.
module Ext
ENV_ENABLED = 'DD_TRACE_MYSQL2_ENABLED'.freeze
ENV_SERVICE_NAME = 'DD_TRACE_MYSQL2_SERVICE_NAME'.freeze
ENV_ANALYTICS_ENABLED = 'DD_TRACE_MYSQL2_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MYSQL2_ANALYTICS_SAMPLE_RATE'.freeze
DEFAULT_PEER_SERVICE_NAME = 'mysql2'.freeze
Expand Down
9 changes: 9 additions & 0 deletions spec/datadog/tracing/contrib/mysql2/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'datadog/tracing/contrib/analytics_examples'
require 'datadog/tracing/contrib/propagation/sql_comment'
require 'datadog/tracing/contrib/sql_comment_propagation_examples'
require 'datadog/tracing/contrib/environment_service_name_examples'

require 'ddtrace'
require 'mysql2'
Expand Down Expand Up @@ -108,6 +109,10 @@
end

it_behaves_like 'with sql comment propagation', span_op_name: 'mysql2.query'

it_behaves_like 'environment service name', 'DD_TRACE_MYSQL2_SERVICE_NAME' do
let(:configuration_options) { {} }
end
end

context 'when a failed query is made' do
Expand All @@ -125,6 +130,10 @@
end

it_behaves_like 'with sql comment propagation', span_op_name: 'mysql2.query', error: Mysql2::Error

it_behaves_like 'environment service name', 'DD_TRACE_MYSQL2_SERVICE_NAME', error: Mysql2::Error do
let(:configuration_options) { {} }
end
end
end
end
Expand Down

0 comments on commit b7133eb

Please sign in to comment.