forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_benchmark_trace_exporter.py
More file actions
87 lines (72 loc) · 2.79 KB
/
Copy pathtest_benchmark_trace_exporter.py
File metadata and controls
87 lines (72 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 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.
# pylint: disable=invalid-name
from unittest.mock import patch
from opentelemetry.exporter.otlp.proto.http_light._common import (
_OTLPHTTPResponse,
)
from opentelemetry.exporter.otlp.proto.http_light.trace_exporter import (
OTLPSpanExporter,
)
from opentelemetry.sdk.trace import TracerProvider, sampling
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
SimpleSpanProcessor,
)
_MOCK_RESPONSE = _OTLPHTTPResponse(200, "OK")
def get_tracer_with_processor(span_processor_class):
span_processor = span_processor_class(
OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces")
)
tracer = TracerProvider(
active_span_processor=span_processor,
sampler=sampling.DEFAULT_ON,
).get_tracer("pipeline_benchmark_tracer")
return tracer
@patch(
"opentelemetry.exporter.otlp.proto.http_light._common._OTLPHTTPClient.post",
return_value=_MOCK_RESPONSE,
)
def test_simple_span_processor(mock_post, benchmark):
tracer = get_tracer_with_processor(SimpleSpanProcessor)
def create_spans_to_be_exported():
span = tracer.start_span("benchmarkedSpan")
for i in range(10):
span.set_attribute(
f"benchmarkAttribute_{i}",
f"benchmarkAttrValue_{i}",
)
span.end()
benchmark(create_spans_to_be_exported)
@patch(
"opentelemetry.exporter.otlp.proto.http_light._common._OTLPHTTPClient.post",
return_value=_MOCK_RESPONSE,
)
def test_batch_span_processor(mock_post, benchmark):
"""Runs benchmark tests using BatchSpanProcessor.
One particular call by pytest-benchmark will be much more expensive since
the batch export thread will activate and consume a lot of CPU to process
all the spans. For this reason, focus on the average measurement. Do not
focus on the min/max measurements which will be misleading.
"""
tracer = get_tracer_with_processor(BatchSpanProcessor)
def create_spans_to_be_exported():
span = tracer.start_span("benchmarkedSpan")
for i in range(10):
span.set_attribute(
f"benchmarkAttribute_{i}",
f"benchmarkAttrValue_{i}",
)
span.end()
benchmark(create_spans_to_be_exported)