-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstraction over pubsub to include OpenTelemetry context
- Loading branch information
Showing
3 changed files
with
33 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule Acme.PubSub do | ||
defmodule Event do | ||
defstruct [:message, :span_ctx] | ||
end | ||
|
||
defmacro __using__(_opts) do | ||
quote do | ||
def handle_info(%Acme.PubSub.Event{} = event, socket) do | ||
OpenTelemetry.Tracer.set_current_span(event.span_ctx) | ||
handle_info(event.message, socket) | ||
end | ||
end | ||
end | ||
|
||
def broadcast(topic, message) do | ||
require OpenTelemetry.Tracer | ||
|
||
OpenTelemetry.Tracer.with_span "acme.pubsub:broadcast" do | ||
event = %Event{message: message, span_ctx: OpenTelemetry.Tracer.current_span_ctx()} | ||
Phoenix.PubSub.broadcast(__MODULE__, topic, event) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters