Skip to content

Commit 8d82dbe

Browse files
sl0thentr0pyclaude
andauthored
feat(elixir): Add propagator, LiveView tracing, and Plug.Telemetry note (#17336)
## DESCRIBE YOUR PR Document Sentry.OpenTelemetry.Propagator for distributed tracing via sentry-trace and baggage headers. Add LiveView trace propagation setup using LiveViewPropagator and Plug.LiveViewContext. Include note about OpentelemetryPhoenix requiring Plug.Telemetry in the endpoint. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9344fc3 commit 8d82dbe

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/platforms/elixir/tracing/index.mdx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,42 @@ Set up OpenTelemetry to send traces to Sentry:
6060
config :opentelemetry, span_processor: {Sentry.OpenTelemetry.SpanProcessor, []}
6161

6262
config :opentelemetry, sampler: {Sentry.OpenTelemetry.Sampler, []}
63+
64+
# Enable distributed tracing across services via sentry-trace and baggage headers
65+
config :opentelemetry,
66+
text_map_propagators: [
67+
:trace_context,
68+
:baggage,
69+
Sentry.OpenTelemetry.Propagator
70+
]
6371
```
6472

6573
## Set Up Phoenix Instrumentation
6674

67-
In your `application.ex`, set up the OpenTelemetry instrumentation:
75+
In your `application.ex`, set up the OpenTelemetry instrumentation.
76+
77+
78+
<Alert title="Note">
79+
80+
`OpentelemetryPhoenix` requires your Phoenix endpoint to include `Plug.Telemetry` in order to correctly trace endpoint calls. Make sure your endpoint contains:
81+
82+
```elixir
83+
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
84+
```
85+
86+
This is included by default in the Phoenix endpoint template.
87+
88+
</Alert>
6889

6990
```elixir
7091
# lib/my_app/application.ex
7192
defmodule MyApp.Application do
7293
use Application
7394

7495
def start(_type, _args) do
96+
# Set up LiveView trace propagation (must be BEFORE OpentelemetryPhoenix)
97+
Sentry.OpenTelemetry.LiveViewPropagator.setup()
98+
7599
# Set up OpenTelemetry instrumentation
76100
OpentelemetryBandit.setup() # for Bandit (Phoenix 1.7+)
77101
# OR OpentelemetryPhoenix.setup(adapter: :cowboy2) # for Cowboy
@@ -92,6 +116,20 @@ defmodule MyApp.Application do
92116
end
93117
```
94118

119+
Then add `Sentry.Plug.LiveViewContext` to your router's browser pipeline, after `:fetch_session`. This stores the trace context in the session so that LiveView processes can restore it during `mount`, `handle_params`, and `handle_event` callbacks.
120+
121+
```elixir {filename:lib/my_app_web/router.ex}
122+
pipeline :browser do
123+
plug :accepts, ["html"]
124+
plug :fetch_session
125+
plug :fetch_live_flash
126+
plug :put_root_layout, html: {MyAppWeb.Layouts, :root}
127+
plug :protect_from_forgery
128+
plug :put_secure_browser_headers
129+
plug Sentry.Plug.LiveViewContext
130+
end
131+
```
132+
95133
## Advanced Sampling
96134

97135
For more control over sampling, you can use a sampling function:

0 commit comments

Comments
 (0)