Skip to content

Commit 9082b21

Browse files
authored
Merge branch 'main' into fix
2 parents 1acfe25 + e6df097 commit 9082b21

2 files changed

Lines changed: 19 additions & 51 deletions

File tree

src/google/adk/telemetry/google_cloud.py

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def get_gcp_exporters(
119119
if enable_cloud_logging:
120120
exporter = _get_gcp_logs_exporter(
121121
project_id=project_id,
122-
credentials=credentials,
123122
)
124123
if exporter:
125124
log_record_processors.append(exporter)
@@ -187,11 +186,9 @@ def _get_gcp_metrics_exporter(project_id: str) -> MetricReader:
187186

188187
def _get_gcp_logs_exporter(
189188
project_id: str,
190-
credentials: Optional["Credentials"] = None,
191189
) -> LogRecordProcessor:
192190
if os.getenv("GOOGLE_CLOUD_AGENT_ENGINE_ID"):
193191
return _get_agent_engine_logs_exporter(
194-
credentials=credentials,
195192
project_id=project_id,
196193
)
197194

@@ -338,18 +335,14 @@ def _use_client_cert_effective() -> bool:
338335

339336
def _get_agent_engine_logs_exporter(
340337
*,
341-
credentials: "Credentials",
342338
project_id: str,
343339
):
344340
"""Configures logging for Agent Engine.
345341
346342
Args:
347-
credentials: Credentials to use for export calls.
348343
project_id: Project to which to write logs.
349344
"""
350345
try:
351-
from google.cloud.logging_v2.services import logging_service_v2
352-
from google.cloud.logging_v2.services.logging_service_v2.transports import grpc
353346
from opentelemetry.exporter import cloud_logging
354347
except (ImportError, AttributeError):
355348
logger.warning(
@@ -363,46 +356,21 @@ def _get_agent_engine_logs_exporter(
363356
)
364357
return
365358

366-
if "gen_ai_latest_experimental" in os.getenv(
367-
"OTEL_SEMCONV_STABILITY_OPT_IN", ""
368-
).split(","):
369-
# Specify credentials to avoid expensive call to `google.auth.default()`
370-
channel = grpc.LoggingServiceV2GrpcTransport.create_channel(
371-
credentials=credentials,
372-
# pylint: disable-next=protected-access
373-
options=cloud_logging._OPTIONS,
374-
)
375-
return BatchLogRecordProcessor(
376-
cloud_logging.CloudLoggingExporter(
377-
client=logging_service_v2.LoggingServiceV2Client(
378-
transport=grpc.LoggingServiceV2GrpcTransport(
379-
credentials=credentials,
380-
channel=channel,
381-
),
382-
),
383-
project_id=project_id,
384-
default_log_name=os.getenv(
385-
"GCP_DEFAULT_LOG_NAME", "adk-on-agent-engine"
386-
),
387-
),
388-
)
389-
else:
390-
391-
class _SimpleLogRecordProcessor(SimpleLogRecordProcessor):
392-
393-
def force_flush(
394-
self, timeout_millis: int = 30000
395-
) -> bool: # pylint: disable=no-self-use
396-
_ = sys.stdout.flush()
397-
_ = sys.stderr.flush()
398-
return super().force_flush()
399-
400-
return _SimpleLogRecordProcessor(
401-
cloud_logging.CloudLoggingExporter(
402-
project_id=project_id,
403-
default_log_name=os.getenv(
404-
"GCP_DEFAULT_LOG_NAME", "adk-on-agent-engine"
405-
),
406-
structured_json_file=sys.stdout,
407-
),
408-
)
359+
class _SimpleLogRecordProcessor(SimpleLogRecordProcessor):
360+
361+
def force_flush(
362+
self, timeout_millis: int = 30000
363+
) -> bool: # pylint: disable=no-self-use
364+
_ = sys.stdout.flush()
365+
_ = sys.stderr.flush()
366+
return super().force_flush()
367+
368+
return _SimpleLogRecordProcessor(
369+
cloud_logging.CloudLoggingExporter(
370+
project_id=project_id,
371+
default_log_name=os.getenv(
372+
"GCP_DEFAULT_LOG_NAME", "adk-on-agent-engine"
373+
),
374+
structured_json_file=sys.stdout,
375+
),
376+
)

tests/unittests/telemetry/test_google_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_get_gcp_exporters(
6262
)
6363
monkeypatch.setattr(
6464
"google.adk.telemetry.google_cloud._get_gcp_logs_exporter",
65-
lambda project_id, credentials: mock.MagicMock(),
65+
lambda project_id: mock.MagicMock(),
6666
)
6767

6868
# Act.

0 commit comments

Comments
 (0)