File tree 1 file changed +34
-10
lines changed
instrumentation/grape/example
1 file changed +34
-10
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
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
13
6
14
7
require 'opentelemetry-api'
15
8
require 'opentelemetry-sdk'
24
17
end
25
18
26
19
# 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' )
You can’t perform that action at this time.
0 commit comments