-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.rb
More file actions
executable file
·55 lines (44 loc) · 1.41 KB
/
Copy pathexample.rb
File metadata and controls
executable file
·55 lines (44 loc) · 1.41 KB
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
#!/usr/bin/env ruby
require_relative "lib/observable"
# Configure the instrumenter
Observable::Configuration.configure do |config|
config.app_namespace = "example_app"
config.track_return_values = true
config.pii_filters = [/password/, /token/, /secret/]
end
class ExampleService
def initialize
@instrumenter = Observable::Instrumenter.new
end
def process_order(order_id, customer_email, amount)
@instrumenter.instrument(binding) do
# Simulate some processing
puts "Processing order #{order_id} for #{customer_email}, amount: #{amount}"
# Return a result hash
{
order_id: order_id,
status: "processed",
processed_at: Time.now.to_i,
amount: amount
}
end
end
def self.static_method(data)
instrumenter = Observable::Instrumenter.new
instrumenter.instrument(binding) do
puts "Processing data: #{data.inspect}"
data.transform_values(&:upcase) if data.is_a?(Hash)
end
end
end
# Example usage
puts "=== Observable Example ==="
puts
service = ExampleService.new
result = service.process_order("ORD-123", "customer@example.com", 99.99)
puts "Result: #{result}"
puts
static_result = ExampleService.static_method({name: "john", city: "nyc"})
puts "Static result: #{static_result}"
puts "\n=== Check OpenTelemetry spans were created ==="
# In a real application, these spans would be exported to your observability platform