Skip to content

Commit a0d0cbd

Browse files
authored
Merge branch 'main' into add-type-hints-to-sqlite3
2 parents a5b2a7f + 9cf2683 commit a0d0cbd

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646
([#3022](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3022))
4747
- Replace all instrumentor unit test `assertEqualSpanInstrumentationInfo` calls with `assertEqualSpanInstrumentationScope` calls
4848
([#3037](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3037))
49+
- `opentelemetry-instrumentation-sqlalchemy` Fixes engines from `sqlalchemy.engine_from_config` not being fully instrumented
50+
([#2816](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2816))
4951
- `opentelemetry-instrumentation-sqlalchemy`: Fix a remaining memory leak in EngineTracer
5052
([#3053](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3053))
5153

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ Below is a checklist of things to be mindful of when implementing a new instrume
272272
- Isolate sync and async test
273273
- For synchronous tests, the typical test case class is inherited from `opentelemetry.test.test_base.TestBase`. However, if you want to write asynchronous tests, the test case class should inherit also from `IsolatedAsyncioTestCase`. Adding asynchronous tests to a common test class can lead to tests passing without actually running, which can be misleading.
274274
- ex. <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/60fb936b7e5371b3e5587074906c49fb873cbd76/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py#L84>
275-
- All instrumentations have the same version. If you are going to develop a new instrumentation it would probably have `X.Y.dev` version and depends on `opentelemetry-instrumentation` and `opentelemetry-semantic-conventions` for the same version. That means that if you want to install your instrumentation you need to install its dependencies from this repo and the core repo also from git.
275+
- Most of the instrumentations have the same version. If you are going to develop a new instrumentation it would probably have `X.Y.dev` version and depends on `opentelemetry-instrumentation` and `opentelemetry-semantic-conventions` for a [compatible version](https://peps.python.org/pep-0440/#compatible-release). That means that you may need to install the instrumentation dependencies from this repo and the core repo from git.
276+
- Documentation
277+
- When adding a new instrumentation remember to add an entry in `docs/instrumentation/` named `<instrumentation>/<instrumentation>.rst` to have the instrumentation documentation referenced from the index. You can use the entry template available [here](./_template/autodoc_entry.rst)
278+
- Testing
279+
- When adding a new instrumentation remember to update `tox.ini` adding appropriate rules in `envlist`, `command_pre` and `commands` sections
276280

277281
## Guideline for GenAI instrumentations
278282

_template/autodoc_entry.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. include:: ../../../instrumentation/opentelemetry-instrumentation-<REPLACE ME>/README.rst
2+
:end-before: References
3+
4+
.. automodule:: opentelemetry.instrumentation.<REPLACE ME>
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ def _instrument(self, **kwargs):
181181
tracer, connections_usage, enable_commenter, commenter_options
182182
),
183183
)
184+
# sqlalchemy.engine.create is not present in earlier versions of sqlalchemy (which we support)
185+
if parse_version(sqlalchemy.__version__).release >= (1, 4):
186+
_w(
187+
"sqlalchemy.engine.create",
188+
"create_engine",
189+
_wrap_create_engine(
190+
tracer,
191+
connections_usage,
192+
enable_commenter,
193+
commenter_options,
194+
),
195+
)
184196
_w(
185197
"sqlalchemy.engine.base",
186198
"Engine.connect",
@@ -224,6 +236,8 @@ def _instrument(self, **kwargs):
224236
def _uninstrument(self, **kwargs):
225237
unwrap(sqlalchemy, "create_engine")
226238
unwrap(sqlalchemy.engine, "create_engine")
239+
if parse_version(sqlalchemy.__version__).release >= (1, 4):
240+
unwrap(sqlalchemy.engine.create, "create_engine")
227241
unwrap(Engine, "connect")
228242
if parse_version(sqlalchemy.__version__).release >= (1, 4):
229243
unwrap(sqlalchemy.ext.asyncio, "create_async_engine")

instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ def test_create_engine_wrapper(self):
182182
"opentelemetry.instrumentation.sqlalchemy",
183183
)
184184

185+
def test_instrument_engine_from_config(self):
186+
SQLAlchemyInstrumentor().instrument()
187+
from sqlalchemy import engine_from_config # pylint: disable-all
188+
189+
engine = engine_from_config({"sqlalchemy.url": "sqlite:///:memory:"})
190+
cnx = engine.connect()
191+
cnx.execute(text("SELECT 1 + 1;")).fetchall()
192+
spans = self.memory_exporter.get_finished_spans()
193+
194+
self.assertEqual(len(spans), 2)
195+
185196
def test_create_engine_wrapper_enable_commenter(self):
186197
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)
187198
SQLAlchemyInstrumentor().instrument(

0 commit comments

Comments
 (0)