Skip to content

Commit

Permalink
Merge branch 'main' into fix-flask-multithread-context-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hangonlyra authored Feb 22, 2023
2 parents 933a15c + 3bcc043 commit 075cff2
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Add connection attributes to sqlalchemy connect span
([#1608](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1608))

## Version 1.16.0/0.37b0 (2023-02-17)

### Added
Expand Down
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ aiopg>=0.13.0,<1.3.0
asyncpg>=0.12.0
boto~=2.0
botocore~=1.0
boto3~=1.0
celery>=4.0
confluent-kafka>= 1.8.2,< 2.0.0
elasticsearch>=2.0,<9.0
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def getlistcfg(strval):
]


ignore_categories = ["py-class", "py-func", "py-exc", "any"]
ignore_categories = ["py-class", "py-func", "py-exc", "py-obj", "any"]

for category in ignore_categories:
if category in mcfg:
Expand Down
6 changes: 6 additions & 0 deletions docs/instrumentation/boto3sqs/boto3sqs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. include:: ../../../instrumentation/opentelemetry-instrumentation-boto3sqs/README.rst

.. automodule:: opentelemetry.instrumentation.boto3sqs
:members:
:undoc-members:
:show-inheritance:
12 changes: 11 additions & 1 deletion docs/nitpick-exceptions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ py-class=
opentelemetry.sdk.trace.id_generator.IdGenerator
opentelemetry.instrumentation.confluent_kafka.ProxiedProducer
opentelemetry.instrumentation.confluent_kafka.ProxiedConsumer
opentelemetry.instrumentation.instrumentor.BaseInstrumentor
; - AwsXRayIdGenerator
TextMapPropagator
CarrierT
Expand Down Expand Up @@ -54,7 +55,16 @@ any=
; - instrumentation.*
Setter
httpx
;
instrument
__iter__
list.__iter__
__getitem__
list.__getitem__
SQS.ReceiveMessage

py-obj=
opentelemetry.propagators.textmap.CarrierT

py-func=
poll
flush
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
.. _boto3sqs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html
Usage
-----
.. code:: python
.. code-block:: python
import boto3
from opentelemetry.instrumentation.boto3sqs import Boto3SQSInstrumentor
Boto3SQSInstrumentor().instrument()
---
"""
import logging
from typing import Any, Collection, Dict, Generator, List, Mapping, Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,26 @@ def response_hook(span, response):
spans[0].attributes[response_attribute_name],
)

def test_no_op_tracer_provider(self, request_mock):
ElasticsearchInstrumentor().uninstrument()
ElasticsearchInstrumentor().instrument(
tracer_provider=trace.NoOpTracerProvider()
)
response_payload = '{"found": false, "timed_out": true, "took": 7}'
request_mock.return_value = (
1,
{},
response_payload,
)
es = Elasticsearch()
res = es.get(index="test-index", doc_type="_doc", id=1)
self.assertEqual(
res.get("found"), json.loads(response_payload).get("found")
)

spans_list = self.get_finished_spans()
self.assertEqual(len(spans_list), 0)

def test_body_sanitization(self, _):
self.assertEqual(
sanitize_body(sanitization_queries.interval_query),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def _wrap_connect(tracer_provider=None):
def _wrap_connect_internal(func, module, args, kwargs):
with tracer.start_as_current_span(
"connect", kind=trace.SpanKind.CLIENT
):
) as span:
if span.is_recording():
attrs, _ = _get_attributes_from_url(module.url)
span.set_attributes(attrs)
span.set_attribute(
SpanAttributes.DB_SYSTEM, _normalize_vendor(module.name)
)
return func(*args, **kwargs)

return _wrap_connect_internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider, export
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.test.test_base import TestBase


Expand Down Expand Up @@ -128,11 +129,12 @@ async def run():
def test_not_recording(self):
mock_tracer = mock.Mock()
mock_span = mock.Mock()
mock_context = mock.Mock()
mock_span.is_recording.return_value = False
mock_span.__enter__ = mock.Mock(return_value=(mock.Mock(), None))
mock_span.__exit__ = mock.Mock(return_value=None)
mock_tracer.start_span.return_value = mock_span
mock_tracer.start_as_current_span.return_value = mock_span
mock_context.__enter__ = mock.Mock(return_value=mock_span)
mock_context.__exit__ = mock.Mock(return_value=None)
mock_tracer.start_span.return_value = mock_context
mock_tracer.start_as_current_span.return_value = mock_context
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
tracer.return_value = mock_tracer
engine = create_engine("sqlite:///:memory:")
Expand All @@ -159,6 +161,12 @@ def test_create_engine_wrapper(self):
self.assertEqual(len(spans), 2)
# first span - the connection to the db
self.assertEqual(spans[0].name, "connect")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_NAME], ":memory:"
)
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_SYSTEM], "sqlite"
)
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
# second span - the query
self.assertEqual(spans[1].name, "SELECT :memory:")
Expand Down Expand Up @@ -217,6 +225,12 @@ async def run():
self.assertEqual(len(spans), 2)
# first span - the connection to the db
self.assertEqual(spans[0].name, "connect")
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_NAME], ":memory:"
)
self.assertEqual(
spans[0].attributes[SpanAttributes.DB_SYSTEM], "sqlite"
)
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
# second span - the query
self.assertEqual(spans[1].name, "SELECT :memory:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_engine_execute_errors(self):
spans = self.memory_exporter.get_finished_spans()
# one span for the connection and one for the query
self.assertEqual(len(spans), 2)
self.check_meta(spans[0])
span = spans[1]
# span fields
self.assertEqual(span.name, "SELECT opentelemetry-tests")
Expand Down Expand Up @@ -99,6 +100,7 @@ def test_orm_insert(self):
spans = self.memory_exporter.get_finished_spans()
# connect, identity insert on before the insert, insert, and identity insert off after the insert
self.assertEqual(len(spans), 4)
self.check_meta(spans[0])
span = spans[2]
self._check_span(span, "INSERT")
self.assertIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_engine_execute_errors(self):
spans = self.memory_exporter.get_finished_spans()
# one span for the connection and one for the query
self.assertEqual(len(spans), 2)
self.check_meta(spans[0])
span = spans[1]
# span fields
self.assertEqual(span.name, "SELECT opentelemetry-tests")
Expand Down

0 comments on commit 075cff2

Please sign in to comment.