Skip to content

Commit 9dab49f

Browse files
authored
feat(ruby): Update docs for Tracing without Performance (#7759)
1 parent 075b84e commit 9dab49f

File tree

6 files changed

+106
-3
lines changed

6 files changed

+106
-3
lines changed

src/platform-includes/distributed-tracing/custom-instrumentation/python.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Distributed tracing works out of the box for [supported frameworks](/platforms/python/usage/distributed-tracing/#how-to-use-distributed-tracing) and when <PlatformLink to="/performance/">performance monitoring</PlatformLink> is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, then you can set up custom instrumentation for distributed tracing.
1+
Distributed tracing works out of the box for [supported frameworks](/platforms/python/usage/distributed-tracing/#how-to-use-distributed-tracing) and when <PlatformLink to="/performance/">performance monitoring</PlatformLink> is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, you can set up custom instrumentation for distributed tracing.
22

3-
This page descirbes how to manually propoage trace information into and out of your Python application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application.
3+
This page describes how to manually propagate trace information into and out of your Python application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application.
44

55
## 1. Extract Incoming Tracing Information
66

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Distributed tracing works out of the box for supported frameworks and when <PlatformLink to="/performance/">performance monitoring</PlatformLink> is enabled. If you're using an unsupported framework or don't want to turn on performance monitoring, you can set up custom instrumentation for distributed tracing.
2+
3+
This page describes how to manually propagate trace information into and out of your Ruby application. All you have to do is to make sure your application extracts incoming headers and to set those headers again when making an outgoing request within your application.
4+
5+
## 1. Extract Incoming Tracing Information
6+
7+
Incoming tracing information has to be extracted and stored in memory for later use. Sentry provides the `continue_trace` function to help you with this. Incoming tracing information can come from different places:
8+
9+
- In a web environment, it's sent with HTTP headers, for example, by another Sentry SDK used in your frontend project.
10+
- In a job queue, like Sidekiq / DelayedJob, it can be retrieved from meta or header variables.
11+
- You also can pick up tracing information from environment variables.
12+
13+
Here's an example of how to extract and store incoming tracing information using `continue_trace` in a Rack application where `env` is a typical hash of incoming HTTP headers:
14+
15+
```ruby
16+
# rack application
17+
def call(env)
18+
transaction = Sentry.continue_trace(env, name: 'transaction', op: 'op')
19+
Sentry.start_transaction(transaction: transaction)
20+
end
21+
```
22+
23+
Sentry's `continue_trace` function will extract the given headers, try to find the `sentry-trace` and `baggage` headers, and store them in memory for later use.
24+
25+
## 2. Inject Tracing Information to Outgoing Requests
26+
27+
For distributed tracing to work, the two headers `sentry-trace` and `baggage`, must be added to outgoing requests. If you pregenerate HTML on the server-side, you might want to take a look at [Inject Tracing Information into Rendered HTML](#inject-tracing-information-into-rendered-html), which describes how to pass on tracing information through HTML meta tags.
28+
29+
### Inject Tracing Information Into HTTP Requests
30+
31+
The Ruby SDK intercepts all requests using `net/http` and adds this tracing information automatically to outgoing requests.
32+
33+
If the gem you're using for making requests doesn't use `net/http` internally, you can generate this tracing information with the Sentry SDK's `get_traceparent`, `get_baggage` and `get_trace_propagation_headers` functions. Here's an example:
34+
35+
```ruby
36+
# using custom HTTPRequest implementation
37+
HTTPRequest.get('https://example.com', headers: Sentry.get_trace_propagation_headers)
38+
```
39+
40+
In this example, tracing information is propagated to the project running at `https://example.com`. If this project also uses a supported Sentry SDK, it will extract and save the tracing information for later use.
41+
42+
The two services are now connected with your custom distributed tracing implementation.
43+
44+
### Inject Tracing Information Into Rendered HTML
45+
46+
To propagate tracing information into JavaScript running in rendered HTML, you have to inject HTML `meta` tags in your rendered HTML. For example, in a rails layout, you can inject the meta tags as follows:
47+
48+
```erb {filename: app/views/layouts/application.html.erb}
49+
<!DOCTYPE html>
50+
<html>
51+
<head>
52+
<meta charset="UTF-8" />
53+
<meta name="sentry-trace" content=<%= Sentry.get_traceparent %>>
54+
<meta name="baggage" content=<%= Sentry.get_baggage %>>
55+
</head>
56+
<body>
57+
<p>This is a website.</p>
58+
</body>
59+
</html>
60+
```
61+
62+
The rendered template will then look something like this:
63+
64+
```html
65+
<!DOCTYPE html>
66+
<html>
67+
<head>
68+
<meta charset="UTF-8" />
69+
<meta
70+
name="sentry-trace"
71+
content="98e5de1c09e444469475855d313e22c3-b995922394e8433d"
72+
/>
73+
<meta
74+
name="baggage"
75+
content="sentry-trace_id=98e5de1c09e444469475855d313e22c3,sentry-environment=prod,sentry-public_key=..."
76+
/>
77+
</head>
78+
<body>
79+
<p>This is a website.</p>
80+
</body>
81+
</html>
82+
```
83+
84+
## Verification
85+
86+
If you make outgoing requests from your project to other services, check if the headers `sentry-trace` and `baggage` are present in the request. If so, distributed tracing should work.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
If you use the current version of our Ruby SDK, distributed tracing just works out of the box. No additional configuration is required.
2+
3+
If you however use version `5.10.0` or below, you need to have our <PlatformLink to="/performance/">performance monitoring feature enabled</PlatformLink> for distributed tracing to work.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<SignInNote />
2+
3+
```ruby
4+
Sentry.init do |config|
5+
config.dsn = '___PUBLIC_DSN___'
6+
7+
# takes strings and regexes
8+
config.trace_propagation_targets = ['myproject.org', /.*\.otherservice.org\/.*/]
9+
10+
# ...
11+
end
12+
```

src/platforms/common/usage/distributed-tracing/custom-instrumentation.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ supported:
77
- php
88
- java
99
- android
10+
- ruby
1011
---
1112

1213
<PlatformContent includePath="distributed-tracing/custom-instrumentation/" />

src/platforms/common/usage/distributed-tracing/limiting-trace-propagation.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ sidebar_order: 100
44
description: ""
55
supported:
66
- python
7+
- ruby
78
---
89

910
By default, trace information (`sentry-trace` and `baggage` headers) will be added to all outgoing HTTP requests. If you want to limit the URLs where trace information is added, you can specify that using the `trace_propagation_targets` option:
1011

1112
<PlatformContent includePath="distributed-tracing/limiting-traces/" />
1213

13-
In the example above, trace information will be added to all requests to URLs that contain `"https://myproject.org"` and to all sub domains of `otherservice.org`, like `https://api.otherservice.org/something/` and `https://payment.otherservice.org/something/`.
14+
In the example above, trace information will be added to all requests to URLs that contain `myproject.org` and to all sub domains of `otherservice.org`, like `https://api.otherservice.org/something/` and `https://payment.otherservice.org/something/`.
1415

1516
See our <PlatformLink to="/configuration/options/#trace-propagation-targets">config options</PlatformLink> documentation for more information about the `trace_propagation_targets` option.

0 commit comments

Comments
 (0)