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

adding event dispatcher #708

Closed
wants to merge 16 commits into from
Closed

adding event dispatcher #708

wants to merge 16 commits into from

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Jun 13, 2022

To implement the otel spec requirement that SDK implementations MUST allow end users to change the library's default error handling behavior for relevant errors, implement psr-14 compliant event system. It wraps our existing logging mechanism, so by default we still log errors etc as before, but it is now possible to provide any psr-14 implementation and handle events in some other way.
In passing, fix up some covers annotations in SpanTest which exposed some uncovered code in SpanLimits

Fixes #299
Replaces #603

brettmc added 2 commits June 13, 2022 10:29
per spec, "SDK implementations MUST allow end users to change the library's default error handling behavior for relevant errors"
@codecov
Copy link

codecov bot commented Jun 13, 2022

Codecov Report

Merging #708 (db10181) into main (8f7f399) will increase coverage by 0.41%.
The diff coverage is 98.86%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #708      +/-   ##
============================================
+ Coverage     82.41%   82.82%   +0.41%     
- Complexity     1247     1284      +37     
============================================
  Files           139      150      +11     
  Lines          3048     3127      +79     
============================================
+ Hits           2512     2590      +78     
- Misses          536      537       +1     
Flag Coverage Δ
7.4 82.81% <98.86%> (+0.41%) ⬆️
8.0 82.87% <98.86%> (+0.41%) ⬆️
8.1 82.87% <98.86%> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/API/Behavior/LogsMessagesTrait.php 100.00% <ø> (ø)
src/API/Common/Log/LoggerHolder.php 100.00% <ø> (ø)
src/Contrib/Jaeger/HttpSender.php 100.00% <ø> (ø)
src/Contrib/Jaeger/JaegerTransport.php 86.66% <0.00%> (ø)
src/API/Behavior/EmitsEventsTrait.php 100.00% <100.00%> (ø)
src/API/Common/Event/Dispatcher.php 100.00% <100.00%> (ø)
src/API/Common/Event/Event/DebugEvent.php 100.00% <100.00%> (ø)
src/API/Common/Event/Event/ErrorEvent.php 100.00% <100.00%> (ø)
src/API/Common/Event/Event/WarningEvent.php 100.00% <100.00%> (ø)
src/API/Common/Event/Handler/DebugEventHandler.php 100.00% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f7f399...db10181. Read the comment docs.

*/

//logger used by default event handlers
LoggerHolder::set(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tidal - this might be an opportunity to move LoggerHolder somewhere under SDK\Event ? A way to get rid of the static singleton could be to create something like an AbstractLoggableEvent (or trait) which accepts a LoggerInterface and is extended by our events as required?

Copy link
Contributor

@Nevay Nevay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage over the current approach? Users can already configure the behavior by setting the global logger (Java seems to do the same).

src/SDK/Common/Event/Handler/ErrorEventHandler.php Outdated Show resolved Hide resolved
@brettmc
Copy link
Collaborator Author

brettmc commented Jun 14, 2022

What is the advantage over the current approach? Users can already configure the behavior by setting the global logger (Java seems to do the same).
I agree that just for logging, a PSR-3 implementation such as monolog covers the requirement pretty well (particularly when you can add your own processors and formatters to the logger).

The idea of events came up in a SIG meeting a while back. Aside from being a way to log, the idea was that having events internally would be useful when it came to things like intra-signal messaging (eg, fire a metrics event on batch export with queue size and #records exported). I believe it can also help with #298.

That said, since PSR-14 doesn't provide a mechanism to register event listeners, it concerns me a little that if we did have our own internal events (eg for metrics), then that functionality would be turned off by default if a user decides to use another PSR-14 package (and the onus is on them to register some/all events to re-enable that functionality). Would it then be safer to keep logging directly to a PSR-3 logger, and not expose our internal eventing?

brettmc added 6 commits June 15, 2022 09:45
otel spec says that _all_ otel libraries (including API) should be able to expose troubleshooting telemetry,
so enable that by moving events (and logging) into API
@brettmc
Copy link
Collaborator Author

brettmc commented Jun 22, 2022

Discussed in SIG to shrink this PR back to just providing an event dispatcher. Error logging to be via psr-3 as we currently do.

@brettmc
Copy link
Collaborator Author

brettmc commented Jun 23, 2022

Further notes for the event system: ensure it stays public, and look at using CloudEvents as the basis for the events themselves.

@brettmc brettmc marked this pull request as draft June 24, 2022 11:34
@bobstrecansky
Copy link
Collaborator

Just a quick conflict to resolve with the composer.json ^

@bobstrecansky
Copy link
Collaborator

bobstrecansky commented Jun 29, 2022

@tidal mentioned we want to tie this to an event system as well - cloud events

@brettmc brettmc mentioned this pull request Jul 12, 2022
@brettmc brettmc closed this Jul 13, 2022
@brettmc brettmc deleted the feature/event-dispatcher branch October 25, 2022 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Error Handling: Error Handlers must be configurable
4 participants