Add Valkey Instrumentation#3478
Conversation
| @retryable | ||
| def check_redis_connection(): | ||
| connection = redis.Redis(host=REDIS_HOST, port=REDIS_PORT) | ||
| connection = valkey.Redis(host=REDIS_HOST, port=REDIS_PORT) |
There was a problem hiding this comment.
Thank you watching for this PR, sir
But, This is a draft of PR.
Could you waiting for ready.
There was a problem hiding this comment.
@xrmx
Thank you for your patience. Would you mind taking a look and reviewing this PR?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.pyBecause 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!
669c7f8 to
73d1eca
Compare
73d1eca to
24ecc80
Compare
|
adding valkey support was also discussed in valkey-io/valkey-py#190 (comment) i'd be happy to see valkey supported here as well 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 anyhow, if you need help on this i'm happy to lend a hand |
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>
|
Hi everyone, thank you for your patience and for all the thoughtful feedback! I've merged the latest 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! |
73f1e72 to
de7dd22
Compare
…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.
de7dd22 to
4f9e1ad
Compare
|
Hi everyone, the shared base package refactoring is now complete! Here's a summary of the changes:
This addresses the concerns raised by @amirreza-sf80 and @leandrodamascena about code duplication. The backend-specific differences are now isolated in each package's Ready for review — any feedback is welcome! |
|
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. |
|
Hi @sightseeker thanks for this. Please could you merge Then please also do |
; Conflicts: ; .github/workflows/test_1.yml
|
@tammy-baylis-swi Done! I've merged |
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "opentelemetry-instrumentation-valkey" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added myself as component owner for the Valkey and redis-valkey-base packages in 9a4656e.
There was a problem hiding this comment.
Thank you that's awesome. Please keep us posted on the squatting report.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@sightseeker Filed a PEP 541 issue, you can follow pypi/support#10257
| @@ -0,0 +1,472 @@ | |||
| # Copyright The OpenTelemetry Authors | |||
There was a problem hiding this comment.
Two semconv questions on this config:
-
db.system = "valkey"—"valkey"is not yet a recognised value in the OTel semantic conventions (neither inDbSystemValuesnor the incubatingdb_attributes). Has a semconv issue or PR been filed to add it? Without one, Valkey spans will not match any officialdb.systemfilter in backends that expect known values. -
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 reuseDB_REDIS_DATABASE_INDEXfor the index (at least until Valkey gets its own semconv definition)? Otherwise users may face a breaking change if/when semconv does definedb.valkey.*attributes differently.
There was a problem hiding this comment.
-
You're right,
valkeyis 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 addingvalkeyas adb.systemvalue. In the meantime, since Valkey is a Redis fork with its own identity and roadmap, I think usingvalkeyis the right direction — but happy to discuss. -
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
- (a): Reuse Redis attributes (
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
MikeGoldsmith
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
net.transport has been deprecated, let's not introduce it.
…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
MikeGoldsmith
left a comment
There was a problem hiding this comment.
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.
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:
valkey-searchmodule is not yet GA, related tests are intentionally omitted in this PR.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
instrumentation/opentelemetry-instrumentation-valkey/tests/covering:db.statement,db.valkey.args_length,db.valkey.database_index,net.peer.name)opentelemetry-instrumentation-valkey, verified spans in Jaeger backendtox -e py38-test-instrumentation-valkeytox -e py39-test-instrumentation-valkeytox -e py310-test-instrumentation-valkeytox -e py311-test-instrumentation-valkeytox -e py312-test-instrumentation-valkeytox -e py313-test-instrumentation-valkeytox -e pypy3-test-instrumentation-valkeytox -e lint-instrumentation-valkeyDoes This PR Require a Core Repo Change?
Checklist:
CHANGELOG.mdentry under “New Features”)