|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | +import json |
| 3 | + |
2 | 4 | import flask |
3 | 5 | from flask import abort |
| 6 | +from flask import jsonify |
4 | 7 | from flask import make_response |
5 | 8 |
|
6 | 9 | from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY |
@@ -82,6 +85,50 @@ def index(): |
82 | 85 | self.assertEqual(handler_span.resource, "/") |
83 | 86 | self.assertEqual(req_span.error, 0) |
84 | 87 |
|
| 88 | + def test_route_params_request(self): |
| 89 | + """ |
| 90 | + When making a request to an endpoint with non-string url params |
| 91 | + We create the expected spans |
| 92 | + """ |
| 93 | + |
| 94 | + @self.app.route("/route_params/<first>/<int:second>/<float:third>/<path:fourth>") |
| 95 | + def route_params(first, second, third, fourth): |
| 96 | + return jsonify( |
| 97 | + { |
| 98 | + "first": first, |
| 99 | + "second": second, |
| 100 | + "third": third, |
| 101 | + "fourth": fourth, |
| 102 | + } |
| 103 | + ) |
| 104 | + |
| 105 | + res = self.client.get("/route_params/test/100/5.5/some/sub/path") |
| 106 | + self.assertEqual(res.status_code, 200) |
| 107 | + if isinstance(res.data, bytes): |
| 108 | + data = json.loads(res.data.decode()) |
| 109 | + else: |
| 110 | + data = json.loads(res.data) |
| 111 | + |
| 112 | + assert data == { |
| 113 | + "first": "test", |
| 114 | + "second": 100, |
| 115 | + "third": 5.5, |
| 116 | + "fourth": "some/sub/path", |
| 117 | + } |
| 118 | + |
| 119 | + spans = self.get_spans() |
| 120 | + self.assertEqual(len(spans), 8) |
| 121 | + |
| 122 | + root = spans[0] |
| 123 | + assert root.name == "flask.request" |
| 124 | + assert root.get_tag(http.URL) == "http://localhost/route_params/test/100/5.5/some/sub/path" |
| 125 | + assert root.get_tag("flask.endpoint") == "route_params" |
| 126 | + assert root.get_tag("flask.url_rule") == "/route_params/<first>/<int:second>/<float:third>/<path:fourth>" |
| 127 | + assert root.get_tag("flask.view_args.first") == "test" |
| 128 | + assert root.get_metric("flask.view_args.second") == 100.0 |
| 129 | + assert root.get_metric("flask.view_args.third") == 5.5 |
| 130 | + assert root.get_tag("flask.view_args.fourth") == "some/sub/path" |
| 131 | + |
85 | 132 | def test_request_query_string_trace(self): |
86 | 133 | """Make sure when making a request that we create the expected spans and capture the query string.""" |
87 | 134 |
|
|
0 commit comments