-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] semantic convention 1.20.0 verification - database instrumentation - redis #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,21 +30,27 @@ def _extract_conn_attributes(conn_kwargs): | |
| } | ||
| db = conn_kwargs.get("db", 0) | ||
| attributes[SpanAttributes.DB_REDIS_DATABASE_INDEX] = db | ||
| try: | ||
|
|
||
| if conn_kwargs.get("username"): | ||
| attributes[SpanAttributes.DB_USER] = conn_kwargs["username"] | ||
|
|
||
| if conn_kwargs.get("client_name"): | ||
| # TODO: add to semconv? | ||
| attributes["db.redis.client_name"] = conn_kwargs["client_name"] | ||
|
|
||
| if conn_kwargs.get("path"): | ||
| attributes[SpanAttributes.NET_SOCK_PEER_ADDR] = conn_kwargs["path"] | ||
| attributes[ | ||
| SpanAttributes.NET_SOCK_FAMILY | ||
| ] = NetSockFamilyValues.UNIX.value | ||
| else: | ||
| attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get( | ||
| "host", "localhost" | ||
| ) | ||
| attributes[SpanAttributes.NET_PEER_PORT] = conn_kwargs.get( | ||
| "port", 6379 | ||
| "host", "TRACE_MISSING" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a sentinel defined for a missing value when one is expected? Defaulting to |
||
| ) | ||
| attributes[SpanAttributes.NET_PEER_PORT] = conn_kwargs.get("port", 0) | ||
| attributes[ | ||
| SpanAttributes.NET_TRANSPORT | ||
| ] = NetTransportValues.IP_TCP.value | ||
| except KeyError: | ||
| attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get("path", "") | ||
| attributes[ | ||
| SpanAttributes.NET_SOCK_FAMILY | ||
| ] = NetSockFamilyValues.UNIX.value | ||
|
|
||
| return attributes | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,3 +243,58 @@ def test_no_op_tracer_provider(self): | |
|
|
||
| spans = self.memory_exporter.get_finished_spans() | ||
| self.assertEqual(len(spans), 0) | ||
|
|
||
| def test_db_semantic_attributes_server(self): | ||
| redis_client = redis.Redis( | ||
| host="test.db.semantic.conv", | ||
| port=12345, | ||
| client_name="buggy_client", | ||
| ) | ||
| connection = redis.connection.Connection() | ||
| redis_client.connection = connection | ||
|
|
||
| with mock.patch.object(redis_client, "connection"): | ||
| redis_client.set("key", "value") | ||
|
|
||
| spans = self.memory_exporter.get_finished_spans() | ||
| self.assertEqual(len(spans), 1) | ||
|
|
||
| # semconv 1.20.0 | ||
| span = spans[0] | ||
| self.assertEqual(span.name, "SET") | ||
| self.assertEqual(span.attributes.get("db.system"), "redis") | ||
| self.assertEqual( | ||
| span.attributes.get("net.peer.name"), "test.db.semantic.conv" | ||
| ) | ||
| self.assertEqual(span.attributes.get("net.peer.port"), 12345) | ||
| self.assertEqual(span.attributes.get("net.transport"), "ip_tcp") | ||
| self.assertEqual(span.attributes.get("db.statement"), "SET ? ?") | ||
| self.assertEqual(span.attributes.get("db.redis.database_index"), 0) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I also need to check the negative (e.g. |
||
|
|
||
| def test_db_semantic_attributes_socket(self): | ||
| redis_client = redis.Redis( | ||
| unix_socket_path="/tmp/semantic.conv.sock", | ||
| db=2, | ||
| username="redis-user", | ||
| ) | ||
| connection = redis.connection.Connection() | ||
| redis_client.connection = connection | ||
|
|
||
| with mock.patch.object(redis_client, "connection"): | ||
| redis_client.set("key", "value") | ||
|
|
||
| spans = self.memory_exporter.get_finished_spans() | ||
| self.assertEqual(len(spans), 1) | ||
|
|
||
| # semconv 1.20.0 | ||
| span = spans[0] | ||
| self.assertEqual(span.name, "SET") | ||
| self.assertEqual(span.attributes.get("db.system"), "redis") | ||
| self.assertEqual( | ||
| span.attributes.get("net.sock.peer.addr"), | ||
| "/tmp/semantic.conv.sock", | ||
| ) | ||
| self.assertEqual(span.attributes.get("net.sock.family"), "unix") | ||
| self.assertEqual(span.attributes.get("db.statement"), "SET ? ?") | ||
| self.assertEqual(span.attributes.get("db.redis.database_index"), 2) | ||
| self.assertEqual(span.attributes.get("db.user"), "redis-user") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't in the semconv, but would be useful for debugging and can be different from
username.