From f91d6774ca1b6475db4951e83061def1d7088f3b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 5 May 2025 22:49:06 -0400 Subject: [PATCH] Add a schema for source location. --- .../log_stream/log_stream/log_entry.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/google_cloud_logging/log_stream/log_stream/log_entry.py b/google_cloud_logging/log_stream/log_stream/log_entry.py index d6754c9..84f25eb 100644 --- a/google_cloud_logging/log_stream/log_stream/log_entry.py +++ b/google_cloud_logging/log_stream/log_stream/log_entry.py @@ -28,8 +28,8 @@ class BaseLogEntry(BaseModel): span_id: Annotated[str | None, Field(alias="spanId", default=None)] trace_sampled: Annotated[bool | None, Field(alias="traceSampled", default=None)] source_location: Annotated[ - dict | None, Field(alias="sourceLocation", default=None) - ] # https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation + SourceLocation | None, Field(alias="sourceLocation", default=None) + ] split: Annotated[ dict | None, Field(default=None) ] # https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSplit @@ -56,6 +56,12 @@ class JsonPayloadLogEntry(BaseLogEntry): json_payload: Annotated[dict, Field(alias="jsonPayload")] +LogEntry = Annotated[ + Union[ProtoPayloadLogEntry, JsonPayloadLogEntry, TextPayloadLogEntry, BaseLogEntry], + Field(), +] + + class LogSeverity(str, Enum): # https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity DEFAULT = "DEFAULT" @@ -69,10 +75,11 @@ class LogSeverity(str, Enum): EMERGENCY = "EMERGENCY" -LogEntry = Annotated[ - Union[ProtoPayloadLogEntry, JsonPayloadLogEntry, TextPayloadLogEntry, BaseLogEntry], - Field(), -] +class SourceLocation(BaseModel): + # https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation + file: str + line: str + function: Annotated[str | None, Field(default=None)] def create_log_entry(entry: dict) -> LogEntry: