open-telemetry / opentelemetry-php

The OpenTelemetry PHP Library
https://opentelemetry.io/docs/instrumentation/php/
Apache License 2.0
717 stars 179 forks source link

Warnings logged in OTEL SDK causing exceptions in Symfony (using Monolog OTEL interation) #1066

Closed perfectglitch closed 1 year ago

perfectglitch commented 1 year ago

Describe your environment Alpine Linux 3.15 (Docker) PHP 8.2 RoadRunner 2.12 Symfony 5.4 Sylius 1.13 Monolog 2.9

OTEL Composer dependencies:

"open-telemetry/exporter-otlp": "dev-main", "open-telemetry/opentelemetry-auto-symfony": "dev-main", "open-telemetry/sdk": "dev-main", "open-telemetry/transport-grpc": "dev-main",

Steps to reproduce Implement the Monolog log handler that forwards log messages to OTEL logger.

What is the expected behavior? User warnings triggered in OTEL API/SDK do not cause Exceptions in application

What is the actual behavior?

Web request results in unhandled exception.

ErrorException:
User Warning: /usr/src/app/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php(70): attribute with non-homogeneous array values dropped: params

  at /usr/src/app/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php:46
  at OpenTelemetry\SDK\Common\Attribute\AttributesBuilder::doLog('warning', '/usr/src/app/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php(70): attribute with non-homogeneous array values dropped: params', array())
     (/usr/src/app/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php:67)
  at OpenTelemetry\SDK\Common\Attribute\AttributesBuilder::logWarning('attribute with non-homogeneous array values dropped: params')
     (/usr/src/app/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php:70)
brettmc commented 1 year ago

Hi @perfectglitch There are two things going on here. The warning itself is because of a part of the spec I recently implemented, but needs more thought based on what I'm reading in https://github.com/open-telemetry/opentelemetry-specification/pull/2888 (it mentions that log records should be allowed to have complex attributes, which is not what the spec says about attributes)

Secondly, reporting warnings shouldn't be affecting your application. We originally chose error_log as the default reporting mechanism. A while back we dropped the E_USER_ERROR level because it could break applications. It seems like E_USER_WARNING also does this. What would happen if we dropped it back further, to E_USER_NOTICE?

PHP usually comes with php.ini-development and php.ini-production, with differing settings for display_errors, among other things. I'd expect that using the production settings would resolve this, but unsure if it's reasonable even in development for warnings from this library to impact the application.

perfectglitch commented 1 year ago

@brettmc thanks for the quick response. Indeed it's not supposed to cause issues and it turned out to be the default behavior for Symfony in debug mode. There are settings available to mitigate this: https://symfony.com/doc/current/reference/configuration/framework.html#throw Seems like debug.error_handler.throw_at should be bumped a notch. Not sure how it will affect everything else but that's no longer related to OTEL PHP lib.