Skip to content
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

Remove db.name attribute from Redis instrumentation #1427

Merged

Conversation

luke6Lh43
Copy link
Contributor

@luke6Lh43 luke6Lh43 commented Nov 2, 2022

Description

There is no DB name concept in Redis (databases are numbered from 0 to 15), hence sending db.name attribute to OTel collector doesn't make sense. In the current implementation db.name attribute is defaulted to DB number. Technically, it shouldn't be any problem with that but it may break some OpenTelemetry backends which expects a real DB name not a number. There is another attribute db.redis.database_index which should be used for this purpose.

After this fix, we will be also alligned with below document where is stated that for Redis db.name attribute shouldn't be set:

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md

Fixes #1395

Type of change

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

How Has This Been Tested?

Firstly, I run following command to test the setup after the code change:

tox -e test-instrumentation-redis

Then, I tested that locally with some app and after removing db.name attribute from instrumentation, it is not exported to OTel collector as expected.

Before the fix:

InstrumentationScope opentelemetry.instrumentation.redis 0.34b0
Span #0
    Trace ID       : cf35dd1cc002f28471e83522955fa616
    Parent ID      : 0665eddd63d1811b
    ID             : 340b84683b6076c3
    Name           : RPUSH
    Kind           : SPAN_KIND_CLIENT
    Start time     : 2022-11-02 11:15:54.311276 +0000 UTC
    End time       : 2022-11-02 11:15:54.318314 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message : 
Attributes:
     -> db.name: Int(0)
     -> db.redis.args_length: Int(3)
     -> db.redis.database_index: Int(0)
     -> db.statement: Str(RPUSH key {"time": "2022-11-02 12:15:54", "voter_id": "4e03a47155c7252", "choice": "alone"})
     -> db.system: Str(redis)
     -> net.peer.name: Str(localhost)
     -> net.peer.port: Str(6379)
     -> net.transport: Str(ip_tcp)
Span #1
    Trace ID       : dfab74806a3f5a6eb27dd96ea5825486
    Parent ID      : 2ba23ddbdcbbb60d
    ID             : 68818dbba797fd91
    Name           : LRANGE
    Kind           : SPAN_KIND_CLIENT
    Start time     : 2022-11-02 11:15:54.335377 +0000 UTC
    End time       : 2022-11-02 11:15:54.34132 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message : 
Attributes:
     -> db.name: Int(0)
     -> db.redis.args_length: Int(4)
     -> db.redis.database_index: Int(0)
     -> db.statement: Str(LRANGE key 0 -1)
     -> db.system: Str(redis)
     -> net.peer.name: Str(localhost)
     -> net.peer.port: Str(6379)
     -> net.transport: Str(ip_tcp)

After the fix:

InstrumentationScope opentelemetry.instrumentation.redis 0.34b0
Span #0
    Trace ID       : ab2622f411379b075ec6ebf699e08525
    Parent ID      : e7ae303f79d7a23a
    ID             : bec8e7f732dd3c4b
    Name           : RPUSH
    Kind           : SPAN_KIND_CLIENT
    Start time     : 2022-11-01 10:56:13.013253 +0000 UTC
    End time       : 2022-11-01 10:56:13.019925 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message : 
Attributes:
     -> db.redis.args_length: Int(3)
     -> db.redis.database_index: Int(0)
     -> db.statement: Str(RPUSH key {"time": "2022-11-01 11:56:13", "voter_id": "577278715f01a5e", "choice": "alone"})
     -> db.system: Str(redis)
     -> net.peer.name: Str(localhost)
     -> net.peer.port: Str(6379)
     -> net.transport: Str(ip_tcp)
Span #1
    Trace ID       : 71bbcbb379bb5baa7a2702287bcfe401
    Parent ID      : b117d6756b142459
    ID             : 0b6621439c2bfea1
    Name           : LRANGE
    Kind           : SPAN_KIND_CLIENT
    Start time     : 2022-11-01 10:56:13.035479 +0000 UTC
    End time       : 2022-11-01 10:56:13.040153 +0000 UTC
    Status code    : STATUS_CODE_UNSET
    Status message : 
Attributes:
     -> db.redis.args_length: Int(4)
     -> db.redis.database_index: Int(0)
     -> db.statement: Str(LRANGE key 0 -1)
     -> db.system: Str(redis)
     -> net.peer.name: Str(localhost)
     -> net.peer.port: Str(6379)
     -> net.transport: Str(ip_tcp)

Does This PR Require a Core Repo Change?

  • No.

Checklist:

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

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@luke6Lh43 luke6Lh43 requested a review from a team November 2, 2022 11:20
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 2, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: luke6Lh43 / name: luke6Lh43 (f009d91, c065c20)
  • ✅ login: sanketmehta28 / name: Sanket Mehta (0caa0c6)

Copy link
Member

@sanketmehta28 sanketmehta28 left a comment

Choose a reason for hiding this comment

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

Please add the test case for this change

@luke6Lh43
Copy link
Contributor Author

luke6Lh43 commented Nov 3, 2022

I've tried to fix docker-tests which is failing but it looks there is more generic issue... I've run it locally on my machine and got an error related to psycopg2 library:

<snipped>

× Encountered error while trying to install package.
╰─> psycopg2

<snipped>

To be 100% sure that issue is not related to the fix I've made, I've cloned main repo and run docker-tests and got same error message... To my mind it looks like some issue with packages dependencies. Has anyone experienced similar issue recently?

@srikanthccv
Copy link
Member

That's a regular python dep installation issue. It is probably not related to this project, but in general, you may have an issue installing the above. Are you sure your system is set up to run the psycopg2?

@luke6Lh43
Copy link
Contributor Author

Hi. I've added another commit where I've simply removed verification of db.name attribute from test functions. @sanketmehta28 since we're removing db.name attribute from instrumentation, do we really need another test function for that or removing verification of that attribute from existing functions would be enough?

@sanketmehta28
Copy link
Member

removing the verification of the attribute and adding verification for new attribute should be sufficient

CHANGELOG.md Outdated Show resolved Hide resolved
@srikanthccv srikanthccv enabled auto-merge (squash) November 10, 2022 19:01
@srikanthccv srikanthccv merged commit 5f85a5b into open-telemetry:main Nov 10, 2022
saartochner-lumigo pushed a commit to lumigo-io/opentelemetry-python-contrib that referenced this pull request Nov 13, 2022
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.

[opentelemetry-instrumentation-redis] Stop sending db.name argument or rename it to redis[0-15]
3 participants