Skip to content

Commit 454beab

Browse files
committed
chore: update readme
1 parent d302ac8 commit 454beab

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

README.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Uptrace Ruby exporter for OpenTelemetry
1+
# OpenTelemetry Ruby distro for Uptrace
22

33
![build workflow](https://github.com/uptrace/uptrace-ruby/actions/workflows/build.yml/badge.svg)
44
[![Documentation](https://img.shields.io/badge/uptrace-documentation-informational)](https://uptrace.dev/get/opentelemetry-ruby)
@@ -10,8 +10,11 @@
1010

1111
## Introduction
1212

13-
uptrace-ruby is an OpenTelemery distribution configured to export
14-
[traces](https://uptrace.dev/opentelemetry/distributed-tracing) to Uptrace.
13+
`uptrace-ruby` is a preconfigured [OpenTelemetry](https://opentelemetry.io)
14+
distribution for Ruby that exports **traces, logs, and metrics** to
15+
[Uptrace](https://uptrace.dev). It builds on top of
16+
[opentelemetry-ruby](https://github.com/open-telemetry/opentelemetry-ruby) and
17+
makes connecting your application to Uptrace fast and easy.
1518

1619
## Quickstart
1720

@@ -21,7 +24,8 @@ Install uptrace-ruby:
2124
gem install uptrace
2225
```
2326

24-
Run the [basic example](example/basic) below using the DSN from the Uptrace project settings page.
27+
Run the [traces example](example/traces) below using the DSN from the Uptrace
28+
project settings page.
2529

2630
```ruby
2731
#!/usr/bin/env ruby
@@ -32,42 +36,52 @@ require 'bundler/setup'
3236
require 'uptrace'
3337

3438
# Configure OpenTelemetry with sensible defaults.
35-
# Copy your project DSN here or use UPTRACE_DSN env var.
39+
# DSN can be set via UPTRACE_DSN environment variable.
40+
# Example: export UPTRACE_DSN="https://<project_secret>@uptrace.dev?grpc=4317"
3641
Uptrace.configure_opentelemetry(dsn: '') do |c|
37-
# c is OpenTelemetry::SDK::Configurator
42+
# c is an instance of OpenTelemetry::SDK::Configurator
43+
44+
# Configure service metadata (helps identify this service in Uptrace).
3845
c.service_name = 'myservice'
3946
c.service_version = '1.0.0'
4047

48+
# Add environment information
4149
c.resource = OpenTelemetry::SDK::Resources::Resource.create(
42-
'deployment.environment' => 'production'
50+
'deployment.environment.name' => ENV.fetch('RACK_ENV', 'development')
4351
)
4452
end
4553

46-
# Create a tracer. Usually, tracer is a global variable.
47-
tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
48-
49-
# Create a root span (a trace) to measure some operation.
50-
tracer.in_span('main-operation', kind: :client) do |main|
51-
tracer.in_span('GET /posts/:id') do |child1|
52-
child1.set_attribute('http.method', 'GET')
53-
child1.set_attribute('http.route', '/posts/:id')
54-
child1.set_attribute('http.url', 'http://localhost:8080/posts/123')
55-
child1.set_attribute('http.status_code', 200)
56-
child1.record_exception(ArgumentError.new('error1'))
54+
# Ensure spans are flushed even if the program exits unexpectedly.
55+
at_exit { OpenTelemetry.tracer_provider.shutdown }
56+
57+
# Register a tracer (usually stored globally).
58+
TRACER = OpenTelemetry.tracer_provider.tracer('my_app', '0.1.0')
59+
60+
# Example trace with nested spans.
61+
TRACER.in_span('main-operation', kind: :server) do |main_span|
62+
# Simulate an HTTP request span.
63+
TRACER.in_span('GET /posts/:id', kind: :client) do |http_span|
64+
http_span.set_attribute('http.method', 'GET')
65+
http_span.set_attribute('http.route', '/posts/:id')
66+
http_span.set_attribute('http.url', 'http://localhost:8080/posts/123')
67+
http_span.set_attribute('http.status_code', 200)
68+
http_span.record_exception(ArgumentError.new('Invalid parameter'))
5769
end
5870

59-
tracer.in_span('SELECT') do |child2|
60-
child2.set_attribute('db.system', 'mysql')
61-
child2.set_attribute('db.statement', 'SELECT * FROM posts LIMIT 100')
71+
# Simulate a database query span.
72+
TRACER.in_span('SELECT posts', kind: :client) do |db_span|
73+
db_span.set_attribute('db.system', 'mysql')
74+
db_span.set_attribute('db.statement', 'SELECT * FROM posts LIMIT 100')
6275
end
6376

64-
puts("trace URL: #{Uptrace.trace_url(main)}")
77+
# Print the trace URL (clickable in console).
78+
puts "Trace URL: #{Uptrace.trace_url(main_span)}"
6579
end
66-
67-
# Send buffered spans and free resources.
68-
OpenTelemetry.tracer_provider.shutdown
6980
```
7081

82+
Additional examples are available for [logs](example/logs) and
83+
[metrics](example/metrics).
84+
7185
## Links
7286

7387
- [Examples](example)

0 commit comments

Comments
 (0)