SentryStr Tracing
A tracing integration for SentryStr that provides seamless logging and alerting through Nostr relays with optional direct messaging capabilities.
Features
- Custom Tracing Layer: Integrates with the
tracingecosystem - Structured Logging: Captures all tracing fields and metadata
- Direct Messaging: Optional DM alerts for critical events
- Level Filtering: Configurable event level thresholds
- NIP-17/NIP-44 Support: Choose between gift wrapping or direct encryption
- Builder Pattern: Clean, fluent API for configuration
Quick Start
Basic Usage
use SentryStrTracingBuilder;
use ;
async
With Direct Messaging
use *;
use Level;
use ;
async
Configuration Options
Builder Methods
with_config(config)- Use existing SentryStr configwith_generated_keys_and_relays(relays)- Generate new keyswith_secret_key_and_relays(key, relays)- Use specific keywith_direct_messaging(dm_config)- Enable DM alertswith_min_level(level)- Set minimum tracing levelwith_fields(include)- Include/exclude custom fieldswith_metadata(include)- Include/exclude tracing metadata
Direct Message Configuration
let dm_config = new
.with_min_level // Only warn+ events
.with_nip17; // Use NIP-17 encryption
Examples
Run the examples to see the integration in action:
# Basic tracing without DMs
# With direct message alerts
# Complex structured logging
# Integration test
Integration Patterns
Web Application
use ;
use SentryStrTracingBuilder;
use ;
async
Background Service
use SentryStrTracingBuilder;
use ;
async
async
Advanced Usage
Custom Event Processing
The layer captures all structured fields from your tracing events:
error!;
All fields are preserved in the SentryStr event and available for filtering and alerting.
Environment-based Configuration
use env;
let dm_enabled = var.unwrap_or_default == "true";
let min_level = var
.unwrap_or_else;
let mut builder = new
.with_generated_keys_and_relays;
if dm_enabled
builder.init.await?;
Best Practices
- Use appropriate log levels - Don't spam with debug messages
- Structure your logs - Include relevant context fields
- Set DM thresholds carefully - Only alert on actionable events
- Use spans for request tracing - Leverage
#[instrument] - Configure relay redundancy - Use multiple relays for reliability
Performance Considerations
- Events are processed asynchronously to avoid blocking
- DM sending is optional and non-blocking
- Failed Nostr sends are logged but don't crash the application
- Configurable field inclusion to control overhead
Error Handling
The layer handles errors gracefully:
- Failed Nostr events are logged to stderr
- DM failures don't affect event capture
- Network issues are retried automatically
- Malformed events are skipped with warnings