Skip to content

Add pymssql instrumentation - #893

Open
pvital wants to merge 3 commits into
mainfrom
pymssql_instrumentation
Open

Add pymssql instrumentation#893
pvital wants to merge 3 commits into
mainfrom
pymssql_instrumentation

Conversation

@pvital

@pvital pvital commented Aug 20, 2026

Copy link
Copy Markdown
Member

This PR adds pymssql instrumentation for Microsoft SQL Server, along with tests and CI updates to test it.

  • Add src/instana/instrumentation/pymssql.py: patches pymssql.connect(and the Connect alias) via the shared ConnectionFactory with module_name="mssql"
  • Extend CursorWrapper._collect_kvs in pep0249.py: host now falls back from 'host' to 'server' kwarg (pymssql uses server=)
  • Add "mssql" to EXIT_SPANS tuple in span/kind.py (alphabetical order)
  • Add _collect_mssql_attributes method to RegisteredSpan and wire it into _populate_exit_span_data after the mysql branch
  • Register pymssql module in boot_agent() import block
  • Add tests/clients/test_pymssql.py: TestPyMSSQL class with autouse fixture that skips gracefully when SQL Server is unreachable; covers all three user stories:
    • US1: vanilla query, basic query, root exit span, parametrized DML statement attributes, cursor context manager
    • US2: parametrized error capture (syntax error, missing table), no-error-on-success assertion
    • US3: executemany parametrized across 2-row and 5-row batches
    • SQLAlchemy bypass (no double-span)
  • Add mssql_* keys to tests/helpers.py (MSSQL_HOST/PORT/DATABASE/USER/SA_PASSWORD env vars, defaults to 127.0.0.1:1433)
  • Add pymssql>=2.2.0 to tests/requirements.txt
  • Add the mcr.microsoft.com/azure-sql-edge container image into docker-compose.yml for local testing.
  • Add the mcr.microsoft.com/mssql/server:2022-latest container image into the CircleCI configuration for testing across all Python versions.

pvital added 3 commits August 20, 2026 06:07
- Add src/instana/instrumentation/pymssql.py: patches pymssql.connect
  (and Connect alias) via the shared ConnectionFactory with
  module_name="mssql"
- Extend CursorWrapper._collect_kvs in pep0249.py: host now falls
  back from 'host' to 'server' kwarg (pymssql uses server=); port
  defaults to 1433 when not supplied
- Add "mssql" to EXIT_SPANS tuple in span/kind.py (alphabetical order)
- Add _collect_mssql_attributes method to RegisteredSpan and wire it
  into _populate_exit_span_data after the mysql branch
- Register pymssql module in boot_agent() import block

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
- Add tests/clients/test_pymssql.py: TestPyMSSQL class with autouse
  fixture that skips gracefully when SQL Server is unreachable;
  covers all three user stories:
  - US1: vanilla query, basic query, root exit span, parametrized
    DML statement attributes, cursor context manager
  - US2: parametrized error capture (syntax error, missing table),
    no-error-on-success assertion
  - US3: executemany parametrized across 2-row and 5-row batches
  - SQLAlchemy bypass (no double-span)
- Add mssql_* keys to tests/helpers.py (MSSQL_HOST/PORT/DATABASE/
  USER/SA_PASSWORD env vars, defaults to 127.0.0.1:1433)
- Add pymssql>=2.2.0 to tests/requirements.txt

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
@pvital
pvital requested a review from a team as a code owner August 20, 2026 13:17
@pvital pvital self-assigned this Aug 20, 2026

@GSVarsha GSVarsha 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.

Looks good to me!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants