{"library":"opentelemetry-instrumentation-pymssql","title":"OpenTelemetry pymssql Instrumentation","description":"This library provides OpenTelemetry instrumentation for `pymssql`, a Python wrapper for FreeTDS that enables interaction with Microsoft SQL Server. It automatically creates spans for database connection and query operations, helping to trace SQL interactions within your application. The current version is 0.62b0, and it's released as part of the `opentelemetry-python-contrib` project, which has a frequent release cadence.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install opentelemetry-instrumentation-pymssql pymssql"],"cli":null},"imports":["from opentelemetry.instrumentation.pymssql import PymssqlInstrumentor"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport pymssql\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.pymssql import PymssqlInstrumentor\n\n# 1. Configure OpenTelemetry Tracer Provider\nresource = Resource.create({\"service.name\": \"pymssql-example\"})\nprovider = TracerProvider(resource=resource)\nprocessor = SimpleSpanProcessor(ConsoleSpanExporter())\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\n# 2. Instrument pymssql\nPymssqlInstrumentor().instrument()\n\n# 3. Use pymssql normally\n# Replace with your actual MSSQL connection details or use environment variables\nserver = os.environ.get(\"MSSQL_SERVER\", \"your_server.database.windows.net\")\nuser = os.environ.get(\"MSSQL_USER\", \"your_username\")\npassword = os.environ.get(\"MSSQL_PASSWORD\", \"your_password\")\ndatabase = os.environ.get(\"MSSQL_DATABASE\", \"your_database\")\n\nif not all([server, user, password, database]):\n    print(\"WARNING: Skipping pymssql connection as environment variables for MSSQL_SERVER, MSSQL_USER, MSSQL_PASSWORD, MSSQL_DATABASE are not set.\")\n    print(\"Please set these to run the quickstart.\")\nelse:\n    print(f\"Attempting to connect to MSSQL: {server}/{database} with user {user}...\")\n    try:\n        with pymssql.connect(server, user, password, database) as conn:\n            with conn.cursor() as cursor:\n                cursor.execute('SELECT 1 as result')\n                row = cursor.fetchone()\n                print(f\"Query result: {row}\")\n        print(\"pymssql connection and query successful (and instrumented!). Check console for OTel traces.\")\n    except Exception as e:\n        print(f\"Error connecting to or querying MSSQL: {e}\")\n        print(\"Ensure MSSQL server is accessible and credentials are correct.\")","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"0.62b1","pypi_latest":"0.62b1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.8,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"31.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":"31M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"33.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.8,"import_time_s":null,"mem_mb":null,"disk_size":"33M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.4,"import_time_s":null,"mem_mb":null,"disk_size":"25M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.5,"import_time_s":null,"mem_mb":null,"disk_size":"25M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"31.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"opentelemetry-instrumentation-pymssql","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.3,"import_time_s":null,"mem_mb":null,"disk_size":"31M"}]}}