Skip to content

Commit

Permalink
fix: send StructuredLogHandler instrumentation log using an explicit …
Browse files Browse the repository at this point in the history
…logger (#705)
  • Loading branch information
daniel-sanche committed Jan 18, 2023
1 parent e70e425 commit ac6a2c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion google/cloud/logging_v2/handlers/structured_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,8 @@ def emit(self, record):
def emit_instrumentation_info(self):
google.cloud.logging_v2._instrumentation_emitted = True
diagnostic_object = _create_diagnostic_entry()
logging.info(diagnostic_object.payload)
struct_logger = logging.getLogger(__name__)
struct_logger.addHandler(self)
struct_logger.setLevel(logging.INFO)
struct_logger.info(diagnostic_object.payload)
struct_logger.handlers.clear()
3 changes: 2 additions & 1 deletion tests/unit/handlers/test_structured_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ def test_valid_instrumentation_info(self):
import mock
import json

with mock.patch.object(logging, "info") as mock_log:
logger = logging.getLogger("google.cloud.logging_v2.handlers.structured_log")
with mock.patch.object(logger, "info") as mock_log:
handler = self._make_one()
handler.emit_instrumentation_info()
mock_log.assert_called_once()
Expand Down

0 comments on commit ac6a2c6

Please sign in to comment.