Skip to content

Commit

Permalink
Add performance tests for b3 propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Dec 3, 2020
1 parent 6e5d7f1 commit 0afd9ba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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("parent"):
with tracer.start_as_current_span("child"):
benchmark(FORMAT.inject, dict.__setitem__, {})
4 changes: 2 additions & 2 deletions opentelemetry-sdk/benchmarks/trace/test_benchmark__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_b3_propagator_start_span(benchmark):
def benchmark_start_as_current_span():
span = tracer.start_span(
"benchmarkedSpan",
attributes={"long.attribute": -10000000001000000000}
attributes={"long.attribute": -10000000001000000000},
)
span.add_event("benchmarkEvent")
span.end()
Expand All @@ -44,7 +44,7 @@ def test_b3_propagator_start_as_current_span(benchmark):
def benchmark_start_as_current_span():
with tracer.start_as_current_span(
"benchmarkedSpan",
attributes={"long.attribute": -10000000001000000000}
attributes={"long.attribute": -10000000001000000000},
) as span:
span.add_event("benchmarkEvent")

Expand Down

0 comments on commit 0afd9ba

Please sign in to comment.