Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
41b3f41
Add DuplicateFilter to http/grpc exporter
DylanRussell Jul 21, 2025
75aacde
Precommit and Changelog
DylanRussell Jul 21, 2025
0c1aadf
Fix lint issue. Add comment
DylanRussell Jul 21, 2025
007de16
Update CHANGELOG.md
DylanRussell Jul 22, 2025
99c7af3
Update exporter/opentelemetry-exporter-otlp-proto-common/src/opentele…
DylanRussell Jul 22, 2025
c29039c
Merge branch 'main' into fix_endless_logging
DylanRussell Jul 22, 2025
03cd086
Add filter to BatchProcessor class
DylanRussell Jul 22, 2025
49197c9
Run precommit and add DuplicateFilter to another place..
DylanRussell Jul 22, 2025
cb1a158
Move DuplicateFilter to SDK
DylanRussell Jul 23, 2025
0b84028
Merge remote-tracking branch 'origin' into fix_endless_logging
DylanRussell Jul 23, 2025
bcfc20c
improve changelog entry
DylanRussell Jul 23, 2025
0caca6b
Precommit and comment changes
DylanRussell Jul 23, 2025
b65b152
Merge branch 'main' into fix_endless_logging
DylanRussell Jul 23, 2025
17ce88b
Fix broken test
DylanRussell Jul 23, 2025
614c5c6
Precommit
DylanRussell Jul 23, 2025
470ff1b
Fix lint issue
DylanRussell Jul 23, 2025
95e10b6
precommit
DylanRussell Jul 24, 2025
9c81751
test repro of issue
DylanRussell Jul 24, 2025
3cdd4d1
add print statements
DylanRussell Jul 24, 2025
e6867e0
undo debug stuff
DylanRussell Jul 25, 2025
f0c7eda
Merge branch 'main' into fix_endless_logging
DylanRussell Jul 25, 2025
427e536
Merge remote-tracking branch 'origin' into fix_endless_logging
DylanRussell Aug 12, 2025
a022958
Merge branch 'main' into fix_endless_logging
DylanRussell Aug 21, 2025
6efa3ab
Merge branch 'main' into fix_endless_logging
xrmx Aug 22, 2025
61d1422
Update time to 20s
DylanRussell Aug 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Overwrite logging.config.fileConfig and logging.config.dictConfig to ensure
the OTLP `LogHandler` remains attached to the root logger. Fix a bug that
can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https://github.com/open-telemetry/opentelemetry-python/pull/4636)).
- Filter duplicate logs emitted from the OTLP exporters to avoid endlessly logging when the OTLP logger itself
is failing to export logs.

## Version 1.35.0/0.56b0 (2025-07-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import logging
import time
from collections.abc import Sequence
from typing import (
Any,
Expand Down Expand Up @@ -51,6 +52,21 @@
_ResourceDataT = TypeVar("_ResourceDataT")


class DuplicateFilter(logging.Filter):
def filter(self, record):
current_log = (
record.module,
record.levelno,
record.msg,
time.time() // 60,
)
if current_log != getattr(self, "last_log", None):
self.last_log = current_log
return True
# False means python's `logging` module will no longer process this log.
return False


def _encode_instrumentation_scope(
instrumentation_scope: InstrumentationScope,
) -> PB2InstrumentationScope:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging
import unittest

from opentelemetry.exporter.otlp.proto.common._internal import (
DuplicateFilter,
)


class TestCommonFuncs(unittest.TestCase):
def test_duplicate_logs_filter_works(self):
test_logger = logging.getLogger("testLogger")
test_logger.addFilter(DuplicateFilter())
with self.assertLogs("testLogger") as cm:
test_logger.info("message")
test_logger.info("message")
self.assertEqual(len(cm.output), 1)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
ssl_channel_credentials,
)
from opentelemetry.exporter.otlp.proto.common._internal import (
DuplicateFilter,
_get_resource_data,
)
from opentelemetry.exporter.otlp.proto.grpc import (
Expand Down Expand Up @@ -87,6 +88,8 @@
)
_MAX_RETRYS = 6
logger = getLogger(__name__)
# This prevents logs generated when a log fails to be written to generate another log which fails to be written etc. etc.
logger.addFilter(DuplicateFilter())
SDKDataT = TypeVar("SDKDataT")
ResourceDataT = TypeVar("ResourceDataT")
TypingResourceT = TypeVar("TypingResourceT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import requests
from requests.exceptions import ConnectionError

from opentelemetry.exporter.otlp.proto.common._internal import (
DuplicateFilter,
)
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs
from opentelemetry.exporter.otlp.proto.http import (
_OTLP_HTTP_HEADERS,
Expand Down Expand Up @@ -56,6 +59,8 @@
from opentelemetry.util.re import parse_env_headers

_logger = logging.getLogger(__name__)
# This prevents logs generated when a log fails to be written to generate another log which fails to be written etc. etc.
_logger.addFilter(DuplicateFilter())


DEFAULT_COMPRESSION = Compression.NoCompression
Expand Down
Loading