mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-05 22:09:56 +08:00
Add support for enabling Redis sanitization from environment variable (#1690)
* Add support for enabling Redis sanitization from environment variable * add sanitization environment variable docs * strip environment variable * update changelog * lint * lint * lint - hopefully the last time --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
@ -168,6 +168,32 @@ class TestRedis(TestBase):
|
||||
span = spans[0]
|
||||
self.assertEqual(span.attributes.get("db.statement"), "SET ? ?")
|
||||
|
||||
def test_query_sanitizer_enabled_env(self):
|
||||
redis_client = redis.Redis()
|
||||
connection = redis.connection.Connection()
|
||||
redis_client.connection = connection
|
||||
|
||||
RedisInstrumentor().uninstrument()
|
||||
|
||||
env_patch = mock.patch.dict(
|
||||
"os.environ",
|
||||
{"OTEL_PYTHON_INSTRUMENTATION_SANITIZE_REDIS": "true"},
|
||||
)
|
||||
env_patch.start()
|
||||
RedisInstrumentor().instrument(
|
||||
tracer_provider=self.tracer_provider,
|
||||
)
|
||||
|
||||
with mock.patch.object(redis_client, "connection"):
|
||||
redis_client.set("key", "value")
|
||||
|
||||
spans = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(len(spans), 1)
|
||||
|
||||
span = spans[0]
|
||||
self.assertEqual(span.attributes.get("db.statement"), "SET ? ?")
|
||||
env_patch.stop()
|
||||
|
||||
def test_query_sanitizer_disabled(self):
|
||||
redis_client = redis.Redis()
|
||||
connection = redis.connection.Connection()
|
||||
|
Reference in New Issue
Block a user