Skip to content

Commit 4083cac

Browse files
NathanielRNalrex
and
alrex
authored
Add b3 format benchmark tests (open-telemetry#1489)
Co-authored-by: alrex <aboten@lightstep.com>
1 parent 33c9269 commit 4083cac

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import opentelemetry.propagators.b3 as b3_format
16+
import opentelemetry.sdk.trace as trace
17+
from opentelemetry.trace.propagation.textmap import DictGetter
18+
19+
FORMAT = b3_format.B3Format()
20+
21+
22+
def test_extract_single_header(benchmark):
23+
benchmark(
24+
FORMAT.extract,
25+
DictGetter(),
26+
{
27+
FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-c32d953d73ad2251-1-11fd79a30b0896cd285b396ae102dd76"
28+
},
29+
)
30+
31+
32+
def test_inject_empty_context(benchmark):
33+
tracer = trace.TracerProvider().get_tracer("sdk_tracer_provider")
34+
with tracer.start_as_current_span("Root Span"):
35+
with tracer.start_as_current_span("Child Span"):
36+
benchmark(
37+
FORMAT.inject,
38+
dict.__setitem__,
39+
{
40+
FORMAT.TRACE_ID_KEY: "bdb5b63237ed38aea578af665aa5aa60",
41+
FORMAT.SPAN_ID_KEY: "00000000000000000c32d953d73ad225",
42+
FORMAT.PARENT_SPAN_ID_KEY: "11fd79a30b0896cd285b396ae102dd76",
43+
FORMAT.SAMPLED_KEY: "1",
44+
},
45+
)

0 commit comments

Comments
 (0)