Skip to content

Commit 0007c90

Browse files
authored
Add metric instrumentation for WSGI (#1128)
1 parent 6503cdf commit 0007c90

File tree

12 files changed

+191
-90
lines changed

12 files changed

+191
-90
lines changed

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'release/*'
77
pull_request:
88
env:
9-
CORE_REPO_SHA: c82829283d3e99aa2e089d1774ee509619650617
9+
CORE_REPO_SHA: d4d7c67663cc22615748d632e1c8c5799e8eacae
1010

1111
jobs:
1212
build:
@@ -42,7 +42,7 @@ jobs:
4242
path: |
4343
.tox
4444
~/.cache/pip
45-
key: v5-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
45+
key: v6-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
4646
- name: run tox
4747
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
4848
# - name: Find and merge ${{ matrix.package }} benchmarks
@@ -118,7 +118,7 @@ jobs:
118118
path: |
119119
.tox
120120
~/.cache/pip
121-
key: v5-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
121+
key: v6-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt', 'gen-requirements.txt', 'docs-requirements.txt') }}
122122
- name: run tox
123123
run: tox -e ${{ matrix.tox-environment }}
124124
- name: Ensure generated code is up to date

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
([#1111](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1111))
3535
- Set otlp-proto-grpc as the default metrics exporter for auto-instrumentation
3636
([#1127](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1127))
37+
- Add metric instrumentation for WSGI
38+
([#1128](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1128))
3739

3840

3941
## [1.12.0rc1-0.31b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.12.0rc1-0.31b0) - 2022-05-17

instrumentation/README.md

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11

2-
| Instrumentation | Supported Packages |
3-
| --------------- | ------------------ |
4-
| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 |
5-
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 |
6-
| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 |
7-
| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 |
8-
| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda |
9-
| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 |
10-
| [opentelemetry-instrumentation-boto3sqs](./opentelemetry-instrumentation-boto3sqs) | boto3 ~= 1.0 |
11-
| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 |
12-
| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 |
13-
| [opentelemetry-instrumentation-confluent-kafka](./opentelemetry-instrumentation-confluent-kafka) | confluent-kafka ~= 1.8.2 |
14-
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi |
15-
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 |
16-
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 |
17-
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 |
18-
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 |
19-
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 |
20-
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 |
21-
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 |
22-
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 |
23-
| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 |
24-
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging |
25-
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 |
26-
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 |
27-
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 |
28-
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 |
29-
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 |
30-
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 |
31-
| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 |
32-
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 |
33-
| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 |
34-
| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 |
35-
| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 |
36-
| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy |
37-
| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 |
38-
| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 |
39-
| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 |
40-
| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 |
41-
| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib |
42-
| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 |
43-
| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi |
2+
| Instrumentation | Supported Packages | Metrics support |
3+
| --------------- | ------------------ | --------------- |
4+
| [opentelemetry-instrumentation-aiohttp-client](./opentelemetry-instrumentation-aiohttp-client) | aiohttp ~= 3.0 | No
5+
| [opentelemetry-instrumentation-aiopg](./opentelemetry-instrumentation-aiopg) | aiopg >= 0.13.0, < 1.3.0 | No
6+
| [opentelemetry-instrumentation-asgi](./opentelemetry-instrumentation-asgi) | asgiref ~= 3.0 | No
7+
| [opentelemetry-instrumentation-asyncpg](./opentelemetry-instrumentation-asyncpg) | asyncpg >= 0.12.0 | No
8+
| [opentelemetry-instrumentation-aws-lambda](./opentelemetry-instrumentation-aws-lambda) | aws_lambda | No
9+
| [opentelemetry-instrumentation-boto](./opentelemetry-instrumentation-boto) | boto~=2.0 | No
10+
| [opentelemetry-instrumentation-boto3sqs](./opentelemetry-instrumentation-boto3sqs) | boto3 ~= 1.0 | No
11+
| [opentelemetry-instrumentation-botocore](./opentelemetry-instrumentation-botocore) | botocore ~= 1.0 | No
12+
| [opentelemetry-instrumentation-celery](./opentelemetry-instrumentation-celery) | celery >= 4.0, < 6.0 | No
13+
| [opentelemetry-instrumentation-confluent-kafka](./opentelemetry-instrumentation-confluent-kafka) | confluent-kafka ~= 1.8.2 | No
14+
| [opentelemetry-instrumentation-dbapi](./opentelemetry-instrumentation-dbapi) | dbapi | No
15+
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | No
16+
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | No
17+
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | No
18+
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | No
19+
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | No
20+
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No
21+
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No
22+
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | No
23+
| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | No
24+
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | No
25+
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | No
26+
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | No
27+
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | No
28+
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | No
29+
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No
30+
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No
31+
| [opentelemetry-instrumentation-pyramid](./opentelemetry-instrumentation-pyramid) | pyramid >= 1.7 | No
32+
| [opentelemetry-instrumentation-redis](./opentelemetry-instrumentation-redis) | redis >= 2.6 | No
33+
| [opentelemetry-instrumentation-remoulade](./opentelemetry-instrumentation-remoulade) | remoulade >= 0.50 | No
34+
| [opentelemetry-instrumentation-requests](./opentelemetry-instrumentation-requests) | requests ~= 2.0 | No
35+
| [opentelemetry-instrumentation-sklearn](./opentelemetry-instrumentation-sklearn) | scikit-learn ~= 0.24.0 | No
36+
| [opentelemetry-instrumentation-sqlalchemy](./opentelemetry-instrumentation-sqlalchemy) | sqlalchemy | No
37+
| [opentelemetry-instrumentation-sqlite3](./opentelemetry-instrumentation-sqlite3) | sqlite3 | No
38+
| [opentelemetry-instrumentation-starlette](./opentelemetry-instrumentation-starlette) | starlette ~= 0.13.0 | No
39+
| [opentelemetry-instrumentation-system-metrics](./opentelemetry-instrumentation-system-metrics) | psutil >= 5 | No
40+
| [opentelemetry-instrumentation-tornado](./opentelemetry-instrumentation-tornado) | tornado >= 5.1.1 | No
41+
| [opentelemetry-instrumentation-urllib](./opentelemetry-instrumentation-urllib) | urllib | No
42+
| [opentelemetry-instrumentation-urllib3](./opentelemetry-instrumentation-urllib3) | urllib3 >= 1.0.0, < 2.0.0 | No
43+
| [opentelemetry-instrumentation-wsgi](./opentelemetry-instrumentation-wsgi) | wsgi | Yes

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from opentelemetry.sdk.trace import Span
3636
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
3737
from opentelemetry.semconv.trace import SpanAttributes
38-
from opentelemetry.test.test_base import TestBase
3938
from opentelemetry.test.wsgitestutil import WsgiTestBase
4039
from opentelemetry.trace import (
4140
SpanKind,
@@ -84,7 +83,7 @@
8483
_django_instrumentor = DjangoInstrumentor()
8584

8685

87-
class TestMiddleware(TestBase, WsgiTestBase):
86+
class TestMiddleware(WsgiTestBase):
8887
@classmethod
8988
def setUpClass(cls):
9089
conf.settings.configure(ROOT_URLCONF=modules[__name__])
@@ -402,7 +401,7 @@ def test_trace_response_headers(self):
402401
self.memory_exporter.clear()
403402

404403

405-
class TestMiddlewareWithTracerProvider(TestBase, WsgiTestBase):
404+
class TestMiddlewareWithTracerProvider(WsgiTestBase):
406405
@classmethod
407406
def setUpClass(cls):
408407
conf.settings.configure(ROOT_URLCONF=modules[__name__])
@@ -460,7 +459,7 @@ def test_django_with_wsgi_instrumented(self):
460459
)
461460

462461

463-
class TestMiddlewareWsgiWithCustomHeaders(TestBase, WsgiTestBase):
462+
class TestMiddlewareWsgiWithCustomHeaders(WsgiTestBase):
464463
@classmethod
465464
def setUpClass(cls):
466465
conf.settings.configure(ROOT_URLCONF=modules[__name__])

instrumentation/opentelemetry-instrumentation-flask/tests/test_automatic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
from werkzeug.wrappers import Response
1818

1919
from opentelemetry.instrumentation.flask import FlaskInstrumentor
20-
from opentelemetry.test.test_base import TestBase
2120
from opentelemetry.test.wsgitestutil import WsgiTestBase
2221

2322
# pylint: disable=import-error
2423
from .base_test import InstrumentationTest
2524

2625

27-
class TestAutomatic(InstrumentationTest, TestBase, WsgiTestBase):
26+
class TestAutomatic(InstrumentationTest, WsgiTestBase):
2827
def setUp(self):
2928
super().setUp()
3029

instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware
2727
from opentelemetry.sdk.resources import Resource
2828
from opentelemetry.semconv.trace import SpanAttributes
29-
from opentelemetry.test.test_base import TestBase
3029
from opentelemetry.test.wsgitestutil import WsgiTestBase
3130
from opentelemetry.util.http import get_excluded_urls
3231

@@ -50,7 +49,7 @@ def expected_attributes(override_attributes):
5049
return default_attributes
5150

5251

53-
class TestProgrammatic(InstrumentationTest, TestBase, WsgiTestBase):
52+
class TestProgrammatic(InstrumentationTest, WsgiTestBase):
5453
def setUp(self):
5554
super().setUp()
5655

@@ -252,7 +251,7 @@ def test_exclude_lists_from_explicit(self):
252251
self.assertEqual(len(span_list), 1)
253252

254253

255-
class TestProgrammaticHooks(InstrumentationTest, TestBase, WsgiTestBase):
254+
class TestProgrammaticHooks(InstrumentationTest, WsgiTestBase):
256255
def setUp(self):
257256
super().setUp()
258257

@@ -300,9 +299,7 @@ def test_hooks(self):
300299
self.assertEqual(resp.headers["hook_attr"], "hello otel")
301300

302301

303-
class TestProgrammaticHooksWithoutApp(
304-
InstrumentationTest, TestBase, WsgiTestBase
305-
):
302+
class TestProgrammaticHooksWithoutApp(InstrumentationTest, WsgiTestBase):
306303
def setUp(self):
307304
super().setUp()
308305

@@ -350,9 +347,7 @@ def test_no_app_hooks(self):
350347
self.assertEqual(resp.headers["hook_attr"], "hello otel without app")
351348

352349

353-
class TestProgrammaticCustomTracerProvider(
354-
InstrumentationTest, TestBase, WsgiTestBase
355-
):
350+
class TestProgrammaticCustomTracerProvider(InstrumentationTest, WsgiTestBase):
356351
def setUp(self):
357352
super().setUp()
358353
resource = Resource.create({"service.name": "flask-api"})
@@ -383,7 +378,7 @@ def test_custom_span_name(self):
383378

384379

385380
class TestProgrammaticCustomTracerProviderWithoutApp(
386-
InstrumentationTest, TestBase, WsgiTestBase
381+
InstrumentationTest, WsgiTestBase
387382
):
388383
def setUp(self):
389384
super().setUp()
@@ -417,7 +412,7 @@ def test_custom_span_name(self):
417412

418413

419414
class TestProgrammaticWrappedWithOtherFramework(
420-
InstrumentationTest, TestBase, WsgiTestBase
415+
InstrumentationTest, WsgiTestBase
421416
):
422417
def setUp(self):
423418
super().setUp()
@@ -444,9 +439,7 @@ def test_mark_span_internal_in_presence_of_span_from_other_framework(self):
444439
)
445440

446441

447-
class TestCustomRequestResponseHeaders(
448-
InstrumentationTest, TestBase, WsgiTestBase
449-
):
442+
class TestCustomRequestResponseHeaders(InstrumentationTest, WsgiTestBase):
450443
def setUp(self):
451444
super().setUp()
452445

instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from opentelemetry import trace
2020
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
2121
from opentelemetry.test.globals_test import reset_trace_globals
22-
from opentelemetry.test.test_base import TestBase
2322
from opentelemetry.test.wsgitestutil import WsgiTestBase
2423
from opentelemetry.trace import SpanKind
2524
from opentelemetry.trace.status import StatusCode
@@ -32,7 +31,7 @@
3231
from .pyramid_base_test import InstrumentationTest
3332

3433

35-
class TestAutomatic(InstrumentationTest, TestBase, WsgiTestBase):
34+
class TestAutomatic(InstrumentationTest, WsgiTestBase):
3635
def setUp(self):
3736
super().setUp()
3837

@@ -158,9 +157,7 @@ def test_400s_response_is_not_an_error(self):
158157
self.assertEqual(len(span_list), 1)
159158

160159

161-
class TestWrappedWithOtherFramework(
162-
InstrumentationTest, TestBase, WsgiTestBase
163-
):
160+
class TestWrappedWithOtherFramework(InstrumentationTest, WsgiTestBase):
164161
def setUp(self):
165162
super().setUp()
166163
PyramidInstrumentor().instrument()
@@ -189,9 +186,7 @@ def test_with_existing_span(self):
189186
)
190187

191188

192-
class TestCustomRequestResponseHeaders(
193-
InstrumentationTest, TestBase, WsgiTestBase
194-
):
189+
class TestCustomRequestResponseHeaders(InstrumentationTest, WsgiTestBase):
195190
def setUp(self):
196191
super().setUp()
197192
PyramidInstrumentor().instrument()
@@ -296,9 +291,7 @@ def test_custom_response_header_not_added_in_internal_span(self):
296291
self.assertNotIn(key, span.attributes)
297292

298293

299-
class TestCustomHeadersNonRecordingSpan(
300-
InstrumentationTest, TestBase, WsgiTestBase
301-
):
294+
class TestCustomHeadersNonRecordingSpan(InstrumentationTest, WsgiTestBase):
302295
def setUp(self):
303296
super().setUp()
304297
# This is done because set_tracer_provider cannot override the

instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
)
2525
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor
2626
from opentelemetry.semconv.trace import SpanAttributes
27-
from opentelemetry.test.test_base import TestBase
2827
from opentelemetry.test.wsgitestutil import WsgiTestBase
2928
from opentelemetry.util.http import get_excluded_urls
3029

@@ -48,7 +47,7 @@ def expected_attributes(override_attributes):
4847
return default_attributes
4948

5049

51-
class TestProgrammatic(InstrumentationTest, TestBase, WsgiTestBase):
50+
class TestProgrammatic(InstrumentationTest, WsgiTestBase):
5251
def setUp(self):
5352
super().setUp()
5453
config = Configurator()

0 commit comments

Comments
 (0)