-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtracing_basic.lua
More file actions
115 lines (91 loc) Β· 3.83 KB
/
tracing_basic.lua
File metadata and controls
115 lines (91 loc) Β· 3.83 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env lua
-- Basic distributed tracing example
-- Shows core tracing concepts: transactions, spans, and event correlation
package.path = "build/?.lua;build/?/init.lua;;" .. package.path
local sentry = require("sentry")
local performance = require("sentry.performance")
-- Initialize Sentry with correct DSN
sentry.init({
dsn = "https://e247e6e48f8f482499052a65adaa9f6b@o117736.ingest.us.sentry.io/4504930623356928",
debug = true,
environment = "tracing-basic-example"
})
print("π― Basic Distributed Tracing Example")
print("====================================")
-- Example 1: Simple transaction
print("\nπ¦ Example 1: Simple Transaction")
local tx1 = performance.start_transaction("user_registration", "http.server")
print("β
Started transaction:", tx1.transaction)
-- Simulate validation
local validation_span = performance.start_span("validation.input", "Validate email and password")
print(" β Validating user input...")
os.execute("sleep 0.05")
performance.finish_span("ok")
-- Simulate database operation
local db_span = performance.start_span("db.query", "INSERT INTO users")
print(" β Creating user record...")
os.execute("sleep 0.1")
performance.finish_span("ok")
-- Capture a success event within the transaction
sentry.capture_message("User registered successfully", "info")
performance.finish_transaction("ok")
print("β
Transaction completed")
-- Example 2: Transaction with error
print("\nβ Example 2: Transaction with Error")
local tx2 = performance.start_transaction("payment_processing", "task")
print("β
Started transaction:", tx2.transaction)
-- Simulate payment validation
local validate_span = performance.start_span("payment.validate", "Validate credit card")
os.execute("sleep 0.03")
performance.finish_span("ok")
-- Simulate payment failure
local charge_span = performance.start_span("payment.charge", "Charge credit card")
os.execute("sleep 0.08")
-- Capture error within the transaction
sentry.capture_exception({
type = "PaymentError",
message = "Card declined: insufficient funds"
}, "error")
performance.finish_span("internal_error")
performance.finish_transaction("internal_error")
print("β
Transaction completed (with error)")
-- Example 3: Complex nested operations
print("\nπ’ Example 3: Complex Data Pipeline")
local tx3 = performance.start_transaction("data_processing", "task")
print("β
Started transaction:", tx3.transaction)
-- Stage 1: Data extraction
local extract_span = performance.start_span("extract.data", "Extract from external API")
print(" β Extracting data...")
-- Nested HTTP call within extraction
local api_span = performance.start_span("http.client", "GET /api/users")
os.execute("sleep 0.04")
performance.finish_span("ok")
print(" β API call completed")
performance.finish_span("ok")
print(" β Extraction completed")
-- Stage 2: Data transformation
local transform_span = performance.start_span("transform.data", "Clean and normalize data")
print(" β Transforming data...")
os.execute("sleep 0.06")
performance.finish_span("ok")
-- Stage 3: Data loading
local load_span = performance.start_span("load.data", "Load into data warehouse")
print(" β Loading data...")
os.execute("sleep 0.05")
performance.finish_span("ok")
-- Add breadcrumb and final message
sentry.add_breadcrumb({
message = "Data pipeline completed",
category = "processing",
level = "info",
data = { records_processed = 1250 }
})
sentry.capture_message("Data pipeline completed successfully", "info")
performance.finish_transaction("ok")
print("β
Transaction completed")
print("\nπ Basic tracing examples completed!")
print("\nCheck your Sentry dashboard to see:")
print("β’ 3 transactions with different operations")
print("β’ Nested spans showing timing and hierarchy")
print("β’ Events correlated within transactions")
print("β’ Error handling within transaction context")