Sanitize redis db_statement by default (#1776)

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
Co-authored-by: Shalev Roda <65566801+shalevr@users.noreply.github.com>
This commit is contained in:
Nimrod Shlagman
2023-06-13 15:37:55 +03:00
committed by GitHub
parent 818ef43223
commit 37d85f0745
6 changed files with 36 additions and 134 deletions

View File

@ -47,9 +47,7 @@ class TestRedisInstrument(TestBase):
def test_long_command_sanitized(self):
RedisInstrumentor().uninstrument()
RedisInstrumentor().instrument(
tracer_provider=self.tracer_provider, sanitize_query=True
)
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
self.redis_client.mget(*range(2000))
@ -75,7 +73,7 @@ class TestRedisInstrument(TestBase):
self._check_span(span, "MGET")
self.assertTrue(
span.attributes.get(SpanAttributes.DB_STATEMENT).startswith(
"MGET 0 1 2 3"
"MGET ? ? ? ?"
)
)
self.assertTrue(
@ -84,9 +82,7 @@ class TestRedisInstrument(TestBase):
def test_basics_sanitized(self):
RedisInstrumentor().uninstrument()
RedisInstrumentor().instrument(
tracer_provider=self.tracer_provider, sanitize_query=True
)
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
self.assertIsNone(self.redis_client.get("cheese"))
spans = self.memory_exporter.get_finished_spans()
@ -105,15 +101,13 @@ class TestRedisInstrument(TestBase):
span = spans[0]
self._check_span(span, "GET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET cheese"
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
)
self.assertEqual(span.attributes.get("db.redis.args_length"), 2)
def test_pipeline_traced_sanitized(self):
RedisInstrumentor().uninstrument()
RedisInstrumentor().instrument(
tracer_provider=self.tracer_provider, sanitize_query=True
)
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
with self.redis_client.pipeline(transaction=False) as pipeline:
pipeline.set("blah", 32)
@ -144,15 +138,13 @@ class TestRedisInstrument(TestBase):
self._check_span(span, "SET RPUSH HGETALL")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT),
"SET blah 32\nRPUSH foo éé\nHGETALL xxx",
"SET ? ?\nRPUSH ? ?\nHGETALL ?",
)
self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3)
def test_pipeline_immediate_sanitized(self):
RedisInstrumentor().uninstrument()
RedisInstrumentor().instrument(
tracer_provider=self.tracer_provider, sanitize_query=True
)
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
with self.redis_client.pipeline() as pipeline:
pipeline.set("a", 1)
@ -182,7 +174,7 @@ class TestRedisInstrument(TestBase):
span = spans[0]
self._check_span(span, "SET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "SET b 2"
span.attributes.get(SpanAttributes.DB_STATEMENT), "SET ? ?"
)
def test_parent(self):
@ -230,7 +222,7 @@ class TestRedisClusterInstrument(TestBase):
span = spans[0]
self._check_span(span, "GET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET cheese"
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
)
self.assertEqual(span.attributes.get("db.redis.args_length"), 2)
@ -247,7 +239,7 @@ class TestRedisClusterInstrument(TestBase):
self._check_span(span, "SET RPUSH HGETALL")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT),
"SET blah 32\nRPUSH foo éé\nHGETALL xxx",
"SET ? ?\nRPUSH ? ?\nHGETALL ?",
)
self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3)
@ -308,7 +300,7 @@ class TestAsyncRedisInstrument(TestBase):
self._check_span(span, "MGET")
self.assertTrue(
span.attributes.get(SpanAttributes.DB_STATEMENT).startswith(
"MGET 0 1 2 3"
"MGET ? ? ? ?"
)
)
self.assertTrue(
@ -322,7 +314,7 @@ class TestAsyncRedisInstrument(TestBase):
span = spans[0]
self._check_span(span, "GET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET cheese"
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
)
self.assertEqual(span.attributes.get("db.redis.args_length"), 2)
@ -344,7 +336,7 @@ class TestAsyncRedisInstrument(TestBase):
self._check_span(span, "SET RPUSH HGETALL")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT),
"SET blah 32\nRPUSH foo éé\nHGETALL xxx",
"SET ? ?\nRPUSH ? ?\nHGETALL ?",
)
self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3)
@ -364,7 +356,7 @@ class TestAsyncRedisInstrument(TestBase):
span = spans[0]
self._check_span(span, "SET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "SET b 2"
span.attributes.get(SpanAttributes.DB_STATEMENT), "SET ? ?"
)
def test_parent(self):
@ -412,7 +404,7 @@ class TestAsyncRedisClusterInstrument(TestBase):
span = spans[0]
self._check_span(span, "GET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET cheese"
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
)
self.assertEqual(span.attributes.get("db.redis.args_length"), 2)
@ -434,7 +426,7 @@ class TestAsyncRedisClusterInstrument(TestBase):
self._check_span(span, "SET RPUSH HGETALL")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT),
"SET blah 32\nRPUSH foo éé\nHGETALL xxx",
"SET ? ?\nRPUSH ? ?\nHGETALL ?",
)
self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3)
@ -488,5 +480,5 @@ class TestRedisDBIndexInstrument(TestBase):
span = spans[0]
self._check_span(span, "GET")
self.assertEqual(
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET foo"
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
)