Skip to content

Commit

Permalink
Add pymssql instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumep committed Jan 24, 2025
1 parent 2756c1e commit ea5ff11
Show file tree
Hide file tree
Showing 21 changed files with 946 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ components:
instrumentation/opentelemetry-instrumentation-psycopg:
- federicobond

instrumentation/opentelemetry-instrumentation-pymssql:
- guillaumep

instrumentation/opentelemetry-instrumentation-aiokafka:
- dimastbk

Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/lint_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,24 @@ jobs:
- name: Run tests
run: tox -e lint-instrumentation-pymysql

lint-instrumentation-pymssql:
name: instrumentation-pymssql
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e lint-instrumentation-pymssql

lint-instrumentation-pyramid:
name: instrumentation-pyramid
runs-on: ubuntu-latest
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/test_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,114 @@ jobs:
- name: Run tests
run: tox -e pypy3-test-instrumentation-pymysql -- -ra

py38-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.8 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py38-test-instrumentation-pymssql -- -ra

py39-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.9 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py39-test-instrumentation-pymssql -- -ra

py310-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.10 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py310-test-instrumentation-pymssql -- -ra

py311-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py311-test-instrumentation-pymssql -- -ra

py312-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py312-test-instrumentation-pymssql -- -ra

py313-test-instrumentation-pymssql_ubuntu-latest:
name: instrumentation-pymssql 3.13 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -e py313-test-instrumentation-pymssql -- -ra

py38-test-instrumentation-pyramid_ubuntu-latest:
name: instrumentation-pyramid 3.8 Ubuntu
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3161](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3161))
- `opentelemetry-opentelemetry-botocore` Add basic support for GenAI attributes for AWS Bedrock InvokeModel API
([#3200](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3200))
- `opentelemetry-instrumentation-pymssql` Add pymssql instrumentation
([#394](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/394))

### Fixed

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


### Breaking changes

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


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

### Added
Expand Down
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ psycopg~=3.1.17
pika>=0.12.0
pymongo~=4.6.3
PyMySQL~=1.1.1
pymssql~=2.3.2
pyramid>=1.7
redis>=2.6
remoulade>=0.50
Expand Down
7 changes: 7 additions & 0 deletions docs/instrumentation/pymssql/pymssql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry pymssql Instrumentation
=====================================

.. automodule:: opentelemetry.instrumentation.pymssql
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1,psycopg2-binary >= 2.7.3.1 | No | experimental
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 5 | No | experimental
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No | experimental
| [opentelemetry-instrumentation-pymssql](./opentelemetry-instrumentation-pymssql) | pymssql >= 2, < 3 | No | experimental
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No | experimental
| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | Yes | experimental
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | No | experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ def instrument_connection(
commenter_options: dict[str, Any] | None = None,
connect_module: Callable[..., Any] | None = None,
enable_attribute_commenter: bool = False,
db_api_integration_factory: type[DatabaseApiIntegration] | None = None,
) -> TracedConnectionProxy[ConnectionT]:
"""Enable instrumentation in a database connection.
Args:
name: The instrumentation module name.
connection: The connection to instrument.
database_system: An identifier for the database management system (DBMS)
product being used.
Expand All @@ -220,6 +222,10 @@ def instrument_connection(
commenter_options: Configurations for tags to be appended at the sql query.
connect_module: Module name where connect method is available.
enable_attribute_commenter: Flag to enable/disable sqlcomment inclusion in `db.statement` span attribute. Only available if enable_commenter=True.
db_api_integration_factory: A class or factory function to use as a
replacement for :class:`DatabaseApiIntegration`. Can be used to
obtain connection attributes from the connect method instead of
from the connection itself (as done by the pymssql intrumentor).
Returns:
An instrumented connection.
Expand All @@ -228,7 +234,11 @@ def instrument_connection(
_logger.warning("Connection already instrumented")
return connection

db_integration = DatabaseApiIntegration(
db_api_integration_factory = (
db_api_integration_factory or DatabaseApiIntegration
)

db_integration = db_api_integration_factory(
name,
database_system,
connection_attributes=connection_attributes,
Expand Down
Loading

0 comments on commit ea5ff11

Please sign in to comment.