Registry /
observability / opentelemetry-instrumentation-pymssql
Install & Compatibility
Where this runs
tested against v0.63b1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.6MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
PymssqlInstrumentor
✓ from opentelemetry.instrumentation.pymssql import PymssqlInstrumentor
This quickstart demonstrates how to set up OpenTelemetry with `pymssql` instrumentation. It configures a basic `TracerProvider` with a `ConsoleSpanExporter`, instruments `pymssql`, and then performs a sample database connection and query. Remember to replace placeholder credentials or set corresponding environment variables for a runnable example.
import os
import pymssql
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.instrumentation.pymssql import PymssqlInstrumentor
# 1. Configure OpenTelemetry Tracer Provider
resource = Resource.create({"service.name": "pymssql-example"})
provider = TracerProvider(resource=resource)
processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
# 2. Instrument pymssql
PymssqlInstrumentor().instrument()
# 3. Use pymssql normally
# Replace with your actual MSSQL connection details or use environment variables
server = os.environ.get("MSSQL_SERVER", "your_server.database.windows.net")
user = os.environ.get("MSSQL_USER", "your_username")
password = os.environ.get("MSSQL_PASSWORD", "your_password")
database = os.environ.get("MSSQL_DATABASE", "your_database")
if not all([server, user, password, database]):
print("WARNING: Skipping pymssql connection as environment variables for MSSQL_SERVER, MSSQL_USER, MSSQL_PASSWORD, MSSQL_DATABASE are not set.")
print("Please set these to run the quickstart.")
else:
print(f"Attempting to connect to MSSQL: {server}/{database} with user {user}...")
try:
with pymssql.connect(server, user, password, database) as conn:
with conn.cursor() as cursor:
cursor.execute('SELECT 1 as result')
row = cursor.fetchone()
print(f"Query result: {row}")
print("pymssql connection and query successful (and instrumented!). Check console for OTel traces.")
except Exception as e:
print(f"Error connecting to or querying MSSQL: {e}")
print("Ensure MSSQL server is accessible and credentials are correct.")
Debug
Known issues
gotchaThis instrumentation is in 'beta' (indicated by 'b' in version number, e.g., 0.62b0). While functional, its API or behavior might undergo minor changes in future releases before reaching a stable version.fixReview release notes for each update and test thoroughly, especially if upgrading across minor beta versions.
affects: All versions below 1.0.0
gotchaThe `pymssql` library itself must be installed separately from `opentelemetry-instrumentation-pymssql`. The instrumentation package does not automatically install `pymssql` as a dependency.fixEnsure `pip install pymssql` is run in your environment before attempting to use the instrumentation.
affects: All versions
gotchaInstrumentation occurs globally: calling `PymssqlInstrumentor().instrument()` will patch all subsequent `pymssql` connections and queries within the current process. Ensure this is done early in your application's lifecycle.fixCall `PymssqlInstrumentor().instrument()` once during application startup, typically after OpenTelemetry SDK configuration.
affects: All versions
gotchaFor traces to be visible, you must correctly configure a `TracerProvider` and add a `SpanProcessor` with an appropriate `SpanExporter` (e.g., `ConsoleSpanExporter`, `OTLPSpanExporter`). Without this setup, instrumentation will run, but no telemetry data will be emitted.fixRefer to the quickstart example and OpenTelemetry documentation for setting up a `TracerProvider` and `SpanExporter`.
affects: All versions
Upgrade
Version history
0.63b1latest on PyPI · released May 21, 2026
Audit
Dependencies
pymssqlrequiredThe database driver being instrumented. Must be installed separately.
opentelemetry-apirequiredCore OpenTelemetry API for defining tracing concepts.
opentelemetry-sdkrequiredOpenTelemetry SDK for processing and exporting telemetry data.