Skip to content

Commit 92797fa

Browse files
Merge branch 'main' into update-checkly-helpers-docs
2 parents c6761c4 + 9f2ff19 commit 92797fa

File tree

5 files changed

+110
-24
lines changed

5 files changed

+110
-24
lines changed

site/content/docs/open-telemetry/instrumenting-code/_index.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ Below you will find instructions on how to instrument your popular languages and
5656
img="/docs/images/integrations/otel/otel-languages/go_icon.svg"
5757
link="/docs/open-telemetry/instrumenting-code/go/"
5858
>}}
59-
{{< doc-card
60-
class="three-column-card"
61-
headerTag="h3"
62-
title="Ruby"
63-
img="/docs/images/integrations/otel/otel-languages/ruby_icon.svg"
64-
link="/docs/open-telemetry/instrumenting-code/ruby/"
65-
>}}
6659
</div>
6760
<br>
6861
@@ -86,9 +79,9 @@ Below you will find instructions on how to instrument your popular languages and
8679
{{< doc-card
8780
class="three-column-card"
8881
headerTag="h3"
89-
title=".NET"
90-
img="/docs/images/integrations/otel/otel-languages/dot-net_icon.svg"
91-
link="/docs/open-telemetry/instrumenting-code/dot-net/"
82+
title="Ruby on Rails"
83+
img="/docs/images/integrations/otel/otel-languages/ruby_on_rails_icon.svg"
84+
link="/docs/open-telemetry/instrumenting-code/ruby-on-rails/"
9285
>}}
9386
</div>
9487
<br>

site/content/docs/open-telemetry/instrumenting-code/express.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
title: Express
33
weight: 38
4+
head:
5+
title: "Instrumenting Express.js with OpenTelemetry"
6+
metatags:
7+
title: "Instrumenting Express.js with OpenTelemetry"
8+
description: "Instrument your Express.js application with OpenTelemetry and send traces to Checkly."
49
menu:
510
integrations:
611
parent: "Instrumenting your code with OpenTelemetry"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Ruby on Rails
3+
weight: 36
4+
head:
5+
title: "Instrumenting Ruby on Rails with OpenTelemetry"
6+
metatags:
7+
title: "Instrumenting Ruby on Rails with OpenTelemetry"
8+
description: "Instrument your Ruby on Rails application with OpenTelemetry and send traces to Checkly."
9+
menu:
10+
integrations:
11+
parent: "Instrumenting your code with OpenTelemetry"
12+
beta: true
13+
---
14+
15+
This guide will help you instrument your Ruby on Rails application(s) with OpenTelemetry and send traces to Checkly.
16+
<!--more-->
17+
Although this guide is for [Ruby on Rails](https://rubyonrails.org/), the steps are largely the same as instrumenting
18+
any Ruby application with OpenTelemetry. This guide assumes you have a basic understanding of Ruby on Rails and already
19+
have a working Rails application.
20+
21+
## Step 1: Install the OpenTelemetry package
22+
23+
Go to the root of your Rails app and add the basic OpenTelemetry SDK, OTLP exporter and instrumentation gems to your Gemfile:
24+
25+
```bash
26+
bundle add opentelemetry-sdk \
27+
opentelemetry-exporter-otlp \
28+
opentelemetry-instrumentation-all
29+
```
30+
31+
This should add the following lines:
32+
```ruby
33+
# Gemfile
34+
gem "opentelemetry-sdk", "~> 1.4"
35+
gem "opentelemetry-exporter-otlp", "~> 0.26.3"
36+
gem "opentelemetry-instrumentation-all", "~> 0.60.0"
37+
```
38+
39+
## Step 2: Initialize the instrumentation
40+
41+
As per the Ruby on Rails convention, we add an `instrumentation.rb` file to the `config/initializers` directory.
42+
43+
```ruby
44+
# config/initializers/instrumentation.rb
45+
46+
require 'opentelemetry/sdk'
47+
require 'opentelemetry/instrumentation/all'
48+
49+
class ChecklySampler
50+
51+
def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
52+
tracestate = OpenTelemetry::Trace.current_span(parent_context).context.tracestate
53+
decision = tracestate.value('checkly') ? OpenTelemetry::SDK::Trace::Samplers::Decision::RECORD_AND_SAMPLE :
54+
OpenTelemetry::SDK::Trace::Samplers::Decision::DROP
55+
puts(decision)
56+
OpenTelemetry::SDK::Trace::Samplers::Result.new(decision: decision, attributes: {}, tracestate: tracestate)
57+
end
58+
59+
def description
60+
'ChecklySampler'
61+
end
62+
end
63+
64+
OpenTelemetry::SDK.configure do |c|
65+
c.use_all()
66+
end
67+
68+
OpenTelemetry.tracer_provider.sampler = ChecklySampler.new
69+
```
70+
Notice the `ChecklySampler` configuration. This is a custom, **head-based sampler** that will only sample spans that
71+
are generated by Checkly by inspecting the trace state. This way you only pay for the egress traffic generated by Checkly
72+
and not for any other traffic. Also note that the `use_all()` method will automatically install all available
73+
instrumentation libraries.
74+
75+
## Step 3: Start your app with the instrumentation
76+
77+
{{< markdownpartial "/_shared/otel-api-and-endpoint.md" >}}
78+
79+
You can now restart your Rails app with the instrumentation enabled.
80+
81+
```bash
82+
rails server
83+
```
84+
85+
## Debugging and troubleshooting
86+
87+
If you run into any issues, you can also output any traces to the console as follows:
88+
89+
```bash
90+
env OTEL_TRACES_EXPORTER=console rails server
91+
```
92+
93+
Similarly, you can set the `OTEL_LOG_LEVEL` environment variable to `DEBUG` to get more detailed logs.
94+
95+
```bash
96+
env OTEL_LOG_LEVEL=DEBUG rails server
97+
```
98+
99+
## Further reading
100+
101+
- [https://opentelemetry.io/docs/languages/ruby/getting-started/](https://opentelemetry.io/docs/languages/ruby/getting-started/)

site/content/docs/open-telemetry/instrumenting-code/ruby.md

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)