Ensure SQLAlchemy spans have kind set to CLIENT (#278)

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.
This commit is contained in:
Owais Lone
2021-01-05 22:35:58 +05:30
committed by GitHub
parent 472f845381
commit 9fea7f7a27
3 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -74,7 +74,9 @@ class EngineTracer:
# 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)

View File

@ -15,6 +15,7 @@ from unittest import mock
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 @@ class TestSqlalchemyInstrumentation(TestBase):
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 @@ class TestSqlalchemyInstrumentation(TestBase):
self.assertEqual(len(spans), 1)
self.assertEqual(spans[0].name, "SELECT 1 + 1;")
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)