This directory contains practical examples demonstrating how to use the Sentry Lua SDK for error monitoring and performance tracking.
Complete demonstration of core Sentry functionality:
- SDK initialization and configuration
- User context, tags, and extra data
- Breadcrumbs for debugging context
- Manual error capture with
xpcall - Common Lua pitfalls and error patterns
- Scoped context management
Run: lua examples/basic.lua
Demonstrates automatic error capture using sentry.wrap():
- Simple automatic error capture
- Custom error handlers
- Comparison with manual error handling
- Context preservation across wrapped functions
Run: lua examples/wrap_demo.lua
Comprehensive logging functionality demonstration:
- Structured logging at different severity levels
- Parameterized messages with template support
- Additional attributes for rich context
- Automatic print statement capture with recursion protection
- Log correlation with distributed traces
- Log filtering and modification hooks
- Batching and buffer management
Run: lua examples/logging.lua
Requirements: Install dependencies first:
luarocks install pegasus
luarocks install luasocketHTTP client demonstrating trace propagation:
- Object-oriented performance API with method chaining
- LuaSocket HTTP client integration
- Automatic trace context injection into requests
- Cross-process distributed tracing
- Proper parent-child span relationships
HTTP server with distributed tracing:
- Object-oriented transaction and span management
- Pegasus web server integration
- Automatic trace context extraction from headers
- Cross-process trace propagation and continuation
- Performance monitoring for web endpoints
Usage:
- Start server:
lua examples/tracing/server.lua - In another terminal:
lua examples/tracing/client.lua - View connected traces in Sentry UI showing proper parent-child relationships
Key Features Demonstrated:
transaction:start_span()andspan:finish()methods- Automatic trace context management across HTTP boundaries
- Proper distributed trace hierarchy (client transaction → server transaction)
- Error correlation within distributed traces
- Performance timing across service boundaries
All examples use the playground project DSN. For production use:
- Replace DSN with your project's DSN
- Update environment and release information
- Configure appropriate sampling rates
After running examples, check your Sentry project:
- Issues tab: View captured errors and exceptions
- Performance tab: View transactions and spans
- Discover tab: Query events and trace data
The distributed tracing examples will show connected spans across processes, demonstrating how requests flow through your system.