From 20e1cd04f8167276453b27469912e90984a291ac Mon Sep 17 00:00:00 2001 From: Xuan <112967240+xuan-cao-swi@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:53:47 -0400 Subject: [PATCH] feat!: obfuscation for mysql2, dalli and postgresql as default option for db_statement (#682) * feat!: fuscation for mysql2, dalli and pg * feat!: update readme * feat!: set db.statement option to obfuscate by default for mysql2, pg and dalli Co-authored-by: Ariel Valentin --- instrumentation/dalli/README.md | 16 ++++++++++++++++ .../instrumentation/dalli/instrumentation.rb | 2 +- .../dalli/instrumentation_test.rb | 2 +- instrumentation/mysql2/README.md | 6 +++--- .../instrumentation/mysql2/instrumentation.rb | 2 +- .../mysql2/instrumentation_test.rb | 2 +- instrumentation/pg/README.md | 4 ++-- .../instrumentation/pg/instrumentation.rb | 2 +- .../instrumentation/pg/instrumentation_test.rb | 2 +- 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/instrumentation/dalli/README.md b/instrumentation/dalli/README.md index 3f0efd4c6..bf4f988fa 100644 --- a/instrumentation/dalli/README.md +++ b/instrumentation/dalli/README.md @@ -30,6 +30,22 @@ OpenTelemetry::SDK.configure do |c| end ``` +### Configuration options + +```ruby +OpenTelemetry::SDK.configure do |c| + c.use 'OpenTelemetry::Instrumentation::Dalli', { + # You may optionally set a value for 'peer.service', which + # will be included on all spans from this instrumentation: + peer_service: '', + + # The obfuscation of query in the db.statement attribute is enabled by default. + # To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit + db_statement: :include, + } +end +``` + ## How can I get involved? The `opentelemetry-instrumentation-dalli` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`. diff --git a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb index 014f38ccd..610bf5a5f 100644 --- a/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb +++ b/instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb @@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit obfuscate include] + option :db_statement, default: :obfuscate, validate: %I[omit obfuscate include] private diff --git a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb index d426a4bf3..512ba0359 100644 --- a/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb +++ b/instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb @@ -28,7 +28,7 @@ describe 'tracing' do before do - instrumentation.install + instrumentation.install(db_statement: :include) end it 'accepts peer service name from config' do diff --git a/instrumentation/mysql2/README.md b/instrumentation/mysql2/README.md index 66af9c6bb..7ba249e74 100644 --- a/instrumentation/mysql2/README.md +++ b/instrumentation/mysql2/README.md @@ -46,9 +46,9 @@ end ```ruby OpenTelemetry::SDK.configure do |c| c.use 'OpenTelemetry::Instrumentation::Mysql2', { - # The obfuscation of SQL in the db.statement attribute is disabled by default. - # To enable, set db_statement to :obfuscate. - db_statement: :obfuscate, + # The obfuscation of SQL in the db.statement attribute is enabled by default. + # To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit + db_statement: :include, } end ``` diff --git a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb index 3e85c3ff3..9a7b78ccb 100644 --- a/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb +++ b/instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb @@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit include obfuscate] + option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate] option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name] option :obfuscation_limit, default: 2000, validate: :integer diff --git a/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb b/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb index e363980c7..6eb1ada72 100644 --- a/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb +++ b/instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb @@ -22,7 +22,7 @@ let(:instrumentation) { OpenTelemetry::Instrumentation::Mysql2::Instrumentation.instance } let(:exporter) { EXPORTER } let(:span) { exporter.finished_spans.first } - let(:config) { {} } + let(:config) { { db_statement: :include } } before do exporter.reset diff --git a/instrumentation/pg/README.md b/instrumentation/pg/README.md index a9261dce6..12c4c167d 100644 --- a/instrumentation/pg/README.md +++ b/instrumentation/pg/README.md @@ -50,9 +50,9 @@ OpenTelemetry::SDK.configure do |c| # will be included on all spans from this instrumentation: peer_service: 'postgres:readonly', - # By default, this instrumentation includes the executed SQL as the `db.statement` + # By default, this instrumentation obfuscate/sanitize the executed SQL as the `db.statement` # semantic attribute. Optionally, you may disable the inclusion of this attribute entirely by - # setting this option to :omit or sanitize the attribute by setting to :obfuscate + # setting this option to :omit or disbale sanitization the attribute by setting to :include db_statement: :include, } end diff --git a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb index bf6a4dcdc..2eeb6ac66 100644 --- a/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb +++ b/instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb @@ -25,7 +25,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base end option :peer_service, default: nil, validate: :string - option :db_statement, default: :include, validate: %I[omit include obfuscate] + option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate] option :obfuscation_limit, default: 2000, validate: :integer private diff --git a/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb b/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb index 57bef4797..32dedf646 100644 --- a/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb +++ b/instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb @@ -51,7 +51,7 @@ let(:user) { ENV.fetch('TEST_POSTGRES_USER', 'postgres') } let(:dbname) { ENV.fetch('TEST_POSTGRES_DB', 'postgres') } let(:password) { ENV.fetch('TEST_POSTGRES_PASSWORD', 'postgres') } - + let(:config) { { db_statement: :include } } before do instrumentation.install(config) end