Skip to content

Commit

Permalink
feat: [Logging] Add resource labels to logs from Cloud Run (#7642)
Browse files Browse the repository at this point in the history
  • Loading branch information
kynx authored Dec 27, 2024
1 parent 9b3b7fe commit dad50ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"google/cloud-core": "^1.58",
"google/cloud-core": "^1.61",
"google/gax": "^1.36.0"
},
"require-dev": {
Expand Down
22 changes: 19 additions & 3 deletions tests/Unit/PsrLoggerBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
namespace Google\Cloud\Logging\Tests\Unit;

use Google\Cloud\Core\Batch\BatchRunner;
use Google\Cloud\Core\Report\CloudRunMetadataProvider;
use Google\Cloud\Core\Compute\Metadata;
use Google\Cloud\Core\Compute\Metadata\Readers\ReaderInterface;
use Google\Cloud\Core\Report\CloudRunJobMetadataProvider;
use Google\Cloud\Core\Report\CloudRunServiceMetadataProvider;
use Google\Cloud\Core\Report\GAEFlexMetadataProvider;
use Google\Cloud\Logging\Connection\Rest;
use Google\Cloud\Logging\Entry;
Expand All @@ -30,6 +33,8 @@
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;

use function str_repeat;

/**
* @group logging
*/
Expand Down Expand Up @@ -121,13 +126,18 @@ public function testTraceIdLabelOnServerlessPlatforms(
'my-project'
);

$reader = self::createStub(ReaderInterface::class);
$reader->method('read')
->willReturn('');
$metadata = new Metadata($reader);

$psrBatchLogger = new PsrLogger(
$logger,
null,
[
'batchEnabled' => true,
'batchRunner' => $this->runner->reveal(),
'metadataProvider' => new $metadataProviderClass($server)
'metadataProvider' => new $metadataProviderClass($server, $metadata)
]
);

Expand Down Expand Up @@ -201,7 +211,13 @@ public function traceIdProvider()
],
[
str_repeat('x', 32),
CloudRunMetadataProvider::class,
CloudRunServiceMetadataProvider::class,
[],
['run.googleapis.com/trace_id' => str_repeat('x', 32)]
],
[
str_repeat('x', 32),
CloudRunJobMetadataProvider::class,
[],
['run.googleapis.com/trace_id' => str_repeat('x', 32)]
],
Expand Down

0 comments on commit dad50ff

Please sign in to comment.