Skip to content

Add Valkey Instrumentation#3478

Open
sightseeker wants to merge 27 commits intoopen-telemetry:mainfrom
sightseeker:feature/valkey
Open

Add Valkey Instrumentation#3478
sightseeker wants to merge 27 commits intoopen-telemetry:mainfrom
sightseeker:feature/valkey

Conversation

@sightseeker
Copy link
Copy Markdown

@sightseeker sightseeker commented May 8, 2025

Description

This PR introduces a new Valkey instrumentation plugin for the OpenTelemetry Python Contrib library.
users can now automatically capture and export Valkey trace data alongside existing OpenTelemetry spans. This fills the gap for applications leveraging Valkey’s Client library, enabling end-to-end distributed tracing without manual span management.

Notes:

  • Since the valkey-search module is not yet GA, related tests are intentionally omitted in this PR.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Added unit tests under instrumentation/opentelemetry-instrumentation-valkey/tests/ covering:
    • automatic span creation on Valkey client calls
    • context propagation across async boundaries
    • correct attribute mapping (e.g. db.statement, db.valkey.args_length, db.valkey.database_index, net.peer.name)
  • Manual end-to-end test with example app instrumented via opentelemetry-instrumentation-valkey, verified spans in Jaeger backend
  • Test configuration:
    • tox -e py38-test-instrumentation-valkey
    • tox -e py39-test-instrumentation-valkey
    • tox -e py310-test-instrumentation-valkey
    • tox -e py311-test-instrumentation-valkey
    • tox -e py312-test-instrumentation-valkey
    • tox -e py313-test-instrumentation-valkey
    • tox -e pypy3-test-instrumentation-valkey
  • Lint configuration:
    • tox -e lint-instrumentation-valkey

Does This PR Require a Core Repo Change?

  • Yes. – Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (CHANGELOG.md entry under “New Features”)
  • Unit tests have been added
  • Documentation has been updated (README and Sphinx docs)

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@retryable
def check_redis_connection():
connection = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
connection = valkey.Redis(host=REDIS_HOST, port=REDIS_PORT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can test both no?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you watching for this PR, sir
But, This is a draft of PR.
Could you waiting for ready.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@xrmx
Thank you for your patience. Would you mind taking a look and reviewing this PR?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this PR is so large that it is difficult to review. I suggest splitting it into several smaller PRs, as that would make more sense.

Copy link
Copy Markdown
Author

@sightseeker sightseeker May 16, 2025

Choose a reason for hiding this comment

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

@zhengkezhou1

Thanks for the feedback! This instrumentation PR is actually a near-one-for-one copy of the existing Redis instrumentation, with only the service-specific bits renamed and a handful of Valkey-specific tweaks. To see how small the diff really is, you can run:

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/src \
                    instrumentation/opentelemetry-instrumentation-valkey/src

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/tests/__init__.py \
                    instrumentation/opentelemetry-instrumentation-valkey/tests/__init__.py

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py \
                    instrumentation/opentelemetry-instrumentation-valkey/tests/test_valkey.py

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/LICENCE \
                    instrumentation/opentelemetry-instrumentation-valkey/LICENCE

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/pyproject.toml \
                    instrumentation/opentelemetry-instrumentation-valkey/pyproject.toml

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/README.rst \
                    instrumentation/opentelemetry-instrumentation-valkey/README.rst

git diff --no-index instrumentation/opentelemetry-instrumentation-redis/test-requirements.txt \
                    instrumentation/opentelemetry-instrumentation-valkey/test-requirements.txt

git diff --no-index tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py \
                    tests/opentelemetry-docker-tests/tests/valkey/test_valkey_functional.py

Because the core of this PR is simply “copy + rename + small adjustments,” I think a single PR still keeps reviewable granularity. Please let me know if you’d prefer me to split out any particular piece!

@sightseeker sightseeker marked this pull request as ready for review May 9, 2025 06:58
@sightseeker sightseeker requested a review from a team as a code owner May 9, 2025 06:58
@sightseeker sightseeker changed the title Valkey Instrumentation from Redis Instrumentation Based Add Valkey Instrumentation based from Redis Instrumentation May 10, 2025
@sightseeker sightseeker requested a review from xrmx May 10, 2025 05:30
@sightseeker sightseeker changed the title Add Valkey Instrumentation based from Redis Instrumentation Add Valkey Instrumentation May 12, 2025
@amirreza-sf80
Copy link
Copy Markdown

adding valkey support was also discussed in valkey-io/valkey-py#190 (comment)

i'd be happy to see valkey supported here as well
but having two package with the exact same code base is gonna be problematic

one idea would be to create a base package that does the logic of both redis and valkey, and valkey and redis packages only implementing the parts needed for them
tho i can see this one has it's own problems as well

anyhow, if you need help on this i'm happy to lend a hand

mkmkme pushed a commit to valkey-io/valkey-py that referenced this pull request Jun 11, 2025
There's no opentelemetry-instrumentation-valkey as of now, although it
is WIP [1]. Fix the link for now, we can revert it later.

[1] open-telemetry/opentelemetry-python-contrib#3478

Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io>
@sightseeker
Copy link
Copy Markdown
Author

Hi everyone, thank you for your patience and for all the thoughtful feedback!

I've merged the latest main to resolve conflicts and keep this PR up to date.

Regarding the suggestion from @amirreza-sf80 and @leandrodamascena about creating a shared base package for Redis and Valkey — I agree that maintaining two packages with nearly identical code is not ideal. I'm planning to refactor this by extracting the common instrumentation logic into a shared base that both Redis and Valkey can build on, with each package only implementing the backend-specific parts.

I'll be working on this in the coming updates. Any input or help is very welcome!

@pmeier Thanks for creating the external repo as a stopgap — that's really helpful for the community in the meantime.

@dcmcand Thanks for the support!

…ation

Create opentelemetry-instrumentation-redis-valkey-base with KVStoreConfig
dataclass and parameterized factory functions (_traced_execute_factory,
_traced_execute_pipeline_factory, and async variants). Both Redis and Valkey
instrumentation packages now delegate to this shared base, eliminating code
duplication while preserving all existing behavior and backward compatibility.

Valkey gains instrument_client/uninstrument_client and suppress_instrumentation
support from following the Redis pattern through the shared base.
@sightseeker
Copy link
Copy Markdown
Author

Hi everyone, the shared base package refactoring is now complete! Here's a summary of the changes:

  • Created opentelemetry-instrumentation-redis-valkey-base — a shared base package containing KVStoreConfig dataclass and parameterized factory functions for traced execution (sync/async, single command/pipeline)
  • Refactored opentelemetry-instrumentation-redis to delegate to the shared base (all 29 existing tests pass, no behavioral changes)
  • Refactored opentelemetry-instrumentation-valkey to use the shared base, gaining instrument_client()/uninstrument_client() and suppress_instrumentation support for free (12 tests pass)

This addresses the concerns raised by @amirreza-sf80 and @leandrodamascena about code duplication. The backend-specific differences are now isolated in each package's KVStoreConfig, while all common tracing logic lives in the shared base.

Ready for review — any feedback is welcome!

@github-actions github-actions Bot removed the Stale label Mar 12, 2026
@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 26, 2026
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Hi @sightseeker thanks for this. Please could you merge main in and resolve merge conflicts? That will hopefully stop some of the ci/cd failures.

Then please also do tox -e precommit to fix the formatting

@sightseeker
Copy link
Copy Markdown
Author

@tammy-baylis-swi Done! I've merged main and resolved the conflicts, and ran tox -e precommit to fix formatting issues (unused imports and an RST title underline). Please take a look when you get a chance.

build-backend = "hatchling.build"

[project]
name = "opentelemetry-instrumentation-valkey"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @sightseeker !

Do you know who published this package with the same name?: https://pypi.org/project/opentelemetry-instrumentation-valkey/ We might have to name this something else.

Would you continue to own these new packages via https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/.github/component_owners.yml?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch! I looked into it — the package on PyPI (opentelemetry-instrumentation-valkey by ajay-h1) appears to be a name-squatting package. Its description is "A professional-grade AI utility for automated data synchronization and backend management" with a homepage pointing to https://github.com/ai/library, which is completely unrelated to OpenTelemetry. I've reported it to PyPI as name-squatting on the official opentelemetry-instrumentation-* namespace.

Regarding component ownership — yes, I'm happy to be listed as the owner for the Valkey and redis-valkey-base packages in component_owners.yml. I'll add myself there.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added myself as component owner for the Valkey and redis-valkey-base packages in 9a4656e.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you that's awesome. Please keep us posted on the squatting report.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks!

I reported it as malware, but PyPI responded that it doesn't appear to be malicious in nature. The proper process is a PEP 541 name transfer request via pypa/pypi-support. The package's homepage (https://github.com/ai/library) returns 404, so there's a strong case for the claim. It would likely carry more weight if filed by the open-telemetry organization.

Would someone from the maintainer team be able to help with that?

Copy link
Copy Markdown
Contributor

@xrmx xrmx Apr 16, 2026

Choose a reason for hiding this comment

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

@sightseeker Filed a PEP 541 issue, you can follow pypi/support#10257

@@ -0,0 +1,472 @@
# Copyright The OpenTelemetry Authors
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two semconv questions on this config:

  1. db.system = "valkey""valkey" is not yet a recognised value in the OTel semantic conventions (neither in DbSystemValues nor the incubating db_attributes). Has a semconv issue or PR been filed to add it? Without one, Valkey spans will not match any official db.system filter in backends that expect known values.

  2. db.valkey.database_index / db.valkey.args_length / db.valkey.pipeline_length — these are bespoke string literals with no semconv backing. Since Valkey is Redis-protocol-compatible, would it make sense to reuse DB_REDIS_DATABASE_INDEX for the index (at least until Valkey gets its own semconv definition)? Otherwise users may face a breaking change if/when semconv does define db.valkey.* attributes differently.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. You're right, valkey is not yet a recognized value in the OTel semantic conventions. I checked and there's no existing issue or PR to add it. I'll file a semconv issue to propose adding valkey as a db.system value. In the meantime, since Valkey is a Redis fork with its own identity and roadmap, I think using valkey is the right direction — but happy to discuss.

  2. That's a fair point. Since there's no semconv definition for Valkey yet, I think there are two options:

    • (a): Reuse Redis attributes (DB_REDIS_DATABASE_INDEX, etc.) for now and switch when semconv defines Valkey-specific ones
    • (b): Use db.valkey.* as proposed, accepting they may change later

I'd lean toward (a) for the db.valkey.* attributes — reusing DB_REDIS_DATABASE_INDEX etc. for now. For db.system, I still think "valkey" is correct since it identifies the actual database product being used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think use the redis based attributes for now and switch to the keyval ones once approved makes sense.

I'm okay with using db.system=valkey for now too.

Thanks @sightseeker.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. switched to Redis-based attributes (DB_REDIS_DATABASE_INDEX, db.redis.args_length, db.redis.pipeline_length) in f35ea5d, keeping db.system="valkey".

; Conflicts:
;	.github/workflows/test_1.yml
;	CHANGELOG.md
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Over all looks good. I've left a suggestion about not using net.transport and using db.system=keyval and reusing other Redis attributes pending specific ones being added to semconv.

Have you had any luck with getting the old package removed?

from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_PEER_NAME,
NET_PEER_PORT,
NET_TRANSPORT,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

net.transport has been deprecated, let's not introduce it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fix for review comment: a4be038

@MikeGoldsmith MikeGoldsmith moved this from Ready for review to Approved PRs that need fixes in Python PR digest Apr 8, 2026
…finitions exist

Use DB_REDIS_DATABASE_INDEX, db.redis.args_length, and db.redis.pipeline_length
instead of bespoke db.valkey.* attributes. db.system remains "valkey" to identify
the actual database product. Per review feedback from MikeGoldsmith.
Remove NET_TRANSPORT and NetTransportValues from the shared base util,
as net.transport has been deprecated in OTel semantic conventions.
Update Redis and Valkey tests accordingly. Per review feedback from
MikeGoldsmith.
; Conflicts:
;	.github/workflows/core_contrib_test.yml
;	instrumentation/opentelemetry-instrumentation-redis/pyproject.toml
;	opentelemetry-contrib-instrumentations/pyproject.toml
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

This looks good to me. Left one more suggestion of updating some semconv.

Still need to figure out the testing stuff and the Pypi pacakge ownership too.

…ER_NAME/NET_PEER_PORT

Migrate from deprecated net.peer.name/net.peer.port to the newer
server.address/server.port semconv attributes in the shared base package
and both Redis/Valkey tests. Per review feedback from MikeGoldsmith.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs that need fixes

Development

Successfully merging this pull request may close these issues.

10 participants