Skip to content

Commit f811cbe

Browse files
committed
doc: add more test example
1 parent e680d0a commit f811cbe

File tree

8 files changed

+109
-5
lines changed

8 files changed

+109
-5
lines changed

opentelemetry-auto-instrumentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ opentelemetry-helpers-sql-obfuscation
3333
opentelemetry-resource-detector-google_cloud_platform
3434
opentelemetry-resource-detector-azure
3535
opentelemetry-resource-detector-container
36+
opentelemetry-resource-detector-aws
3637
```
3738

3839
### Example installation strategies
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Example
2+
3+
## Installation
4+
5+
Install opentelemetry-auto-instrumentation through `gem install`
6+
Then `bundle install`
7+
8+
9+
## Simple Example (simple-example)
10+
11+
```bash
12+
OTEL_RUBY_REQUIRE_BUNDLER=true OTEL_TRACES_EXPORTER=console RUBYOPT="-r opentelemetry-auto-instrumentation" OTEL_RUBY_OPERATOR=false ruby app.rb
13+
```
14+
15+
## Rails Example (rails-example)
16+
17+
Without auto-instrumentation
18+
```bash
19+
bundle exec rackup config.ru
20+
```
21+
22+
In other terminal make the request call
23+
```bash
24+
wget http://localhost:9292
25+
# or curl http://localhost:9292 if you have curl on system
26+
```
27+
28+
With auto-instrumentation
29+
```bash
30+
OTEL_RUBY_REQUIRE_BUNDLER=false OTEL_TRACES_EXPORTER=console RUBYOPT="-r opentelemetry-auto-instrumentation" OTEL_RUBY_OPERATOR=false bundle exec rackup config.ru
31+
```
32+
33+
The load sequence must be opentelemetry-auto-instrumentation -> user library -> bundler.require (initialize otel sdk and instrumentation installation)
34+
35+
In other terminal make the request call
36+
```bash
37+
wget http://localhost:9292
38+
# or curl http://localhost:9292 if you have curl on system
39+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
# Gemfile
4+
source 'https://rubygems.org'
5+
6+
gem 'rails'
7+
gem 'rack'
8+
gem 'rake', '13.0.6'
9+
gem 'bigdecimal', '3.1.3'
10+
gem 'logger', '1.5.3'
11+
gem 'webrick'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
require 'rails'
8+
require 'action_controller/railtie'
9+
10+
require 'bundler'
11+
Bundler.require
12+
13+
# MyApp
14+
class MyApp < Rails::Application
15+
config.secret_key_base = 'your_secret_key_here'
16+
config.eager_load = false
17+
config.logger = Logger.new($stdout)
18+
config.api_only = true
19+
config.active_support.to_time_preserves_timezone = :zone
20+
21+
routes.draw do
22+
get '/', to: 'application#index'
23+
get '/hello', to: 'application#hello'
24+
post '/data', to: 'application#create'
25+
end
26+
end
27+
28+
# ApplicationController
29+
class ApplicationController < ActionController::API
30+
def index
31+
render json: { message: 'Hello World!', time: Time.current }
32+
end
33+
34+
def hello
35+
name = params[:name] || 'World'
36+
render json: { greeting: "Hello #{name}!" }
37+
end
38+
39+
def create
40+
render json: {
41+
message: 'Data received',
42+
data: params.except(:controller, :action)
43+
}
44+
end
45+
end
46+
47+
MyApp.initialize!
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'app'
4+
5+
run MyApp
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
22

3+
source 'https://rubygems.org'

opentelemetry-auto-instrumentation/example/app.rb renamed to opentelemetry-auto-instrumentation/example/simple-example/app.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
url = URI.parse("http://catfact.ninja/fact")
7+
url = URI.parse('http://catfact.ninja/fact')
88
req = Net::HTTP::Get.new(url.to_s)
9-
res = Net::HTTP.start(url.host, url.port) {|http|
9+
Net::HTTP.start(url.host, url.port) do |http|
1010
http.request(req)
11-
}
11+
end

opentelemetry-auto-instrumentation/lib/opentelemetry-auto-instrumentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def require(...)
118118

119119
# set OTEL_OPERATOR to false if not in autoinstrumentation-ruby image, default to /otel-auto-instrumentation-ruby
120120
# /otel-auto-instrumentation-ruby is set in opentelemetry-operator ruby.go
121-
operator_gem_path = ENV['OTEL_RUBY_OPERATOR'].nil? || ENV['OTEL_RUBY_OPERATOR'] == 'true' ? '/otel-auto-instrumentation-ruby' : nil
121+
operator_gem_path = ENV['OTEL_RUBY_OPERATOR'] == 'true' ? '/otel-auto-instrumentation-ruby' : nil
122122
additional_gem_path = operator_gem_path || ENV['OTEL_RUBY_ADDITIONAL_GEM_PATH'] || Gem.dir
123123
$stdout.puts "Loading the additional gem path from #{additional_gem_path}" if ENV['OTEL_RUBY_AUTO_INSTRUMENTATION_DEBUG'] == 'true'
124124

0 commit comments

Comments
 (0)