Skip to content

Commit

Permalink
pass context along with pubsub message
Browse files Browse the repository at this point in the history
  • Loading branch information
RudolfMan committed Apr 17, 2022
1 parent efb4cea commit 8f26d96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/acme/orders.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Acme.Orders do
The Orders context.
"""

require OpenTelemetry.Tracer

import Ecto.Query, warn: false
alias Acme.Repo

Expand Down Expand Up @@ -68,11 +70,15 @@ defmodule Acme.Orders do
"""
def update_order(%Order{} = order, attrs) do
order_changeset = Order.changeset(order, attrs)
OpenTelemetry.Tracer.with_span "orders:update_order" do
order_changeset = Order.changeset(order, attrs)

with {:ok, order} <- Repo.update(order_changeset) do
ctx = OpenTelemetry.Tracer.current_span_ctx()
Phoenix.PubSub.broadcast(Acme.PubSub, "orders:#{order.id}", {:order_updated, order, ctx})

with {:ok, order} <- Repo.update(order_changeset) do
Phoenix.PubSub.broadcast(Acme.PubSub, "orders:#{order.id}", {:order_updated, order})
{:ok, order}
{:ok, order}
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/acme_web/live/order_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ defmodule AcmeWeb.OrderLive.Show do
end

@impl true
def handle_info({:order_updated, order}, socket) do
def handle_info({:order_updated, order, ctx}, socket) do
OpenTelemetry.Tracer.set_current_span(ctx)

opts = %{attributes: %{user: inspect(self())}}

OpenTelemetry.Tracer.with_span "order_live.show:order_updated", opts do
Expand Down

0 comments on commit 8f26d96

Please sign in to comment.