Skip to content

Add Valkey Instrumentation#3478

Open
sightseeker wants to merge 38 commits into
open-telemetry:mainfrom
sightseeker:feature/valkey
Open

Add Valkey Instrumentation#3478
sightseeker wants to merge 38 commits into
open-telemetry:mainfrom
sightseeker:feature/valkey

Conversation

@sightseeker

@sightseeker sightseeker commented May 8, 2025

Copy link
Copy Markdown

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

linux-foundation-easycla Bot commented May 8, 2025

Copy link
Copy Markdown

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.

@sightseeker sightseeker May 16, 2025

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.

@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
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>
- Bump valkey requires-python to >=3.10 and remove 3.9 classifier/tox factor
- Remove unreachable return statement after warning in uninstrument_client
- Add redis-valkey-base to opentelemetry-contrib-instrumentations
- Update bootstrap_gen with redis-valkey-base and bump valkey to 0.63b0.dev
- Migrate redis/valkey docker functional tests to SERVER_ADDRESS/SERVER_PORT
- Update valkey docker tests to use db.redis.* attributes per semconv decision
@sightseeker

Copy link
Copy Markdown
Author

Thanks @tammy-baylis-swi! Done — dropped Python 3.9 from the valkey and redis-valkey-base packages (requires-python, classifiers, tox factor, and the core_contrib workflow) in 71d14f1 and 6888ed9. I've also merged latest main to pick up the project-wide 3.9 drop.

; Conflicts:
;	CHANGELOG.md
;	tests/opentelemetry-docker-tests/tests/check_availability.py
; Conflicts:
;	tests/opentelemetry-docker-tests/tests/test-requirements.txt
@emdneto

emdneto commented May 12, 2026

Copy link
Copy Markdown
Member

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

; Conflicts:
;	instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py
;	instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py
@sightseeker

Copy link
Copy Markdown
Author

Thanks for the heads-up about towncrier! I've added a changelog fragment at .changelog/3478.added and removed the manual CHANGELOG.md entries.

I also had to deal with a large merge conflict from the upstream Redis semconv stability migration (#4370).

Integrating it into the shared base package would be a sizable refactor that significantly expands the scope of this PR, so for now I've kept Redis on the upstream version and the shared base package is only used by Valkey.

I'd like to revisit consolidating Redis into the shared base in a follow-up PR after this one lands, does that work for you?

@tammy-baylis-swi

Copy link
Copy Markdown
Contributor

I also had to deal with a large merge conflict from the upstream Redis semconv stability migration (#4370).

Thank you, that was mine so I appreciate it 🙂

I'd like to revisit consolidating Redis into the shared base in a follow-up PR after this one lands, does that work for you?

That works for me.

Not sure what happened with the most recent merge but some calls need to be run again please:

  • tox -e generate
  • tox -e generate-workflows
  • tox -e precommit

Run tox -e generate and tox -e generate-workflows to:
- Add redis-valkey-base entry to instrumentation/README.md
- Regenerate test.yml and core_contrib_test.yml with valkey jobs
- Update lint.yml with valkey lint env
- Refresh uv.lock
@sightseeker

Copy link
Copy Markdown
Author

@tammy-baylis-swi
Done! Ran tox -e generate, tox -e generate-workflows, and tox -e precommit — the regenerated workflows, README, bootstrap_gen, and uv.lock are in acc6cae.

@github-actions

github-actions Bot commented Jun 1, 2026

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 Jun 1, 2026
; Conflicts:
;	opentelemetry-contrib-instrumentations/pyproject.toml
;	opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
;	tests/opentelemetry-docker-tests/tests/test-requirements.txt
@sightseeker

Copy link
Copy Markdown
Author

Hi @tammy-baylis-swi! I've resolved the latest merge conflicts with main and bumped the valkey/redis-valkey-base packages to 0.64b0.dev to match the new release. Would you mind taking another look when you have a chance? 🙏

@github-actions github-actions Bot removed the Stale label Jun 2, 2026
…headers

Replace the full Apache 2.0 license boilerplate with the one-line
SPDX identifier on all newly added Python files, following the
repository-wide migration in open-telemetry#4533.

@tammy-baylis-swi tammy-baylis-swi left a comment

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! This lgtm.

The check-links will fail until the first readthedocs publish. PyPI publish destination was sorted a while ago. @sightseeker is on the component_owners list and has actively worked hard on this for a while.

More Approvers will also have to take a look.

@tammy-baylis-swi tammy-baylis-swi moved this from Approved PRs that need fixes to Approved PRs in Python PR digest Jun 9, 2026
@sightseeker

Copy link
Copy Markdown
Author

A big thank you to @tammy-baylis-swi for the approval 🙏

@xrmx, @fabiob, @MikeGoldsmith , @zhengkezhou1
This PR adds Valkey instrumentation to the Python contrib library, filling a gap for users who have migrated from Redis to Valkey. One approval has already been given, and we need two more to move forward.

Would any of you be able to take another look when you have a moment? I'm happy to clarify anything or make further adjustments. Thanks so much for your time!

# SPDX-License-Identifier: Apache-2.0
#
"""
Shared instrumentation base for Redis and 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.

I am very late to the discussion but wondering if instead we should not move this helpers in opentelemetry-instrumentation instead so that we can reuse them more generally. I'm not asking to move code just to start a discussion.

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.

Also if we are introducing some helpers they should be used by both instrumentations and not just by one.


_BACKEND_NAME = "valkey"
_DB_SYSTEM = "valkey"
_DB_SYSTEM_ATTR = DB_SYSTEM

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.

Looks like this is implementing the old semconv, I'm not sure we should introduce new instrumentations with outdated semconv if there's a stable one available. Redis instrumentation got updated in 0059b27

@github-project-automation github-project-automation Bot moved this from Approved PRs to Reviewed PRs that need fixes in Python PR digest Jun 23, 2026
Migrate the Valkey instrumentation (and the shared redis-valkey-base
helpers) to support the new stable DB and HTTP semantic conventions
via OTEL_SEMCONV_STABILITY_OPT_IN, mirroring what was done for Redis
in open-telemetry#4370.

- redis-valkey-base: switch helpers to use _semconv stability helpers
  (_set_db_system, _set_db_statement, _set_db_redis_database_index,
  _set_http_net_peer_name_client, _set_http_peer_port_client,
  _set_net_transport) and resolve schema_url via signal-type opt-in
- valkey: drop hardcoded attribute keys from KVStoreConfig, mark
  package as semconv migration, switch tracer schema_url to the
  stability-aware helper
- tests: cover default / database / database/dup / http / http/dup
  stability modes for db.system, db.statement and connection attrs
@github-actions

github-actions Bot commented Jul 8, 2026

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 Jul 8, 2026
@xrmx xrmx removed the Stale label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.