Skip to content

Commit 9dcb383

Browse files
committed
ref(logs): extract attribute compilation to dedicated method in LogsHandler
Extracts the attribute merging logic into a new compileAttributes() method for better organization and readability. The new method properly structures log attributes with namespaced keys (log.context, log.extra, log.channel) while maintaining the existing sentry.origin attribute.
1 parent bc33d2b commit 9dcb383

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Monolog/LogsHandler.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handle($record): bool
6666
self::getSentryLogLevelFromMonologLevel($record['level']),
6767
$record['message'],
6868
[],
69-
array_merge($record['context'], $record['extra'], ['sentry.origin' => 'auto.logger.monolog'])
69+
$this->compileAttributes($record)
7070
);
7171

7272
return $this->bubble === false;
@@ -123,4 +123,17 @@ public function __destruct()
123123
// Just in case so that the destructor can never fail.
124124
}
125125
}
126+
127+
/**
128+
* @param array<string, mixed>|LogRecord $record
129+
*/
130+
protected function compileAttributes($record): array
131+
{
132+
return [
133+
'log.context' => $record['context'],
134+
'log.extra' => $record['extra'],
135+
'log.channel' => $record['channel'],
136+
'sentry.origin' => 'auto.logger.monolog',
137+
];
138+
}
126139
}

0 commit comments

Comments
 (0)