Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 opentelemetry-exporter-gcp-logging/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add `force_flush` method to `CloudLoggingExporter` (#559)

## Version 1.13.0a0

Released 2026-07-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
_OTEL_SDK_VERSION = opentelemetry_sdk_version.__version__
_USER_AGENT = f"opentelemetry-python {_OTEL_SDK_VERSION}; google-cloud-logging-exporter {__version__}"

logger = logging.getLogger(__name__)

# Set user-agent metadata, see https://github.com/grpc/grpc/issues/23644 and default options
# from
# https://github.com/googleapis/python-logging/blob/5309478c054d0f2b9301817fd835f2098f51dc3a/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py#L179-L182
Expand Down Expand Up @@ -474,5 +476,14 @@ def _write_log_entries_to_client(
"Error while writing to Cloud Logging", exc_info=ex
)

# pylint: disable=unused-argument,no-self-use
def force_flush(self, timeout_millis: float = 30_000) -> bool:
"""Flushes any buffered logs.

For CloudLoggingExporter, this is a no-op as logs are exported synchronously.
"""
logger.debug("force_flush does nothing for CloudLoggingExporter")
return True

def shutdown(self):
pass
13 changes: 13 additions & 0 deletions opentelemetry-exporter-gcp-logging/tests/test_cloud_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Be sure to review the changes.
"""

import logging
import re
from io import StringIO
from textwrap import dedent
Expand Down Expand Up @@ -452,3 +453,15 @@ def test_deprecation_warning():
buf = StringIO()
with pytest.deprecated_call():
CloudLoggingExporter(project_id=PROJECT_ID, structured_json_file=buf)


def test_force_flush(caplog):
buf = StringIO()
with pytest.deprecated_call():
exporter = CloudLoggingExporter(
project_id=PROJECT_ID, structured_json_file=buf
)
with caplog.at_level(logging.DEBUG):
assert exporter.force_flush() is True
assert exporter.force_flush(timeout_millis=1000) is True
assert "force_flush does nothing for CloudLoggingExporter" in caplog.text
Loading