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 #763

Merged
merged 12 commits into from
Jul 18, 2022
Merged

Adding event dispatcher #763

merged 12 commits into from
Jul 18, 2022

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Jul 12, 2022

When discussing #708 in SIG last week, we decided that using it to perform logging was overkill (since psr-3 can provide enough control to meet the spec requirements).
This implements a simplified event dispatcher, based loosely on psr-14 and using CloudEvents to represent events (as suggested during SIG)

Replaces #708

@codecov
Copy link

codecov bot commented Jul 12, 2022

Codecov Report

Merging #763 (317892f) into main (f33b623) will decrease coverage by 4.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #763      +/-   ##
============================================
- Coverage     82.86%   78.66%   -4.20%     
- Complexity     1295     1348      +53     
============================================
  Files           150      156       +6     
  Lines          3192     3314     +122     
============================================
- Hits           2645     2607      -38     
- Misses          547      707     +160     
Flag Coverage Δ
7.4 78.66% <100.00%> (-4.21%) ⬇️
8.0 78.74% <100.00%> (-4.19%) ⬇️
8.1 78.74% <100.00%> (-4.19%) ⬇️

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

Impacted Files Coverage Δ
src/API/Common/Event/Dispatcher.php 100.00% <100.00%> (ø)
src/API/Common/Event/EmitsEventsTrait.php 100.00% <100.00%> (ø)
src/SDK/Trace/Span.php 12.50% <0.00%> (-81.74%) ⬇️
src/SDK/Trace/SpanLimits.php 0.00% <0.00%> (-75.00%) ⬇️
src/API/Trace/AbstractSpan.php 0.00% <0.00%> (-38.89%) ⬇️
src/SDK/Trace/Behavior/HttpSpanExporterTrait.php 93.47% <0.00%> (-1.88%) ⬇️
src/SDK/Trace/Tracer.php 100.00% <0.00%> (ø)
src/SDK/Trace/ExporterFactory.php 100.00% <0.00%> (ø)
src/SDK/Common/Util/WeakMap.php 0.00% <0.00%> (ø)
src/SDK/Common/Util/ShutdownHandler.php 63.63% <0.00%> (ø)
... and 3 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 f33b623...317892f. Read the comment docs.

composer.json Show resolved Hide resolved
src/API/Behavior/EmitsEventsTrait.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
src/API/Common/Event/Dispatcher.php Outdated Show resolved Hide resolved
@tidal
Copy link
Member

tidal commented Jul 15, 2022

When discussing #708 in SIG last week, we decided that using it to perform logging was overkill (since psr-3 can provide enough control to meet the spec requirements).

I don't know what the spec requirements that should be in that case. However I see the spec as a minimum requirement which must be fulfilled to get to the fun parts. Using an event listener for logs would allow for more fine grained control, but this could still be implemented for (additional logs) in the future.

@Nevay
Copy link
Contributor

Nevay commented Jul 15, 2022

After reading through the CloudEvents spec: I think that using PSR-14 (as initially done in #708) makes more sense, it is widely used and would allow users to use a single event system in their application.

CloudEvents main goal seems to be propagation between independent applications; users can still create CloudEvents from PSR-14 events by registering a listener that converts and emits these events. Creating CloudEvents:

The CloudEvents specification purposely avoids being too prescriptive about how CloudEvents are created. For example, it does not assume that the original event source is the same entity that is constructing the associated CloudEvent for that occurrence.

- add dispatcher interface
- remove singleton
- move some logic into methods
- make generator-returning method private
@brettmc
Copy link
Collaborator Author

brettmc commented Jul 18, 2022

After reading through the CloudEvents spec: I think that using PSR-14 (as initially done in #708) makes more sense, it is widely used and would allow users to use a single event system in their application.

@Nevay I thought that initially, too. But without an interface in PSR-14 for registering events in a listener, it wasn't possible to have our code register its own events in a user-provided PSR-14 implementation. Effectively, you could bring your own psr-14, but you'd then be responsible for knowing about and hooking up of our internal events, including future events that we come up with. I'm happy to be corrected here, though - we're all for standards and choice

@brettmc
Copy link
Collaborator Author

brettmc commented Jul 18, 2022

@tidal I think I've addressed all review comments now

@tidal
Copy link
Member

tidal commented Jul 18, 2022

@brettmc
Thanks!!!

@tidal tidal merged commit 7f2e974 into open-telemetry:main Jul 18, 2022
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.

Effectively, you could bring your own psr-14, but you'd then be responsible for knowing about and hooking up of our internal events, including future events that we come up with.

I assumed that this event dispatcher was solely for user facing events. If priority handling between multiple dispatchers is not required we could use a composite dispatcher that contains our internal dispatcher and the user provided dispatcher(s). What kind of events/internal events are currently planned?

if we did have our own internal events (eg for metrics) [708]

For metrics it might make more sense to use the meter provider and emit metrics directly, partly because we cannot use asynchronous instruments otherwise.

private static function createInstance(): self
{
$dispatcher = new self();
Context::getCurrent()->with(self::getConstantKeyInstance(), $dispatcher)->activate();
Copy link
Contributor

Choose a reason for hiding this comment

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

The "root" dispatcher should use a static instance and not the context; currently leaks the created scope.
Additionally leads to different behavior depending on when the dispatcher is retrieved for the first time as listeners will then be added to the same instance.

@brettmc brettmc deleted the adding-events-simplified 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.

None yet

4 participants