Skip to content

Commit 126a85a

Browse files
author
Muriel Picone Farías
committed
Add basic Grape endpoints to example
1 parent 2c905e1 commit 126a85a

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
# frozen_string_literal: true
22

3-
require 'bundler/inline'
4-
5-
gemfile(true) do
6-
source 'https://rubygems.org'
7-
gem 'opentelemetry-api'
8-
gem 'opentelemetry-instrumentation-base'
9-
gem 'opentelemetry-instrumentation-grape'
10-
gem 'opentelemetry-sdk'
11-
gem 'grape'
12-
end
3+
require 'bundler/setup'
4+
5+
Bundler.require
136

147
require 'opentelemetry-api'
158
require 'opentelemetry-sdk'
@@ -24,3 +17,34 @@
2417
end
2518

2619
# A basic Grape endpoint example
20+
class ExampleAPI < Grape::API
21+
format :json
22+
23+
desc 'Return a greeting message'
24+
get :hello do
25+
{ message: 'Hello, world!' }
26+
end
27+
28+
desc 'Return information about a user'
29+
# Filters
30+
before do
31+
sleep(0.01)
32+
end
33+
after do
34+
sleep(0.01)
35+
end
36+
params do
37+
requires :id, type: Integer, desc: 'User ID'
38+
end
39+
get 'users/:id' do
40+
{ id: params[:id], name: 'John Doe', email: '[email protected]' }
41+
end
42+
end
43+
44+
# Set up fake Rack application
45+
builder = Rack::Builder.app do
46+
run ExampleAPI
47+
end
48+
49+
Rack::MockRequest.new(builder).get('/hello')
50+
Rack::MockRequest.new(builder).get('/users/1')

0 commit comments

Comments
 (0)