Skip to content

Commit ef7a0f6

Browse files
committed
add more benchmark for logs signal
1 parent 102fec2 commit ef7a0f6

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

opentelemetry-sdk/benchmarks/logs/test_benchmark_logging_handler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
import logging
216

317
import pytest
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 pytest
16+
17+
from opentelemetry._logs import SeverityNumber
18+
from opentelemetry.sdk._logs import LoggerProvider
19+
from opentelemetry.sdk._logs.export import (
20+
BatchLogRecordProcessor,
21+
InMemoryLogRecordExporter,
22+
SimpleLogRecordProcessor,
23+
)
24+
from opentelemetry.sdk.resources import Resource
25+
26+
resource = Resource(
27+
{
28+
"service.name": "A123456789",
29+
"service.version": "1.34567890",
30+
"service.instance.id": "123ab456-a123-12ab-12ab-12340a1abc12",
31+
}
32+
)
33+
34+
simple_exporter = InMemoryLogRecordExporter()
35+
simple_provider = LoggerProvider(resource=resource)
36+
simple_provider.add_log_record_processor(
37+
SimpleLogRecordProcessor(simple_exporter)
38+
)
39+
simple_logger = simple_provider.get_logger("simple_logger")
40+
41+
batch_exporter = InMemoryLogRecordExporter()
42+
batch_provider = LoggerProvider(resource=resource)
43+
batch_provider.add_log_record_processor(
44+
BatchLogRecordProcessor(batch_exporter)
45+
)
46+
batch_logger = batch_provider.get_logger("batch_logger")
47+
48+
49+
@pytest.mark.parametrize("num_attributes", [0, 1, 3, 5, 10])
50+
def test_simple_log_record_processor(benchmark, num_attributes):
51+
attributes = {f"key{i}": f"value{i}" for i in range(num_attributes)}
52+
53+
def benchmark_emit():
54+
simple_logger.emit(
55+
severity_number=SeverityNumber.INFO,
56+
body="benchmark log message",
57+
attributes=attributes,
58+
event_name="test.event",
59+
)
60+
61+
benchmark(benchmark_emit)
62+
63+
64+
@pytest.mark.parametrize("num_attributes", [0, 1, 3, 5, 10])
65+
def test_batch_log_record_processor(benchmark, num_attributes):
66+
attributes = {f"key{i}": f"value{i}" for i in range(num_attributes)}
67+
68+
def benchmark_emit():
69+
batch_logger.emit(
70+
severity_number=SeverityNumber.INFO,
71+
body="benchmark log message",
72+
attributes=attributes,
73+
event_name="test.event",
74+
)
75+
76+
benchmark(benchmark_emit)
77+
78+
79+
def test_get_logger(benchmark):
80+
def benchmark_get_logger():
81+
simple_provider.get_logger(
82+
"test_logger",
83+
version="1.0.0",
84+
schema_url="https://opentelemetry.io/schemas/1.38.0",
85+
)
86+
87+
benchmark(benchmark_get_logger)

0 commit comments

Comments
 (0)