Skip to content

Commit 9113a1b

Browse files
authored
Do not send template attribute with logs when there are no template values (#1885)
1 parent 071576d commit 9113a1b

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/Logs/LogsAggregator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public function add(
7676
->setAttribute('sentry.release', $options->getRelease())
7777
->setAttribute('sentry.environment', $options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT)
7878
->setAttribute('sentry.server.address', $options->getServerName())
79-
->setAttribute('sentry.message.template', $message)
8079
->setAttribute('sentry.trace.parent_span_id', $hub->getSpan() ? $hub->getSpan()->getSpanId() : null);
8180

8281
if ($client instanceof Client) {
@@ -99,8 +98,12 @@ public function add(
9998
}
10099
});
101100

102-
foreach ($values as $key => $value) {
103-
$log->setAttribute("sentry.message.parameter.{$key}", $value);
101+
if (\count($values)) {
102+
$log->setAttribute('sentry.message.template', $message);
103+
104+
foreach ($values as $key => $value) {
105+
$log->setAttribute("sentry.message.parameter.{$key}", $value);
106+
}
104107
}
105108

106109
$attributes = Arr::simpleDot($attributes);

tests/Logs/LogsAggregatorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public function testMessageFormatting(string $message, array $values, string $ex
105105
$log = $logs[0];
106106

107107
$this->assertSame($expected, $log->getBody());
108+
109+
if (\count($values)) {
110+
$this->assertNotNull($log->attributes()->get('sentry.message.template'));
111+
} else {
112+
$this->assertNull($log->attributes()->get('sentry.message.template'));
113+
}
108114
}
109115

110116
public static function messageFormattingDataProvider(): \Generator

0 commit comments

Comments
 (0)