Skip to content

DB and HTTP semantic convention stability migration for Redis instrumentation#4370

Open
tammy-baylis-swi wants to merge 22 commits intoopen-telemetry:mainfrom
tammy-baylis-swi:redis-semconv-opt-in
Open

DB and HTTP semantic convention stability migration for Redis instrumentation#4370
tammy-baylis-swi wants to merge 22 commits intoopen-telemetry:mainfrom
tammy-baylis-swi:redis-semconv-opt-in

Conversation

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Mar 27, 2026

Description

Add Redis instrumentor support for when OTEL_SEMCONV_STABILITY_OPT_IN includes

  • "database" or "database/dup"
  • "http" or "http/dup"

EDIT: This uses now-merged updates from SQLAlchemy PR, no conflicts 🙂 This duplicates all _semconv helper updates in #4110 at 02adc40

Fixes #2930, #2885

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

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • 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

pluggy==1.6.0
py-cpuinfo==9.0.0
pytest==7.4.4
pytest-asyncio==0.23.5
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 1c7e3cc so Python 3.9 tests pass, else RuntimeError: There is no current event loop in thread 'MainThread'.

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.

do we still need that after dropping py39?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope! 🎉 Removed in 961bab7

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.

Looks good - thanks @tammy-baylis-swi.

Left some queries about some semconv keys and a couple of suggestions.

)

db = conn_kwargs.get("db", 0)
attributes[DB_REDIS_DATABASE_INDEX] = db
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.

I think db.redis.database_index became db.namespace - do we have a set helper that can use old/new/dual write for these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry it's taken me a while to get back into this one!

@MikeGoldsmith it looks like db.redis.database_index is deprecated with no replacement in semconv 1.38.0 (PR). So my interpretation is that old semconv should write the old attribute, and new should write no attribute. While the attribute is only used by the Redis instrumentation, I've put a helper in _semconv.py in 1d9f2a0 for consistency. It does not set any attribute if "new" semconv. Lmk what you think!

_set_http_net_peer_name_client(
attributes, conn_kwargs.get("path", ""), http_sem_conv_opt_in_mode
)
attributes[NET_TRANSPORT] = NetTransportValues.OTHER.value
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.

I think net.transport has been deprecated - should we drop this in stable mode?

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. maybe just set if _report_old()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In 54881b8 I've added _set_net_transport helper for old/new/dup. I think the current trail from old net.transport goes to "deprecated" network.transport then "final" network.transport, so it's got both a _report_old() and _report_new(). Lmk your thoughts!

conn_kwargs.get("port", 6379),
http_sem_conv_opt_in_mode,
)
attributes[NET_TRANSPORT] = NetTransportValues.IP_TCP.value
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.

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Relates to 54881b8

self.assertEqual(span.status.status_code, trace.StatusCode.UNSET)


class TestRedisSemconvConfiguration(TestRedis):
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.

Do we need to inherit TestRedis or could we use TestBase? I think we'll re-run all the stuff in TestRedis like this.

I think we're missing the async tests for _async_traced_execute_factory and _async_traced_execute_pipeline_factory too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 732d1e7!

response_hook: ResponseHook | None = None,
):
# Get semconv opt-in modes for database and HTTP signal types
_OpenTelemetrySemanticConventionStability._initialize()
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.

These are duplicated across all four factories, should we add a helper?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call! Added helper in b1fde84 within Redis instrumentation.

If this gets merged I may put in another PR later to house it in _semconv.py because SQLAlchemy instrumentation could benefit from it too (duplication added in this PR).

@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Apr 23, 2026
self.assertEqual(len(spans), 1)

span = spans[0]
self.assertIn(DB_STATEMENT, span.attributes)
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.

can we assert db.system.name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think addressed in 23280ae plus more asserts in 34de467 but GH has been fussy for me all day 😵 LMK if needed in a different test function too.

pluggy==1.6.0
py-cpuinfo==9.0.0
pytest==7.4.4
pytest-asyncio==0.23.5
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.

do we still need that after dropping py39?

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor Author

Please pardon my delay in addressing your feedback @emdneto and @MikeGoldsmith ! Please could you take another pass through this one for Redis instrumentation and semconv opt-in.

Current CI/CD failures for precommit "rstcheck" seem unrelated and present in other PRs:

rstcheck.................................................................Failed
- hook id: rstcheck
- exit code: 1

_template/autodoc_entry.rst:1: (SEVERE/4) File referenced in "include" directive not found: '../../../instrumentation/opentelemetry-instrumentation-<REPLACE ME>/README.rst'.

@emdneto
Copy link
Copy Markdown
Member

emdneto commented May 5, 2026

Please pardon my delay in addressing your feedback @emdneto and @MikeGoldsmith ! Please could you take another pass through this one for Redis instrumentation and semconv opt-in.

Current CI/CD failures for precommit "rstcheck" seem unrelated and present in other PRs:

rstcheck.................................................................Failed
- hook id: rstcheck
- exit code: 1

_template/autodoc_entry.rst:1: (SEVERE/4) File referenced in "include" directive not found: '../../../instrumentation/opentelemetry-instrumentation-<REPLACE ME>/README.rst'.

Np. I realized I left a pending review since last month 😅 Looking into the rstcheck error

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.

opentelemetry-instrumentation-redis: semantic convention stability migration

3 participants