Skip to content

Commit a6c7885

Browse files
committed
Add pymssql instrumentation
1 parent 2756c1e commit a6c7885

File tree

21 files changed

+950
-47
lines changed

21 files changed

+950
-47
lines changed

.github/component_owners.yml

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ components:
6161
instrumentation/opentelemetry-instrumentation-psycopg:
6262
- federicobond
6363

64+
instrumentation/opentelemetry-instrumentation-pymssql:
65+
- guillaumep
66+
6467
instrumentation/opentelemetry-instrumentation-aiokafka:
6568
- dimastbk
6669

.github/workflows/lint_0.yml

+18
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,24 @@ jobs:
664664
- name: Run tests
665665
run: tox -e lint-instrumentation-pymysql
666666

667+
lint-instrumentation-pymssql:
668+
name: instrumentation-pymssql
669+
runs-on: ubuntu-latest
670+
steps:
671+
- name: Checkout repo @ SHA - ${{ github.sha }}
672+
uses: actions/checkout@v4
673+
674+
- name: Set up Python 3.13
675+
uses: actions/setup-python@v5
676+
with:
677+
python-version: "3.13"
678+
679+
- name: Install tox
680+
run: pip install tox-uv
681+
682+
- name: Run tests
683+
run: tox -e lint-instrumentation-pymssql
684+
667685
lint-instrumentation-pyramid:
668686
name: instrumentation-pyramid
669687
runs-on: ubuntu-latest

.github/workflows/test_1.yml

+108
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,114 @@ jobs:
23382338
- name: Run tests
23392339
run: tox -e pypy3-test-instrumentation-pymysql -- -ra
23402340

2341+
py38-test-instrumentation-pymssql_ubuntu-latest:
2342+
name: instrumentation-pymssql 3.8 Ubuntu
2343+
runs-on: ubuntu-latest
2344+
steps:
2345+
- name: Checkout repo @ SHA - ${{ github.sha }}
2346+
uses: actions/checkout@v4
2347+
2348+
- name: Set up Python 3.8
2349+
uses: actions/setup-python@v5
2350+
with:
2351+
python-version: "3.8"
2352+
2353+
- name: Install tox
2354+
run: pip install tox-uv
2355+
2356+
- name: Run tests
2357+
run: tox -e py38-test-instrumentation-pymssql -- -ra
2358+
2359+
py39-test-instrumentation-pymssql_ubuntu-latest:
2360+
name: instrumentation-pymssql 3.9 Ubuntu
2361+
runs-on: ubuntu-latest
2362+
steps:
2363+
- name: Checkout repo @ SHA - ${{ github.sha }}
2364+
uses: actions/checkout@v4
2365+
2366+
- name: Set up Python 3.9
2367+
uses: actions/setup-python@v5
2368+
with:
2369+
python-version: "3.9"
2370+
2371+
- name: Install tox
2372+
run: pip install tox-uv
2373+
2374+
- name: Run tests
2375+
run: tox -e py39-test-instrumentation-pymssql -- -ra
2376+
2377+
py310-test-instrumentation-pymssql_ubuntu-latest:
2378+
name: instrumentation-pymssql 3.10 Ubuntu
2379+
runs-on: ubuntu-latest
2380+
steps:
2381+
- name: Checkout repo @ SHA - ${{ github.sha }}
2382+
uses: actions/checkout@v4
2383+
2384+
- name: Set up Python 3.10
2385+
uses: actions/setup-python@v5
2386+
with:
2387+
python-version: "3.10"
2388+
2389+
- name: Install tox
2390+
run: pip install tox-uv
2391+
2392+
- name: Run tests
2393+
run: tox -e py310-test-instrumentation-pymssql -- -ra
2394+
2395+
py311-test-instrumentation-pymssql_ubuntu-latest:
2396+
name: instrumentation-pymssql 3.11 Ubuntu
2397+
runs-on: ubuntu-latest
2398+
steps:
2399+
- name: Checkout repo @ SHA - ${{ github.sha }}
2400+
uses: actions/checkout@v4
2401+
2402+
- name: Set up Python 3.11
2403+
uses: actions/setup-python@v5
2404+
with:
2405+
python-version: "3.11"
2406+
2407+
- name: Install tox
2408+
run: pip install tox-uv
2409+
2410+
- name: Run tests
2411+
run: tox -e py311-test-instrumentation-pymssql -- -ra
2412+
2413+
py312-test-instrumentation-pymssql_ubuntu-latest:
2414+
name: instrumentation-pymssql 3.12 Ubuntu
2415+
runs-on: ubuntu-latest
2416+
steps:
2417+
- name: Checkout repo @ SHA - ${{ github.sha }}
2418+
uses: actions/checkout@v4
2419+
2420+
- name: Set up Python 3.12
2421+
uses: actions/setup-python@v5
2422+
with:
2423+
python-version: "3.12"
2424+
2425+
- name: Install tox
2426+
run: pip install tox-uv
2427+
2428+
- name: Run tests
2429+
run: tox -e py312-test-instrumentation-pymssql -- -ra
2430+
2431+
py313-test-instrumentation-pymssql_ubuntu-latest:
2432+
name: instrumentation-pymssql 3.13 Ubuntu
2433+
runs-on: ubuntu-latest
2434+
steps:
2435+
- name: Checkout repo @ SHA - ${{ github.sha }}
2436+
uses: actions/checkout@v4
2437+
2438+
- name: Set up Python 3.13
2439+
uses: actions/setup-python@v5
2440+
with:
2441+
python-version: "3.13"
2442+
2443+
- name: Install tox
2444+
run: pip install tox-uv
2445+
2446+
- name: Run tests
2447+
run: tox -e py313-test-instrumentation-pymssql -- -ra
2448+
23412449
py38-test-instrumentation-pyramid_ubuntu-latest:
23422450
name: instrumentation-pyramid 3.8 Ubuntu
23432451
runs-on: ubuntu-latest

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4545
([#3161](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3161))
4646
- `opentelemetry-opentelemetry-botocore` Add basic support for GenAI attributes for AWS Bedrock InvokeModel API
4747
([#3200](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3200))
48+
- `opentelemetry-instrumentation-pymssql` Add pymssql instrumentation
49+
([#394](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/394))
4850

4951
### Fixed
5052

@@ -67,15 +69,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6769
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in
6870
([#3115](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3115))
6971

70-
7172
### Breaking changes
7273

7374
- `opentelemetry-instrumentation-dbapi` including sqlcomment in `db.statement` span attribute value is now opt-in
7475
([#3115](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3115))
7576
- `opentelemetry-instrumentation-psycopg2`, `opentelemetry-instrumentation-psycopg`, `opentelemetry-instrumentation-mysqlclient`, `opentelemetry-instrumentation-pymysql`: including sqlcomment in `db.statement` span attribute value is now opt-in
7677
([#3121](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3121))
7778

78-
7979
## Version 1.29.0/0.50b0 (2024-12-11)
8080

8181
### Added

docs-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ psycopg~=3.1.17
3535
pika>=0.12.0
3636
pymongo~=4.6.3
3737
PyMySQL~=1.1.1
38+
pymssql~=2.3.2
3839
pyramid>=1.7
3940
redis>=2.6
4041
remoulade>=0.50
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry pymssql Instrumentation
2+
=====================================
3+
4+
.. automodule:: opentelemetry.instrumentation.pymssql
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

instrumentation/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1,psycopg2-binary >= 2.7.3.1 | No | experimental
3636
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 5 | No | experimental
3737
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No | experimental
38+
| [opentelemetry-instrumentation-pymssql](./opentelemetry-instrumentation-pymssql) | pymssql >= 2, < 3 | No | experimental
3839
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No | experimental
3940
| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | Yes | experimental
4041
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | No | experimental

instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ def instrument_connection(
204204
commenter_options: dict[str, Any] | None = None,
205205
connect_module: Callable[..., Any] | None = None,
206206
enable_attribute_commenter: bool = False,
207+
db_api_integration_factory: type[DatabaseApiIntegration] | None = None,
207208
) -> TracedConnectionProxy[ConnectionT]:
208209
"""Enable instrumentation in a database connection.
209210
210211
Args:
212+
name: The instrumentation module name.
211213
connection: The connection to instrument.
212214
database_system: An identifier for the database management system (DBMS)
213215
product being used.
@@ -220,6 +222,10 @@ def instrument_connection(
220222
commenter_options: Configurations for tags to be appended at the sql query.
221223
connect_module: Module name where connect method is available.
222224
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
225+
db_api_integration_factory: A class or factory function to use as a
226+
replacement for :class:`DatabaseApiIntegration`. Can be used to
227+
obtain connection attributes from the connect method instead of
228+
from the connection itself (as done by the pymssql intrumentor).
223229
224230
Returns:
225231
An instrumented connection.
@@ -228,7 +234,11 @@ def instrument_connection(
228234
_logger.warning("Connection already instrumented")
229235
return connection
230236

231-
db_integration = DatabaseApiIntegration(
237+
db_api_integration_factory = (
238+
db_api_integration_factory or DatabaseApiIntegration
239+
)
240+
241+
db_integration = db_api_integration_factory(
232242
name,
233243
database_system,
234244
connection_attributes=connection_attributes,

0 commit comments

Comments
 (0)