Fatal `TypeError` in `PsrLogger` (gRPC): String timestamp passed to Serializer instead of array (Logging V2) · Issue #9077 · googleapis/google-cloud-php · GitHub
Skip to content

Fatal TypeError in PsrLogger (gRPC): String timestamp passed to Serializer instead of array (Logging V2) #9077

Description

@iamacarpet

Environment:

Description:
Following the merge of #9007, which switches the default Logging client to V2, using the PsrLogger with the default gRPC transport results in a fatal TypeError if an explicit timestamp is not provided.

When a log entry is created without an explicit timestamp in the $context array, the Cloud Logging library auto-generates a string timestamp (RFC3339 format). However, when this entry is passed down to the gRPC transport layer, Google\ApiCore\Serializer::decodeMessageImpl() strictly expects the timestamp field for the Protobuf message to be an array (or a valid Protobuf Timestamp object). Because it receives a string, it throws a Fatal Error and crashes the application.

Steps to Reproduce:

  1. Instantiate a PsrLogger using the default gRPC transport in google/cloud >= 0.323.
  2. Log a message without explicitly passing a Protobuf Timestamp in the context:
    $psrLogger->error('Test error message', ['context' => []]);
  3. The library generates a string timestamp by default, which causes gRPC's Serializer to crash.

Stack Trace:

PHP message: PHP Fatal error:  Uncaught TypeError: Google\ApiCore\Serializer::decodeMessageImpl(): Argument #3 ($data) must be of type array, string given, called in /workspace/vendor/google/gax/src/Serializer.php on line 403 and defined in /workspace/vendor/google/gax/src/Serializer.php:416
Stack trace:
#0 /workspace/vendor/google/gax/src/Serializer.php(403): Google\ApiCore\Serializer->decodeMessageImpl(Object(Google\Protobuf\Timestamp), Object(Google\Protobuf\Descriptor), '2026-04-02T15:2...')
#1 /workspace/vendor/google/gax/src/Serializer.php(451): Google\ApiCore\Serializer->decodeElement(Object(Google\Protobuf\FieldDescriptor), '2026-04-02T15:2...')
#2 /workspace/vendor/google/gax/src/Serializer.php(403): Google\ApiCore\Serializer->decodeMessageImpl(Object(Google\Cloud\Logging\V2\LogEntry), Object(Google\Protobuf\Descriptor), Array)
#3 /workspace/vendor/google/gax/src/Serializer.php(447): Google\ApiCore\Serializer->decodeElement(Object(Google\Protobuf\FieldDescriptor), Array)
#4 /workspace/vendor/google/gax/src/Serializer.php(136): Google\ApiCore\Serializer->decodeMessageImpl(Object(Google\Cloud\Logging\V2\WriteLogEntriesRequest), Object(Google\Protobuf\Descriptor), Array)
...
#9 /workspace/vendor/google/cloud/Logging/src/PsrLogger.php(550): Google\Cloud\Logging\Logger->write(Object(Google\Cloud\Logging\Entry))

Expected Behavior:
The Logging V2 implementation should either auto-generate a valid Protobuf Timestamp array/object when utilizing the gRPC transport, or the gRPC layer should correctly cast the RFC3339 string timestamp into the expected format before attempting to serialize the message.

Workaround:
Currently, users must either downgrade to google/cloud < 0.323, force the rest transport, or manually inject a new Google\Cloud\Core\Timestamp() object into every PsrLogger call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions