From 3fb96437807fe0582d3912838dd3a48ece0ab224 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Mon, 30 Sep 2019 13:40:24 -0700 Subject: [PATCH 1/7] Use default TraceContext propagator in example --- .../src/opentelemetry_example_app/flask_example.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py index 229acdfb435..ccf7d80f5d0 100644 --- a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -42,17 +42,14 @@ def configure_opentelemetry(flask_app: flask.Flask): """ # Start by configuring all objects required to ensure # a complete end to end workflow. - # the preferred implementation of these objects must be set, + # The preferred implementation of these objects must be set, # as the opentelemetry-api defines the interface with a no-op # implementation. trace.set_preferred_tracer_implementation(lambda _: Tracer()) + # Next, we need to configure how the values that are used by # traces and metrics are propagated (such as what specific headers # carry this value). - - # TBD: can remove once default TraceContext propagators are installed. - propagators.set_global_httptextformat(B3Format()) - # Integrations are the glue that binds the OpenTelemetry API # and the frameworks and libraries that are used together, automatically # creating Spans and propagating context as appropriate. From 72991b7ddac0bbde432550000c487d59d148cb77 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Thu, 30 Jan 2020 12:02:40 -0800 Subject: [PATCH 2/7] Update tests --- .../tests/test_flask_example.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index fd0b89e98c3..4c8e811a403 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -20,7 +20,8 @@ from werkzeug.wrappers import BaseResponse import opentelemetry_example_app.flask_example as flask_example -from opentelemetry.sdk import trace +from opentelemetry import trace +from opentelemetry.sdk import trace as trace_sdk from opentelemetry.sdk.context.propagation import b3_format @@ -46,7 +47,7 @@ def tearDown(self): self.send_patcher.stop() def test_full_path(self): - trace_id = trace.generate_trace_id() + trace_id = trace_sdk.generate_trace_id() # We need to use the Werkzeug test app because # The headers are injected at the wsgi layer. # The flask test app will not include these, and @@ -56,18 +57,14 @@ def test_full_path(self): client.get( "/", headers={ - "x-b3-traceid": b3_format.format_trace_id(trace_id), - "x-b3-spanid": b3_format.format_span_id( - trace.generate_span_id() - ), - "x-b3-sampled": "1", + "traceparent": "00-{:032x}-{:016x}-{:02x}".format( + trace_id, + trace_sdk.generate_span_id(), + trace.TraceOptions.RECORDED, + ) }, ) # assert the http request header was propagated through. prepared_request = self.send.call_args[0][1] headers = prepared_request.headers - for required_header in {"x-b3-traceid", "x-b3-spanid", "x-b3-sampled"}: - self.assertIn(required_header, headers) - self.assertEqual( - headers["x-b3-traceid"], b3_format.format_trace_id(trace_id) - ) + self.assertRegex(headers['traceparent'], r'00-{:032x}-.*-01'.format(trace_id)) From fbb4ea3603014ff7b1b044d161c6b4f72cb18658 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Thu, 30 Jan 2020 13:20:47 -0800 Subject: [PATCH 3/7] s/RECORDED/SAMPLED/ --- examples/opentelemetry-example-app/tests/test_flask_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index 4c8e811a403..a2e4b2c0eb0 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -60,7 +60,7 @@ def test_full_path(self): "traceparent": "00-{:032x}-{:016x}-{:02x}".format( trace_id, trace_sdk.generate_span_id(), - trace.TraceOptions.RECORDED, + trace.TraceOptions.SAMPLED, ) }, ) From e1693ebedbb9bf4e36dad0978d57b83cae69d43b Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Thu, 30 Jan 2020 13:33:30 -0800 Subject: [PATCH 4/7] Blacken --- .../opentelemetry-example-app/tests/test_flask_example.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index a2e4b2c0eb0..17b5d385804 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -67,4 +67,6 @@ def test_full_path(self): # assert the http request header was propagated through. prepared_request = self.send.call_args[0][1] headers = prepared_request.headers - self.assertRegex(headers['traceparent'], r'00-{:032x}-.*-01'.format(trace_id)) + self.assertRegex( + headers["traceparent"], r"00-{:032x}-.*-01".format(trace_id) + ) From 2871055df93ec812fbe47d47abb549c62770fff6 Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Thu, 30 Jan 2020 13:56:01 -0800 Subject: [PATCH 5/7] Linten --- .../src/opentelemetry_example_app/flask_example.py | 3 +-- examples/opentelemetry-example-app/tests/test_flask_example.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py index 1a0605b44ac..f7a9872b6b6 100644 --- a/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py +++ b/examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py @@ -21,9 +21,8 @@ import requests import opentelemetry.ext.http_requests -from opentelemetry import propagators, trace +from opentelemetry import trace from opentelemetry.ext.flask import instrument_app -from opentelemetry.sdk.context.propagation.b3_format import B3Format from opentelemetry.sdk.trace import TracerSource diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index 17b5d385804..8640687ec0b 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -22,7 +22,6 @@ import opentelemetry_example_app.flask_example as flask_example from opentelemetry import trace from opentelemetry.sdk import trace as trace_sdk -from opentelemetry.sdk.context.propagation import b3_format class TestFlaskExample(unittest.TestCase): From 630d30cfc17550bddd845a30abdc571b2d8f842b Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Fri, 31 Jan 2020 11:50:35 -0800 Subject: [PATCH 6/7] Update examples/opentelemetry-example-app/tests/test_flask_example.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Christian Neumüller --- examples/opentelemetry-example-app/tests/test_flask_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index 8640687ec0b..d441bda34db 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -67,5 +67,5 @@ def test_full_path(self): prepared_request = self.send.call_args[0][1] headers = prepared_request.headers self.assertRegex( - headers["traceparent"], r"00-{:032x}-.*-01".format(trace_id) + headers["traceparent"], r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id) ) From e4ce950ec3c0f91da322ddb03535fe7d0f68c04a Mon Sep 17 00:00:00 2001 From: Chris Kleinknecht Date: Fri, 31 Jan 2020 13:04:28 -0800 Subject: [PATCH 7/7] Reblacken --- examples/opentelemetry-example-app/tests/test_flask_example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/opentelemetry-example-app/tests/test_flask_example.py b/examples/opentelemetry-example-app/tests/test_flask_example.py index d441bda34db..69be9e4bfc7 100644 --- a/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -67,5 +67,6 @@ def test_full_path(self): prepared_request = self.send.call_args[0][1] headers = prepared_request.headers self.assertRegex( - headers["traceparent"], r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id) + headers["traceparent"], + r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id), )