forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
273 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
opentelemetry-sdk/benchmarks/logs/test_benchmark_logging_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler | ||
from opentelemetry.sdk._logs.export import ( | ||
InMemoryLogExporter, | ||
SimpleLogRecordProcessor, | ||
) | ||
|
||
|
||
def _set_up_logging_handler(level): | ||
logger_provider = LoggerProvider() | ||
exporter = InMemoryLogExporter() | ||
processor = SimpleLogRecordProcessor(exporter=exporter) | ||
logger_provider.add_log_record_processor(processor) | ||
handler = LoggingHandler(level=level, logger_provider=logger_provider) | ||
return handler | ||
|
||
|
||
def _create_logger(handler, name): | ||
logger = logging.getLogger(name) | ||
logger.addHandler(handler) | ||
return logger | ||
|
||
|
||
@pytest.mark.parametrize("num_loggers", [1, 10, 100, 1000]) | ||
def test_simple_get_logger_different_names(benchmark, num_loggers): | ||
handler = _set_up_logging_handler(level=logging.DEBUG) | ||
loggers = [ | ||
_create_logger(handler, str(f"logger_{i}")) for i in range(num_loggers) | ||
] | ||
|
||
def benchmark_get_logger(): | ||
for index in range(1000): | ||
loggers[index % num_loggers].warning("test message") | ||
|
||
benchmark(benchmark_get_logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.