Skip to content

Commit 3f62dc9

Browse files
solnicbitsandfoxes
authored andcommitted
Add basic Tracing section to Elixir platform (#14112)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Tracing docs for Elixir SDK 11.0. Preview here: https://sentry-docs-git-elixir-tracing-docs.sentry.dev/platforms/elixir/tracing/ ## 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 --> - [ ] 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) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 430ca55 commit 3f62dc9

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

docs/platforms/elixir/configuration/options.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,34 @@ The maximum number of connections to keep in the pool. Only applied if `client`
115115
The maximum time to wait (in milliseconds) for a connection to become available. Only applied if `client` is set to `Sentry.HackneyClient`.
116116

117117
</SdkOption>
118+
119+
## Tracing Options
120+
121+
<SdkOption name="traces_sample_rate" type='float' defaultValue='nil'>
122+
123+
A number between `0.0` and `1.0` that determines the percentage of transactions that will be sent to Sentry. Either this or `traces_sampler` must be defined to enable tracing.
124+
125+
```elixir
126+
config :sentry,
127+
traces_sample_rate: 0.2 # Sample 20% of transactions
128+
```
129+
130+
</SdkOption>
131+
132+
<SdkOption name="traces_sampler" type='function'>
133+
134+
A function that determines the sample rate for transaction events. This function receives a sampling context map and should return a boolean or a float between `0.0` and `1.0`.
135+
136+
```elixir
137+
config :sentry,
138+
traces_sampler: fn sampling_context ->
139+
case sampling_context.transaction_context.op do
140+
"http.server" -> 0.1 # Sample 10% of HTTP requests
141+
_ -> 0.05 # Sample 5% of other operations
142+
end
143+
end
144+
```
145+
146+
If both `:traces_sampler` and `:traces_sample_rate` are configured, `:traces_sampler` takes precedence.
147+
148+
</SdkOption>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Set Up Tracing
3+
sidebar_title: Tracing
4+
description: "Learn how to enable tracing in your app and discover valuable performance insights of your application."
5+
sidebar_order: 30
6+
---
7+
8+
With [tracing](/product/insights/overview/), Sentry tracks your software performance, measuring metrics like throughput and latency, and displaying the impact of errors across multiple systems.
9+
10+
<Alert>
11+
12+
Tracing in Elixir SDK is available starting from 11.0.0 and it's currently in Beta.
13+
14+
</Alert>
15+
16+
## Install Dependencies
17+
18+
Sentry's Elixir SDK uses OpenTelemetry for tracing. Add the required dependencies to your `mix.exs`:
19+
20+
```elixir
21+
def deps do
22+
[
23+
# Sentry SDK
24+
{:sentry, "~> 11.0"},
25+
26+
# OpenTelemetry core packages
27+
{:opentelemetry, "~> 1.5"},
28+
{:opentelemetry_api, "~> 1.4"},
29+
{:opentelemetry_exporter, "~> 1.0"},
30+
{:opentelemetry_semantic_conventions, "~> 1.27"},
31+
32+
# Instrumentation libraries (choose what you need)
33+
{:opentelemetry_phoenix, "~> 2.0"}, # for Phoenix
34+
{:opentelemetry_bandit, "~> 0.1"}, # for Bandit (Phoenix 1.7+)
35+
{:opentelemetry_ecto, "~> 1.2"}, # for Ecto
36+
37+
# ... your other dependencies
38+
]
39+
end
40+
```
41+
42+
## Configure Sentry
43+
44+
Enable tracing in your Sentry configuration:
45+
46+
```elixir
47+
# config/config.exs or config/dev.exs
48+
config :sentry,
49+
dsn: "___PUBLIC_DSN___",
50+
traces_sample_rate: 1.0 # Adjust for production
51+
```
52+
53+
## Configure OpenTelemetry
54+
55+
Set up OpenTelemetry to send traces to Sentry:
56+
57+
```elixir
58+
# config/config.exs
59+
config :opentelemetry, span_processor: {Sentry.OpenTelemetry.SpanProcessor, []}
60+
61+
config :opentelemetry, sampler: {Sentry.OpenTelemetry.Sampler, []}
62+
```
63+
64+
## Set Up Phoenix Instrumentation
65+
66+
In your `application.ex`, set up the OpenTelemetry instrumentation:
67+
68+
```elixir
69+
# lib/my_app/application.ex
70+
defmodule MyApp.Application do
71+
use Application
72+
73+
def start(_type, _args) do
74+
# Set up OpenTelemetry instrumentation
75+
OpentelemetryBandit.setup() # for Bandit (Phoenix 1.7+)
76+
# OR OpentelemetryPhoenix.setup(adapter: :cowboy2) # for Cowboy
77+
78+
OpentelemetryPhoenix.setup(adapter: :bandit)
79+
OpentelemetryEcto.setup([:my_app, :repo], db_statement: :enabled)
80+
81+
# Optional: Set up Oban instrumentation
82+
# OpentelemetryOban.setup()
83+
84+
children = [
85+
# ... your supervision tree
86+
]
87+
88+
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
89+
Supervisor.start_link(children, opts)
90+
end
91+
end
92+
```
93+
94+
## Advanced Sampling
95+
96+
For more control over sampling, you can use a sampling function:
97+
98+
```elixir
99+
config :sentry,
100+
dsn: "___PUBLIC_DSN___",
101+
traces_sampler: fn sampling_context ->
102+
case sampling_context.transaction_context.op do
103+
"http.server" -> 0.1 # Sample 10% of HTTP requests
104+
_ -> 0.05 # Sample 5% of other operations
105+
end
106+
end
107+
```
108+
109+
Learn more about tracing <PlatformLink to="/configuration/options/#tracing-options">options</PlatformLink>.

0 commit comments

Comments
 (0)