Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Logs/LogsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function add(
$log = (new Log($timestamp, $traceId, $level, $formattedMessage))
->setAttribute('sentry.release', $options->getRelease())
->setAttribute('sentry.environment', $options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT)
->setAttribute('sentry.server.address', $options->getServerName())
->setAttribute('server.address', $options->getServerName())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed attribute leaks through test attribute filter

Medium Severity

Renaming sentry.server.address to server.address breaks the testAttributes test. That test filters out internal attributes using !str_starts_with($key, 'sentry.'), which previously excluded sentry.server.address. Now server.address passes through the filter, causing every test case in attributesDataProvider to fail because the actual result includes an unexpected server.address key alongside the user-supplied attributes.

Additional Locations (1)
Fix in Cursor Fix in Web

->setAttribute('sentry.trace.parent_span_id', $parentSpanId);

if ($client instanceof Client) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Logs/LogsAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testAttributes(array $attributes, array $expected): void
$log->attributes()->toSimpleArray(),
static function (string $key) {
// We are not testing internal Sentry attributes here, only the ones the user supplied
return !str_starts_with($key, 'sentry.');
return !str_starts_with($key, 'sentry.') && $key !== 'server.address';
},
\ARRAY_FILTER_USE_KEY
)
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testAttributesAreAddedToLogMessage(): void

$this->assertSame('1.0.0', $attributes->get('sentry.release')->getValue());
$this->assertSame('production', $attributes->get('sentry.environment')->getValue());
$this->assertSame('web-server-01', $attributes->get('sentry.server.address')->getValue());
$this->assertSame('web-server-01', $attributes->get('server.address')->getValue());
$this->assertSame('User %s performed action %s', $attributes->get('sentry.message.template')->getValue());
$this->assertSame('566e3688a61d4bc8', $attributes->get('sentry.trace.parent_span_id')->getValue());
$this->assertSame('sentry.php', $attributes->get('sentry.sdk.name')->getValue());
Expand Down
2 changes: 1 addition & 1 deletion tests/Monolog/LogsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testHandle($record, Log $expectedLog): void
$log->attributes()->toSimpleArray(),
static function (string $key) {
// We are not testing Sentry's own attributes here, only the ones the user supplied so filter them out of the expected attributes
return !str_starts_with($key, 'sentry.');
return !str_starts_with($key, 'sentry.') && $key !== 'server.address';
},
\ARRAY_FILTER_USE_KEY
)
Expand Down
Loading