From 25f715116457ebc2b49ce501fa00ae2887da638b Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Mon, 4 Jan 2021 19:42:42 +0530 Subject: [PATCH] Ensure SQLAlchemy spans have kind set to CLIENT SQLAlchemy spans were missing kind field and it was being set to internal instead of client. This commit changes sqlalchemy spans to have kind set to "client" instead. --- CHANGELOG.md | 2 ++ .../src/opentelemetry/instrumentation/sqlalchemy/engine.py | 4 +++- .../tests/test_sqlalchemy.py | 3 +++ opentelemetry-python-core | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 120000 opentelemetry-python-core diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c76278bc..8ee9f66b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.16b1...HEAD) ### Added +- `opentelemetry-instrumentation-sqlalchemy` Ensure spans have kind set to "CLIENT" + ([#278](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/278)) - `opentelemetry-instrumentation-celery` Add support for Celery version 5.x ([#266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/266)) - `opentelemetry-instrumentation-urllib` Add urllib instrumentation diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index 07e86d5856..86f52ad724 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -74,7 +74,9 @@ def __init__(self, tracer, engine): # pylint: disable=unused-argument def _before_cur_exec(self, conn, cursor, statement, *args): - self.current_span = self.tracer.start_span(statement) + self.current_span = self.tracer.start_span( + statement, kind=trace.SpanKind.CLIENT + ) with self.tracer.use_span(self.current_span, end_on_exit=False): if self.current_span.is_recording(): self.current_span.set_attribute(_STMT, statement) diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py index a0187454ba..dfc6e429a7 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py @@ -15,6 +15,7 @@ from sqlalchemy import create_engine +from opentelemetry import trace from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor from opentelemetry.test.test_base import TestBase @@ -35,6 +36,7 @@ def test_trace_integration(self): self.assertEqual(len(spans), 1) self.assertEqual(spans[0].name, "SELECT 1 + 1;") + self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT) def test_not_recording(self): mock_tracer = mock.Mock() @@ -67,3 +69,4 @@ def test_create_engine_wrapper(self): self.assertEqual(len(spans), 1) self.assertEqual(spans[0].name, "SELECT 1 + 1;") + self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT) diff --git a/opentelemetry-python-core b/opentelemetry-python-core new file mode 120000 index 0000000000..a07b8d1c18 --- /dev/null +++ b/opentelemetry-python-core @@ -0,0 +1 @@ +../opentelemetry-python \ No newline at end of file