I am currently using NewRelic and am experiencing a lot of difficulties in retrieving logs with custom fields (for example, allowing for faceted search).
My goal is to manage to retrieve logs in NewRelic in the following format:
{
entity.guid: NDI0MTk5MnxBUE18QVBQTElDQVRJT058NTMzMDg2MzM5,
entity.guids: NDI0MTk5MnxBUE18QVBQTElDQVRJT058NTMzMDg2MzM5,
entity.name: foxnot,
hostname: poc-new-relic-web-1,
level: ERROR,
message: info,
newrelic.source: logs.APM,
span.id: 0295c53b980e73dd,
timestamp: 1701161680672,
trace.id: b83046772a0a770d,
custom_field_1: [email protected],
custom_field_2: myvalue
}
Here is my technical context:
- PHP 8.2,
- Symfony 6,
- Monolog,
- PHP APM Agent installed.
Here is an example of a log that is properly retrieved from Symfony, but whose context fields are systematically ignored.
#[Route('/test', name: 'test')]
public function index(LoggerInterface $logger): JsonResponse
{
$logger->error("info", context: ["user_email" => "[email protected]"]);
$logger->info("mon_info", context: ["user_email" => "[email protected]"]);
return new JsonResponse(['message' => 'hello']);
}
when@prod:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
formatter: 'monolog.formatter.json'
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: php://stderr
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
channels: [deprecation]
path: php://stderr
How can I ensure that the logs are retrieved with the custom fields?
I attempted using the Rest API directly, but it does not meet the requirements in terms of securing the response time. I tried using newrelic_add_custom_parameter, but without any result
Thanks in advance