Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
75 changes: 49 additions & 26 deletions ext/opentelemetry-ext-flask/tests/test_flask_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import opentelemetry.ext.flask as otel_flask
from opentelemetry import trace as trace_api
from opentelemetry.ext.testutil.wsgitestutil import WsgiTestBase
from opentelemetry.sdk.trace import MAX_NUM_ATTRIBUTES
from opentelemetry.sdk.util import BoundedDict


class TestFlaskIntegration(WsgiTestBase):
Expand All @@ -40,15 +42,22 @@ def hello_endpoint(helloid):
self.client = Client(self.app, BaseResponse)

def test_simple(self):
expected_attrs = {
"component": "http",
"http.method": "GET",
"http.host": "localhost",
"http.url": "http://localhost/hello/123",
"http.route": "/hello/<int:helloid>",
"http.status_code": 200,
"http.status_text": "OK",
}
expected_attrs = BoundedDict.from_map(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For expectations, I would not use BoundedDict because attributes could get dropped silently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

MAX_NUM_ATTRIBUTES,
{
"component": "http",
"http.method": "GET",
"http.server_name": "localhost",
"http.scheme": "http",
"host.port": 80,
"http.host": "localhost",
"http.target": "/hello/123",
"http.flavor": "1.1",
"http.route": "/hello/<int:helloid>",
"http.status_text": "OK",
"http.status_code": 200,
},
)
resp = self.client.get("/hello/123")
self.assertEqual(200, resp.status_code)
self.assertEqual([b"Hello: 123"], list(resp.response))
Expand All @@ -59,14 +68,21 @@ def test_simple(self):
self.assertEqual(span_list[0].attributes, expected_attrs)

def test_404(self):
expected_attrs = {
"component": "http",
"http.method": "POST",
"http.host": "localhost",
"http.url": "http://localhost/bye",
"http.status_code": 404,
"http.status_text": "NOT FOUND",
}
expected_attrs = BoundedDict.from_map(
MAX_NUM_ATTRIBUTES,
{
"component": "http",
"http.method": "POST",
"http.server_name": "localhost",
"http.scheme": "http",
"host.port": 80,
"http.host": "localhost",
"http.target": "/bye",
"http.flavor": "1.1",
"http.status_text": "NOT FOUND",
"http.status_code": 404,
},
)
resp = self.client.post("/bye")
self.assertEqual(404, resp.status_code)
resp.close()
Expand All @@ -77,15 +93,22 @@ def test_404(self):
self.assertEqual(span_list[0].attributes, expected_attrs)

def test_internal_error(self):
expected_attrs = {
"component": "http",
"http.method": "GET",
"http.host": "localhost",
"http.url": "http://localhost/hello/500",
"http.route": "/hello/<int:helloid>",
"http.status_code": 500,
"http.status_text": "INTERNAL SERVER ERROR",
}
expected_attrs = BoundedDict.from_map(
MAX_NUM_ATTRIBUTES,
{
"component": "http",
"http.method": "GET",
"http.server_name": "localhost",
"http.scheme": "http",
"host.port": 80,
"http.host": "localhost",
"http.target": "/hello/500",
"http.flavor": "1.1",
"http.route": "/hello/<int:helloid>",
"http.status_text": "INTERNAL SERVER ERROR",
"http.status_code": 500,
},
)
resp = self.client.get("/hello/500")
self.assertEqual(500, resp.status_code)
resp.close()
Expand Down
20 changes: 20 additions & 0 deletions ext/opentelemetry-ext-wsgi/tests/test_wsgi_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import opentelemetry.ext.wsgi as otel_wsgi
from opentelemetry import trace as trace_api
from opentelemetry.ext.testutil.wsgitestutil import WsgiTestBase
from opentelemetry.sdk.trace import MAX_NUM_ATTRIBUTES
from opentelemetry.sdk.util import BoundedDict


class Response:
Expand Down Expand Up @@ -97,6 +99,24 @@ def validate_response(self, response, error=None):
self.assertEqual(len(span_list), 1)
self.assertEqual(span_list[0].name, "/")
self.assertEqual(span_list[0].kind, trace_api.SpanKind.SERVER)
self.assertEqual(
span_list[0].attributes,
BoundedDict.from_map(
MAX_NUM_ATTRIBUTES,
{
"component": "http",
"http.method": "GET",
"http.server_name": "127.0.0.1",
"http.scheme": "http",
"host.port": 80,
"http.host": "127.0.0.1",
"http.flavor": "1.0",
"http.url": "http://127.0.0.1/",
"http.status_text": "OK",
"http.status_code": 200,
},
),
)

def test_basic_wsgi_call(self):
app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.