Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/platforms/elixir/tracing/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,42 @@ Set up OpenTelemetry to send traces to Sentry:
config :opentelemetry, span_processor: {Sentry.OpenTelemetry.SpanProcessor, []}

config :opentelemetry, sampler: {Sentry.OpenTelemetry.Sampler, []}

# Enable distributed tracing across services via sentry-trace and baggage headers
config :opentelemetry,
text_map_propagators: [
:trace_context,
:baggage,
Sentry.OpenTelemetry.Propagator
]
Comment on lines +65 to +70
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The documentation for text_map_propagators suggests a mixed list of atoms and module references, a pattern not confirmed to be supported by the OpenTelemetry Elixir SDK.
Severity: MEDIUM

Suggested Fix

Verify with the OpenTelemetry Elixir SDK source code or official documentation whether mixed-type lists are supported for text_map_propagators. If not, update the documentation to show a supported configuration pattern, which might involve using only atoms or providing a different mechanism for custom propagators.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/platforms/elixir/tracing/index.mdx#L65-L70

Potential issue: The documentation suggests configuring `text_map_propagators` with a
mixed list containing both atoms (e.g., `:trace_context`) and module references (e.g.,
`Sentry.OpenTelemetry.Propagator`). There is no authoritative documentation or source
code evidence from the OpenTelemetry Elixir SDK to confirm that it can parse and handle
such a mixed-type list. If a user implements this configuration, the application could
either crash during initialization or, more subtly, fail to register the custom
propagator, leading to incomplete tracing data in production without any obvious error.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@solnic is this a valid problem?

```

## Set Up Phoenix Instrumentation

In your `application.ex`, set up the OpenTelemetry instrumentation:
In your `application.ex`, set up the OpenTelemetry instrumentation.


<Alert title="Note">

`OpentelemetryPhoenix` requires your Phoenix endpoint to include `Plug.Telemetry` in order to correctly trace endpoint calls. Make sure your endpoint contains:

```elixir
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
```

This is included by default in the Phoenix endpoint template.

</Alert>

```elixir
# lib/my_app/application.ex
defmodule MyApp.Application do
use Application

def start(_type, _args) do
# Set up LiveView trace propagation (must be BEFORE OpentelemetryPhoenix)
Sentry.OpenTelemetry.LiveViewPropagator.setup()

# Set up OpenTelemetry instrumentation
OpentelemetryBandit.setup() # for Bandit (Phoenix 1.7+)
# OR OpentelemetryPhoenix.setup(adapter: :cowboy2) # for Cowboy
Expand All @@ -92,6 +116,20 @@ defmodule MyApp.Application do
end
```

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.

```elixir {filename:lib/my_app_web/router.ex}
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {MyAppWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug Sentry.Plug.LiveViewContext
end
```

## Advanced Sampling

For more control over sampling, you can use a sampling function:
Expand Down
Loading