Skip to content

Commit 20e1cd0

Browse files
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 <[email protected]>
1 parent 93dcf35 commit 20e1cd0

File tree

9 files changed

+27
-11
lines changed

9 files changed

+27
-11
lines changed

instrumentation/dalli/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ OpenTelemetry::SDK.configure do |c|
3030
end
3131
```
3232

33+
### Configuration options
34+
35+
```ruby
36+
OpenTelemetry::SDK.configure do |c|
37+
c.use 'OpenTelemetry::Instrumentation::Dalli', {
38+
# You may optionally set a value for 'peer.service', which
39+
# will be included on all spans from this instrumentation:
40+
peer_service: '',
41+
42+
# The obfuscation of query in the db.statement attribute is enabled by default.
43+
# To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit
44+
db_statement: :include,
45+
}
46+
end
47+
```
48+
3349
## How can I get involved?
3450

3551
The `opentelemetry-instrumentation-dalli` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.

instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2020
end
2121

2222
option :peer_service, default: nil, validate: :string
23-
option :db_statement, default: :include, validate: %I[omit obfuscate include]
23+
option :db_statement, default: :obfuscate, validate: %I[omit obfuscate include]
2424

2525
private
2626

instrumentation/dalli/test/opentelemetry/instrumentation/dalli/instrumentation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
describe 'tracing' do
3030
before do
31-
instrumentation.install
31+
instrumentation.install(db_statement: :include)
3232
end
3333

3434
it 'accepts peer service name from config' do

instrumentation/mysql2/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ end
4646
```ruby
4747
OpenTelemetry::SDK.configure do |c|
4848
c.use 'OpenTelemetry::Instrumentation::Mysql2', {
49-
# The obfuscation of SQL in the db.statement attribute is disabled by default.
50-
# To enable, set db_statement to :obfuscate.
51-
db_statement: :obfuscate,
49+
# The obfuscation of SQL in the db.statement attribute is enabled by default.
50+
# To disable, set db_statement to :include; to omit the query completely, set db_statement to :omit
51+
db_statement: :include,
5252
}
5353
end
5454
```

instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2/instrumentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2020
end
2121

2222
option :peer_service, default: nil, validate: :string
23-
option :db_statement, default: :include, validate: %I[omit include obfuscate]
23+
option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate]
2424
option :span_name, default: :statement_type, validate: %I[statement_type db_name db_operation_and_name]
2525
option :obfuscation_limit, default: 2000, validate: :integer
2626

instrumentation/mysql2/test/opentelemetry/instrumentation/mysql2/instrumentation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
let(:instrumentation) { OpenTelemetry::Instrumentation::Mysql2::Instrumentation.instance }
2323
let(:exporter) { EXPORTER }
2424
let(:span) { exporter.finished_spans.first }
25-
let(:config) { {} }
25+
let(:config) { { db_statement: :include } }
2626

2727
before do
2828
exporter.reset

instrumentation/pg/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ OpenTelemetry::SDK.configure do |c|
5050
# will be included on all spans from this instrumentation:
5151
peer_service: 'postgres:readonly',
5252

53-
# By default, this instrumentation includes the executed SQL as the `db.statement`
53+
# By default, this instrumentation obfuscate/sanitize the executed SQL as the `db.statement`
5454
# semantic attribute. Optionally, you may disable the inclusion of this attribute entirely by
55-
# setting this option to :omit or sanitize the attribute by setting to :obfuscate
55+
# setting this option to :omit or disbale sanitization the attribute by setting to :include
5656
db_statement: :include,
5757
}
5858
end

instrumentation/pg/lib/opentelemetry/instrumentation/pg/instrumentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2525
end
2626

2727
option :peer_service, default: nil, validate: :string
28-
option :db_statement, default: :include, validate: %I[omit include obfuscate]
28+
option :db_statement, default: :obfuscate, validate: %I[omit include obfuscate]
2929
option :obfuscation_limit, default: 2000, validate: :integer
3030

3131
private

instrumentation/pg/test/opentelemetry/instrumentation/pg/instrumentation_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
let(:user) { ENV.fetch('TEST_POSTGRES_USER', 'postgres') }
5252
let(:dbname) { ENV.fetch('TEST_POSTGRES_DB', 'postgres') }
5353
let(:password) { ENV.fetch('TEST_POSTGRES_PASSWORD', 'postgres') }
54-
54+
let(:config) { { db_statement: :include } }
5555
before do
5656
instrumentation.install(config)
5757
end

0 commit comments

Comments
 (0)