mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat(otel): set default_log_name for GCP logging exporter
Uses value of GCP_DEFAULT_LOG_NAME env var if it exists, defaults to literal adk-otel. PiperOrigin-RevId: 817125337
This commit is contained in:
committed by
Copybara-Service
parent
9b8a4aad6f
commit
55aa6f669b
@@ -15,6 +15,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from typing import cast
|
from typing import cast
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
@@ -37,6 +38,9 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
logger = logging.getLogger('google_adk.' + __name__)
|
logger = logging.getLogger('google_adk.' + __name__)
|
||||||
|
|
||||||
|
_GCP_LOG_NAME_ENV_VARIABLE_NAME = 'GOOGLE_CLOUD_DEFAULT_LOG_NAME'
|
||||||
|
_DEFAULT_LOG_NAME = 'adk-otel'
|
||||||
|
|
||||||
|
|
||||||
@experimental
|
@experimental
|
||||||
def get_gcp_exporters(
|
def get_gcp_exporters(
|
||||||
@@ -118,9 +122,13 @@ def _get_gcp_metrics_exporter(project_id: str) -> MetricReader:
|
|||||||
def _get_gcp_logs_exporter(project_id: str) -> LogRecordProcessor:
|
def _get_gcp_logs_exporter(project_id: str) -> LogRecordProcessor:
|
||||||
from opentelemetry.exporter.cloud_logging import CloudLoggingExporter
|
from opentelemetry.exporter.cloud_logging import CloudLoggingExporter
|
||||||
|
|
||||||
|
default_log_name = os.environ.get(
|
||||||
|
_GCP_LOG_NAME_ENV_VARIABLE_NAME, _DEFAULT_LOG_NAME
|
||||||
|
)
|
||||||
return BatchLogRecordProcessor(
|
return BatchLogRecordProcessor(
|
||||||
# TODO(jawoszek) - add default_log_name once design is approved.
|
CloudLoggingExporter(
|
||||||
CloudLoggingExporter(project_id=project_id)
|
project_id=project_id, default_log_name=default_log_name
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user