opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

To use `trigger_error` instead of `error_log`

Open enginvardar opened this issue 11 months ago • 3 comments

Is your feature request related to a problem?

When the logger is not set to LogHolder but a generic error handler is set in application that is set by set_error_handler, error handler is not invoked because error_log function does not trigger this.

Describe the solution you'd like To use trigger_error instead of error_log in ErrorLogWriter to allow error handler to handle logging.

What would you think about a change like this?

enginvardar avatar Jan 09 '25 16:01 enginvardar

I'm not sure that we want that as default behaviour, wouldn't this mean runtime opentelemetry exceptions would/could break the observed application? https://opentelemetry.io/docs/specs/otel/error-handling/#basic-error-handling-principles

brettmc avatar Jan 09 '25 23:01 brettmc

Yes, depending on the error handler implementation the log might turn into unhandled exception and the application could break.

What would you think about adding a "trigger_error" option to LogWriterFactory so we use it only if it is set intentionally?

I am now moving to psr3 logger for my case, but almost all containerized applications need some kind of special formatting for logging and my assumption was that I would be able to handle all logging in the error handler.

enginvardar avatar Jan 10 '25 08:01 enginvardar

What would you think about adding a "trigger_error" option

Adding a new option seems safe enough, if we think there's a use-case for it. Would you like to work on it?

brettmc avatar Jan 15 '25 01:01 brettmc