Skip to content

opentelemetry-instrumentation-mysql: add semconv stability opt-in test coverage#4810

Open
anneheartrecord wants to merge 2 commits into
open-telemetry:mainfrom
anneheartrecord:tests/mysql-semconv-modes
Open

opentelemetry-instrumentation-mysql: add semconv stability opt-in test coverage#4810
anneheartrecord wants to merge 2 commits into
open-telemetry:mainfrom
anneheartrecord:tests/mysql-semconv-modes

Conversation

@anneheartrecord

Copy link
Copy Markdown

Description

The mysql instrumentation delegates span creation to the shared dbapi layer, which already handles the database semconv stability migration (#4109). However, unlike pymssql (#4592), the mysql test suite had no coverage of the OTEL_SEMCONV_STABILITY_OPT_IN modes, so regressions in what the instrumentation emits per mode would go unnoticed.

This adds two tests mirroring the merged pymssql pattern:

  • test_semconv_stable (database,http): asserts only stable attributes are emitted (db.system.name, db.namespace, db.query.text, server.address, server.port) and legacy ones (db.system, db.name, db.statement, db.user, net.peer.*) are absent
  • test_semconv_dup (database/dup,http/dup): asserts both legacy and stable attributes are emitted

Verified locally that the current dbapi-based behavior matches the database semconv spec in default, stable and dup modes.

Fixes #1632

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • pytest instrumentation/opentelemetry-instrumentation-mysql/tests/ — 17 passed (15 existing + 2 new)
  • ruff check / ruff format --check (ruff 0.14.1) — clean

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (not required: test-only change, no behavior impact)
  • Unit tests have been added
  • Documentation has been updated (not required)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d8cc31a3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds missing test coverage in the MySQL instrumentation package to ensure DB-API–driven semantic convention stability behavior remains correct across OTEL_SEMCONV_STABILITY_OPT_IN modes, preventing regressions in emitted span attributes.

Changes:

  • Added a small helper context manager to set OTEL_SEMCONV_STABILITY_OPT_IN and reset the semconv stability cache for deterministic tests.
  • Added two integration tests verifying attribute output for database,http (stable-only keys) and database/dup,http/dup (stable + legacy keys).
  • Extended the MySQL connection mock to include a user value so db.user behavior can be asserted in dup mode.

@xrmx xrmx moved this to Easy to review / merge / close in Python PR digest Jul 13, 2026
@xrmx

xrmx commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@anneheartrecord please add a changelog entry in .changelog/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Easy to review / merge / close

Development

Successfully merging this pull request may close these issues.

Make sure mysql instrumentation follows semantic conventions

3 participants