forked from assafp/send-test-spans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_test_spans.rb
78 lines (59 loc) · 2.28 KB
/
send_test_spans.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'epsagon'
require 'faraday'
require 'net/http'
BACKEND = 'opentelemetry.tc.epsagon.com:443/traces'
Epsagon.init(metadata_only: false, debug: true, backend: BACKEND, app_name: 'send-test-spans')
# add custom resource tag:
# OpenTelemetry::SDK.configure do |c|
# c.resource = OpenTelemetry::SDK::Resources::Resource.telemetry_sdk.merge(
# OpenTelemetry::SDK::Resources::Resource.create({ 'custom_resource_tag' => 'custom_resource_tag_val' })
# )
# end
pids = {}
pids[:traced_app] = spawn 'ruby traced_sinatra.rb'
pids[:untraced_app] = spawn 'ruby untraced_sinatra.rb'
sleep 3
# "vanilla" spans:
tracer = OpenTelemetry.tracer_provider.tracer('send-test-spans', '0.1.0')
tracer.in_span('nested_outer') do |span|
span.set_attribute('is_question', true)
span.set_attribute('answer', 42)
span.set_attribute('exact', 42.225)
span.set_attribute('message', 'These pretzels are making me thirsty')
tracer.in_span('inner') do |child_span|
child_span.set_attribute('inner_span_attr', 'is awesome')
tracer.in_span('more_inner') do |grandchild_span|
grandchild_span.set_attribute('more_inner_span_attr', 'is more awesome')
end
end
end
tracer.in_span('test_status_ok') do |span|
span.status = OpenTelemetry::Trace::Status.new(OpenTelemetry::Trace::Status::OK)
end
tracer.in_span('test_status_error') do |span|
span.status = OpenTelemetry::Trace::Status.new(OpenTelemetry::Trace::Status::ERROR)
end
begin
tracer.in_span('with_exception') do |span|
raise RuntimeError.new("This is the error message")
end
rescue RuntimeError
#raised and ignored for span creation
end
#Faraday:
url = 'http://localhost:4566/some/path/index.html;pathparam=who,even,uses,this?q1=a&q2=b&q1=c'
Faraday.post(url, 'yanti=parazi')
#Faraday with error:
Faraday.get('http://localhost:4566/does-not-exist')
#Faraday with server error:
Faraday.get('http://localhost:4566/make-error')
# Sinatra (on server process) with error
`curl -X POST http://localhost:4567/foo/bar -d "amir=asdasd"`
# Sinatra (on server process) with error
`curl http://localhost:4567/asdasd`
# Sinatra (on server process) server error:
`curl http://localhost:4567/make-error`
Process.kill('SIGHUP', pids[:traced_app])
Process.detach(pids[:traced_app])
Process.kill('SIGHUP', pids[:untraced_app])
Process.detach(pids[:untraced_app])