[Monolog] Add option to directly assign context elements as attributes#467
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
============================================
+ Coverage 83.41% 83.46% +0.04%
- Complexity 2317 2330 +13
============================================
Files 149 149
Lines 8769 8791 +22
============================================
+ Hits 7315 7337 +22
Misses 1454 1454 Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
I think this makes sense. Can the non-default mode (OTEL_PHP_MONOLOG_ATTRIB_MODE=otel) be tested ? |
I copied the behavior from the PSR-3 Instrumentation library, which appears to be the only instance of |
|
Tests added. CI failures are for Symphony, unrelated to this PR. |
|
I think this is ready if y'all want to look it over again @open-telemetry/php-approvers Edit: I guess team mentions are disabled? Will comment in Slack. |
This PR modifies how Monolog
contextandextrasarrays behave, and adds specific behavior for exceptions.General Attributes
Per PSR-3:
Per Monolog:
Per OTel Spec Logs Data Model:
These descriptions indicate the intent of the context array of PSR-3, and to a lesser extent, the extras array of Monolog, has the same intended function as the Log Record Attributes of OpenTelemetry.
While identifying the need to prevent breaking existing implementations of the OpenTelemetry Monolog Handler, we suggest adding
OTEL_PHP_MONOLOG_ATTRIB_MODEas a runtime configuration option to switch between the current behavior that prioritizes PSR-3 flexibility and safety, and a new behavior that prioritizes the OpenTelemetry spec and SemConv.Examples are in the README.md.
Exceptions
Per PSR-3:
Per the OTel Spec:
Per the OTel SemConv:
These descriptions indicate that exceptions included in the
contextarray under theexceptionkey should be treated differently than other general keys. This behavior is also included in this PR, regardless of the attributes mode.