From 9932bf1d801955e27d4c00b8f40e0c2e835794ae Mon Sep 17 00:00:00 2001 From: Nathaniel Ruiz Nowell Date: Wed, 9 Dec 2020 16:57:09 -0800 Subject: [PATCH 1/6] Add b3 format benchmark tests --- .../propagation/test_benchmark_b3_format.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py diff --git a/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py new file mode 100644 index 00000000000..7e8eef2bbd3 --- /dev/null +++ b/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py @@ -0,0 +1,42 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from unittest import mock + +import opentelemetry.sdk.trace as trace +import opentelemetry.sdk.trace.propagation.b3_format as b3_format +from opentelemetry.trace.propagation.textmap import DictGetter + +FORMAT = b3_format.B3Format() + + +@mock.patch( + "opentelemetry.sdk.trace.propagation.b3_format.trace.get_tracer_provider", + new=trace.TracerProvider, +) +def test_extract_single_header(benchmark): + benchmark( + FORMAT.extract, + DictGetter(), + { + FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-00000000000000000c32d953d73ad225" + }, + ) + + +def test_inject_empty_context(benchmark): + tracer = trace.TracerProvider().get_tracer("sdk_tracer_provider") + with tracer.start_as_current_span("Root Span"): + with tracer.start_as_current_span("Child Span"): + benchmark(FORMAT.inject, dict.__setitem__, {}) From 8de90160ddc82bf6a47f7a4aa275057339104a5c Mon Sep 17 00:00:00 2001 From: Nathaniel Ruiz Nowell Date: Tue, 12 Jan 2021 14:45:40 -0800 Subject: [PATCH 2/6] benchmarking injecting into a full context --- .../trace/propagation/test_benchmark_b3_format.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py index 7e8eef2bbd3..0201ad60169 100644 --- a/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py +++ b/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py @@ -30,7 +30,7 @@ def test_extract_single_header(benchmark): FORMAT.extract, DictGetter(), { - FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-00000000000000000c32d953d73ad225" + FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-00000000000000000c32d953d73ad225-1-11fd79a30b0896cd285b396ae102dd76" }, ) @@ -39,4 +39,13 @@ def test_inject_empty_context(benchmark): tracer = trace.TracerProvider().get_tracer("sdk_tracer_provider") with tracer.start_as_current_span("Root Span"): with tracer.start_as_current_span("Child Span"): - benchmark(FORMAT.inject, dict.__setitem__, {}) + benchmark( + FORMAT.inject, + dict.__setitem__, + { + FORMAT.TRACE_ID_KEY: "bdb5b63237ed38aea578af665aa5aa60", + FORMAT.SPAN_ID_KEY: "00000000000000000c32d953d73ad225", + FORMAT.PARENT_SPAN_ID_KEY: "11fd79a30b0896cd285b396ae102dd76", + FORMAT.SAMPLED_KEY: "1", + }, + ) From 781c433b93039aeb1d2c6419066eb908421609b5 Mon Sep 17 00:00:00 2001 From: Nathaniel Ruiz Nowell Date: Tue, 12 Jan 2021 14:47:24 -0800 Subject: [PATCH 3/6] Move propagator tests with b3 propagator --- .../benchmarks/trace/propagation/test_benchmark_b3_format.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {opentelemetry-sdk => propagator/opentelemetry-propagator-b3}/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py (100%) diff --git a/opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py similarity index 100% rename from opentelemetry-sdk/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py rename to propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py From 6862e20f1f4dc0ff30fb66d27f8b27d88a68a0bd Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 18 Jan 2021 14:47:11 -0800 Subject: [PATCH 4/6] fix import path --- .../benchmarks/trace/propagation/test_benchmark_b3_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py index 0201ad60169..2419eb93a85 100644 --- a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py +++ b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py @@ -14,8 +14,8 @@ from unittest import mock +import opentelemetry.propagators.b3 as b3_format import opentelemetry.sdk.trace as trace -import opentelemetry.sdk.trace.propagation.b3_format as b3_format from opentelemetry.trace.propagation.textmap import DictGetter FORMAT = b3_format.B3Format() From 7834f70d60b214b603508712ac8d3c0054615285 Mon Sep 17 00:00:00 2001 From: alrex Date: Mon, 18 Jan 2021 15:02:55 -0800 Subject: [PATCH 5/6] fix test --- .../benchmarks/trace/propagation/test_benchmark_b3_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py index 2419eb93a85..1d2c4d3eafe 100644 --- a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py +++ b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py @@ -22,7 +22,7 @@ @mock.patch( - "opentelemetry.sdk.trace.propagation.b3_format.trace.get_tracer_provider", + "opentelemetry.propagators.b3.trace.get_tracer_provider", new=trace.TracerProvider, ) def test_extract_single_header(benchmark): From 12f9a7fc76fe3faf75e1d968d098ca156999bba4 Mon Sep 17 00:00:00 2001 From: alrex Date: Wed, 20 Jan 2021 11:22:44 -0800 Subject: [PATCH 6/6] ensure single header is valid --- .../trace/propagation/test_benchmark_b3_format.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py index 1d2c4d3eafe..843e6e96b0c 100644 --- a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py +++ b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from unittest import mock - import opentelemetry.propagators.b3 as b3_format import opentelemetry.sdk.trace as trace from opentelemetry.trace.propagation.textmap import DictGetter @@ -21,16 +19,12 @@ FORMAT = b3_format.B3Format() -@mock.patch( - "opentelemetry.propagators.b3.trace.get_tracer_provider", - new=trace.TracerProvider, -) def test_extract_single_header(benchmark): benchmark( FORMAT.extract, DictGetter(), { - FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-00000000000000000c32d953d73ad225-1-11fd79a30b0896cd285b396ae102dd76" + FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-c32d953d73ad2251-1-11fd79a30b0896cd285b396ae102dd76" }, )