Skip to content

Commit 7c204cf

Browse files
o11y: Downgrade OTEL logs to DEBUG by default, make it configurable (#558)
The goal of this PR is primarily to downgrade OTEL logs to `DEBUG`, but at the same time allow for keeping the previous behavior through the use `OTEL_LOG_LEVEL` env var. This should clean the logs that are currently flooded with time statistics. --------- Co-authored-by: Paweł Chmielak <[email protected]>
1 parent 5824c53 commit 7c204cf

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.59
2+
3+
* **o11y: Downgrade OTEL logs to `DEBUG` by default, make it configurable**
4+
15
## 1.0.58
26

37
* **o11y: Improved logging in connectors' operations with LoggingMixin class**

examples/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from unstructured_ingest.processes.embedder import EmbedderConfig
1515
from unstructured_ingest.processes.partitioner import PartitionerConfig
1616

17-
base_path = Path(__file__).parent.parent.parent.parent
17+
base_path = Path(__file__).parent.parent
1818
docs_path = base_path / "example-docs"
1919
work_dir = base_path / "tmp_ingest" / CONNECTOR_TYPE
2020
output_path = work_dir / "output"

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.58" # pragma: no cover
1+
__version__ = "1.0.59" # pragma: no cover

unstructured_ingest/otel.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
from dataclasses import dataclass, field
34
from typing import Callable, ClassVar, Optional, Protocol, Sequence
@@ -31,13 +32,27 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
3132
self.log_out(self.formatter(span))
3233
return SpanExportResult.SUCCESS
3334

35+
def get_log_out() -> Callable:
36+
level_names_mapping = {
37+
'CRITICAL': logging.CRITICAL,
38+
'FATAL': logging.FATAL,
39+
'ERROR': logging.ERROR,
40+
'WARN': logging.WARNING,
41+
'WARNING': logging.WARNING,
42+
'INFO': logging.INFO,
43+
'DEBUG': logging.DEBUG,
44+
'NOTSET': logging.NOTSET,
45+
}
46+
log_level = os.getenv("OTEL_LOG_LEVEL", "DEBUG").upper()
47+
log_level_int = level_names_mapping.get(log_level, logging.DEBUG)
48+
return lambda message: logger.log(log_level_int, message)
3449

3550
@dataclass
3651
class OtelHandler:
3752
otel_endpoint: Optional[str] = None
3853
service_name: str = "unstructured-ingest"
3954
trace_provider: TracerProvider = field(init=False)
40-
log_out: Callable = field(default=logger.info)
55+
log_out: Callable = field(default=get_log_out())
4156
trace_context_key: ClassVar[str] = "_trace_context"
4257

4358
def init_trace(self):

0 commit comments

Comments
 (0)