Skip to content

Conversation

@cBiscuitSurprise
Copy link

Description

This CR adds test to verify the semantic conventions for database instrumentation, specifically redis (other DBs to follow). Once the dependent PR is merged, we can move this PR to main

Fixes open-telemetry#1627

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A: Ran updated unit tests.

Does This PR Require a Core Repo Change?

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated (N/A)
  • Unit tests have been added
  • Documentation has been updated (N/A --The docs for 1.20.0 are slightly inaccurate for the Redis example -- namely the net.transport should net.sock.family for socket connections and "UNIX" should be lower-case. Not sure if that needs to be updated or just wait until we get in sync with the latest).

verifies the database semantic convention for redis (1.20.0)
fixes minor issues with attributes to align with specification
)
attributes[SpanAttributes.NET_PEER_PORT] = conn_kwargs.get(
"port", 6379
"host", "TRACE_MISSING"
Copy link
Author

@cBiscuitSurprise cBiscuitSurprise Sep 2, 2023

Choose a reason for hiding this comment

The 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? None may be sufficient, but I wasn't sure.

Defaulting to localhost and 6379 might obfuscate an issue.


if conn_kwargs.get("client_name"):
# TODO: add to semconv?
attributes["db.redis.client_name"] = conn_kwargs["client_name"]
Copy link
Author

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.

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)
Copy link
Author

@cBiscuitSurprise cBiscuitSurprise Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I also need to check the negative (e.g. assertNotIn("net.sock.family", span.attributes))?

@lmolkova lmolkova closed this Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants