Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using monolog processors #742

Open
jamesmehorter opened this issue Oct 4, 2023 · 3 comments
Open

Allow using monolog processors #742

jamesmehorter opened this issue Oct 4, 2023 · 3 comments
Labels
enhancement New feature or request logging

Comments

@jamesmehorter
Copy link

jamesmehorter commented Oct 4, 2023

Summary

Because of how this project grabs calls to monolog's addRecord, it completely bypasses any monolog processors.

See https://github.com/Seldaek/monolog/blob/main/doc/02-handlers-formatters-processors.md#processors

  1. Log entry created (New Relic PHP Agent grabs the log entry and sends to NR)
  2. Monolog runs processors
  3. Monolog outputs the log entry

Basically, the agent grabs the log before monolog processors have a chance to run

Desired Behavior

Use of monolog processors is supported by the New Relic PHP Agent, allowing use of processors bundled with monolog, or custom processors created by users.

Additional context

A processor is used to decorate log entries, for example, to modify a log message or perhaps add data to the $context array prior to output. Some of the processors bundled with monolog are unhelpful in the context of New Relic, e.g. the WebProcessor is not really needed thanks to how this project collects that information with each Transaction (though, someone may find it helpful to have this information on log entries as well.

In our case, we use Laravel, and built a custom monolog processor to decorate all log entry $context arrays with the Laravel session ID. This is VERY important because it allows us to find all log entries tied to a specific user. I.e. a user submits a bug about an error they ran into, we can locate their session ID from their email address, then locate all logs generated by that user's journey; allowing us to identify what went wrong and in-turn guide the user or update our code.

The only way we've made this work with the current version of the New Relic PHP Agent is to log the session ID with each log entry. This has been less-than ideal as we're trying to migrate from Kibana to New Relic, and requires updating hundreds of log entries in our code base, e.g.

Log::debug(json_encode(['message' => 'something failed', 'context' => ['session_id' => session()->getId()]]);

NRQL

SELECT message FROM Log WHERE context.session_id = 'XXYYZZ'

@jamesmehorter jamesmehorter added the enhancement New feature or request label Oct 4, 2023
@mfulb mfulb added the logging label Nov 27, 2023
@tsantos84
Copy link

tsantos84 commented Nov 29, 2023

Monolog has an official processor aimed to replace placeholders in log messages (eg. {foo}) by its value defined in log context.

Eg.

$logger->info('User {username} logged in', ['username' => 'Foo User']);

In this case the placeholder {username} would be replaced by Foo User.

BUT, In current version of PHP Agent, this behaviour don't work due the points related by @jamesmehorter

@rcwsr
Copy link

rcwsr commented Jan 30, 2024

Also facing this issue, saw tons of Matched route "{route}". from our Symfony app, debugging locally I found that it should have been processed by \Monolog\Processor\PsrLogMessageProcessor as mentioned above. Also explains why the processor I just added to add back the log channel (which NR strips from the log line) to extra didn't seem to be working in New Relic logs!!

Guess I'll have to fall back to forwarding logs from a file via the infra agent?

@huelsmc
Copy link

huelsmc commented Feb 2, 2024

We also have this issue of "missing" data that we added via a Processor
Falling back to file log forwarding might be a workaround (while logs in context within APM probably would be not working this way then)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request logging
Projects
None yet
Development

No branches or pull requests

5 participants