Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __repr__(self):
TRACE = "TRACE"


SCOPE = "opentelemetry.instrumentation.aiohttp_server"


@pytest.fixture(name="test_base", scope="function")
def fixture_test_base():
test_base = TestBase()
Expand Down Expand Up @@ -172,14 +175,14 @@ async def test_status_code_instrumentation(
server, _ = server_fixture

assert len(test_base.get_finished_spans()) == 0
metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
assert len(metrics) == 0

client = await aiohttp_client(server)
await client.get(url)

assert len(test_base.get_finished_spans()) == 1
metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
assert len(metrics) == 2

[span] = test_base.get_finished_spans()
Expand Down Expand Up @@ -327,7 +330,7 @@ async def handler(request):
spans = test_base.get_finished_spans()
assert len(spans) == 0

metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
assert len(metrics) == 0

AioHttpServerInstrumentor().uninstrument()
Expand Down Expand Up @@ -545,7 +548,7 @@ async def test_semantic_conventions_metrics_old_default(
assert NETWORK_PROTOCOL_VERSION not in span.attributes
assert HTTP_RESPONSE_STATUS_CODE not in span.attributes

metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
expected_metric_names = [
"http.server.active_requests",
"http.server.duration",
Expand Down Expand Up @@ -619,7 +622,7 @@ async def test_semantic_conventions_metrics_new(
assert HTTP_FLAVOR not in span.attributes
assert HTTP_STATUS_CODE not in span.attributes

metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
expected_metric_names = [
"http.server.active_requests",
"http.server.request.duration",
Expand Down Expand Up @@ -701,7 +704,7 @@ async def test_semantic_conventions_metrics_both(
assert span.attributes.get(HTTP_RESPONSE_STATUS_CODE) == 200
assert span.attributes.get(HTTP_ROUTE) == "default_handler"

metrics = test_base.get_sorted_metrics()
metrics = test_base.get_sorted_metrics(SCOPE)
assert len(metrics) == 3 # Both duration metrics + active requests
server_active_requests_count_attrs_both = list(
_server_active_requests_count_attrs_old
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace import get_tracer

SCOPE = "opentelemetry.instrumentation.asyncio"


class TestTraceFuture(TestBase):
@patch.dict(
Expand Down Expand Up @@ -41,7 +43,7 @@ async def future_cancelled():
self.assertEqual(spans[0].name, "root")
self.assertEqual(spans[1].name, "asyncio future")

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertEqual(len(metrics), 2)

self.assertEqual(metrics[0].name, "asyncio.process.created")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from .celery_test_tasks import app, task_add

SCOPE = "opentelemetry.instrumentation.celery"


class TestMetrics(TestBase):
def setUp(self):
Expand All @@ -34,7 +36,7 @@ def get_metrics(self):
if time.time() > timeout:
break
time.sleep(0.05)
return self.get_sorted_metrics()
return self.get_sorted_metrics(SCOPE)

def test_basic_metric(self):
CeleryInstrumentor().instrument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def path(path_argument, *args, **kwargs):
]
_django_instrumentor = DjangoInstrumentor()

SCOPE = "opentelemetry.instrumentation.django"


# pylint: disable=too-many-public-methods
class TestMiddleware(WsgiTestBase):
Expand Down Expand Up @@ -737,7 +739,7 @@ def test_wsgi_metrics(self):
response = Client().get("/span_name/1234/")
self.assertEqual(response.status_code, 200)
duration = max(round((default_timer() - start) * 1000), 0)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histrogram_data_point_seen = False

Expand Down Expand Up @@ -786,7 +788,7 @@ def test_wsgi_metrics_new_semconv(self):
response = Client().get("/span_name/1234/")
self.assertEqual(response.status_code, 200)
duration_s = default_timer() - start
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histrogram_data_point_seen = False

Expand Down Expand Up @@ -855,7 +857,7 @@ def test_wsgi_metrics_both_semconv(self):
self.assertEqual(response.status_code, 200)
duration_s = max(default_timer() - start, 0)
duration = max(round(duration_s * 1000), 0)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histrogram_data_point_seen = False

Expand Down Expand Up @@ -901,7 +903,7 @@ def test_wsgi_metrics_unistrument(self):
Client().get("/span_name/1234/")
_django_instrumentor.uninstrument()
Client().get("/span_name/1234/")
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
_parsed_falcon_version = package_version.parse(_falcon_version)


SCOPE = "opentelemetry.instrumentation.falcon"


class TestFalconBase(TestBase):
def setUp(self):
super().setUp()
Expand Down Expand Up @@ -487,7 +490,7 @@ def test_traced_not_recording(self):
self.assertFalse(mock_span.set_attribute.called)
self.assertFalse(mock_span.set_status.called)

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertTrue(len(metrics) != 0)
for metric in metrics:
data_points = list(metric.data.data_points)
Expand Down Expand Up @@ -519,7 +522,7 @@ def test_falcon_metrics(self):
self.client().simulate_get("/hello/756")
self.client().simulate_get("/hello/756")
self.client().simulate_get("/hello/756")
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histogram_data_point_seen = False
self.assertTrue(len(metrics) != 0)
Expand All @@ -545,7 +548,7 @@ def test_falcon_metric_values_new_semconv(self):
self.client().simulate_get("/hello/756")
duration = max(default_timer() - start, 0)

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
data_points = list(metric.data.data_points)
self.assertEqual(len(data_points), 1)
Expand Down Expand Up @@ -577,7 +580,7 @@ def test_falcon_metric_values_both_semconv(self):
self.client().simulate_get("/hello/756")
duration_s = default_timer() - start

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)

# pylint: disable=too-many-nested-blocks
for metric in metrics:
Expand Down Expand Up @@ -626,7 +629,7 @@ def test_falcon_metric_values(self):
self.client().simulate_get("/hello/756")
duration = max(round((default_timer() - start) * 1000), 0)

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
data_points = list(metric.data.data_points)
self.assertEqual(len(data_points), 1)
Expand All @@ -650,7 +653,7 @@ def test_metric_uninstrument(self):
self.client().simulate_request(method="POST", path="/hello/756")
FalconInstrumentor().uninstrument()
self.client().simulate_request(method="POST", path="/hello/756")
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def expected_attributes_new(override_attributes):
"http.server.request.duration": _server_duration_attrs_new_copy,
}

SCOPE = "opentelemetry.instrumentation.flask"


# pylint: disable=too-many-public-methods
class TestProgrammatic(InstrumentationTest, WsgiTestBase):
Expand Down Expand Up @@ -497,7 +499,7 @@ def test_flask_metrics(self):
self.client.get("/hello/321")
self.client.get("/hello/756")
duration = max(round((default_timer() - start) * 1000), 0)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histogram_data_point_seen = False
self.assertTrue(len(metrics) != 0)
Expand Down Expand Up @@ -525,7 +527,7 @@ def test_flask_metrics_new_semconv(self):
self.client.get("/hello/321")
self.client.get("/hello/756")
duration_s = max(default_timer() - start, 0)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histogram_data_point_seen = False
self.assertTrue(len(metrics) != 0)
Expand Down Expand Up @@ -557,7 +559,7 @@ def test_flask_metric_values(self):
self.client.post("/hello/756")
self.client.post("/hello/756")
duration = max(round((default_timer() - start) * 1000), 0)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand All @@ -573,7 +575,7 @@ def _assert_basic_metric(
expected_histogram_explicit_bounds=None,
):
# pylint: disable=too-many-nested-blocks
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
MetricInstruments.HTTP_SERVER_DURATION: _server_duration_attrs_old,
}

SCOPE = "opentelemetry.instrumentation.pyramid.callbacks"


class TestAutomatic(InstrumentationTest, WsgiTestBase):
def setUp(self):
Expand Down Expand Up @@ -223,7 +225,7 @@ def test_pyramid_metric(self):
self.client.get("/hello/756")
self.client.get("/hello/756")
self.client.get("/hello/756")
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
number_data_point_seen = False
histogram_data_point_seen = False
self.assertEqual(len(metrics), 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(self):
self.response = {}


SCOPE = "opentelemetry.instrumentation.requests"


class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member
# pylint: disable=too-many-public-methods
Expand Down Expand Up @@ -1008,7 +1011,7 @@ def test_basic_metric_success(self):
HTTP_SCHEME: "http",
}

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertEqual(len(metrics), 1)
for metric in metrics:
self.assertEqual(metric.unit, "ms")
Expand Down Expand Up @@ -1036,7 +1039,7 @@ def test_basic_metric_new_semconv(self):
HTTP_REQUEST_METHOD: "GET",
NETWORK_PROTOCOL_VERSION: "1.1",
}
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertEqual(len(metrics), 1)
for metric in metrics:
self.assertEqual(metric.unit, "s")
Expand Down Expand Up @@ -1074,7 +1077,7 @@ def test_basic_metric_both_semconv(self):
NETWORK_PROTOCOL_VERSION: "1.1",
}

metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertEqual(len(metrics), 2)
for metric in metrics:
for data_point in metric.data.data_points:
Expand Down Expand Up @@ -1145,7 +1148,7 @@ def test_basic_metric_non_recording_span(self):
self.assertTrue(mock_span.is_recording.called)
self.assertFalse(mock_span.set_attribute.called)
self.assertFalse(mock_span.set_status.called)
metrics = self.get_sorted_metrics()
metrics = self.get_sorted_metrics(SCOPE)
self.assertEqual(len(metrics), 1)
duration_data_point = metrics[0].data.data_points[0]
self.assertDictEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"http.server.request.size": _duration_attrs,
}

SCOPE = "opentelemetry.instrumentation.starlette"


class TestStarletteManualInstrumentation(TestBase):
def _create_app(self):
Expand Down Expand Up @@ -182,9 +184,7 @@ def test_starlette_metrics(self):
self._client.get("/foobar")
number_data_point_seen = False
histogram_data_point_seen = False
metrics = self.get_sorted_metrics(
scope="opentelemetry.instrumentation.starlette"
)
metrics = self.get_sorted_metrics(SCOPE)
self.assertTrue(len(metrics) == 3)
for metric in metrics:
self.assertIn(metric.name, _expected_metric_names)
Expand Down Expand Up @@ -225,9 +225,7 @@ def test_basic_post_request_metric_success(self):
duration = max(round((default_timer() - start) * 1000), 0)
response_size = int(response.headers.get("content-length"))
request_size = int(response.request.headers.get("content-length"))
metrics = self.get_sorted_metrics(
scope="opentelemetry.instrumentation.starlette"
)
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand All @@ -254,9 +252,7 @@ def test_metric_for_uninstrment_app_method(self):
self._instrumentor.uninstrument_app(self._app)
self._client.get("/foobar")
self._client.get("/foobar")
metrics = self.get_sorted_metrics(
scope="opentelemetry.instrumentation.starlette"
)
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand All @@ -275,9 +271,7 @@ def test_metric_uninstrument_inherited_by_base(self):
client.get("/foobar")
client.get("/foobar")
client.get("/foobar")
metrics = self.get_sorted_metrics(
scope="opentelemetry.instrumentation.starlette"
)
metrics = self.get_sorted_metrics(SCOPE)
for metric in metrics:
for point in list(metric.data.data_points):
if isinstance(point, HistogramDataPoint):
Expand Down
Loading