This guide helps you quickly set up and use the end-to-end tracing system for monitoring data packets as they flow from external API providers through relayers to on-chain submission.
Add these environment variables to your .env file:
# Enable tracing
TRACING_ENABLED=true
TRACING_SERVICE_NAME=stellarflow-backend
# Console exporter (for development)
TRACING_CONSOLE_EXPORTER=true
# Optional: Jaeger exporter
TRACING_JAEGER_ENDPOINT=http://localhost:14268/api/traces
# Optional: Honeycomb exporter
TRACING_HONEYCOMB_ENDPOINT=https://api.honeycomb.io/v1/events
TRACING_HONEYCOMB_API_KEY=your_api_key_here
TRACING_HONEYCOMB_DATASET=stellarflownpm run devYou should see tracing initialization messages:
[Tracing] Console exporter enabled
[Tracing] Initialized with service name: stellarflow-backend
[Tracing] Export interval: 5000ms
Send a request to any API endpoint:
curl -H "Authorization: Bearer your_api_key" \
http://localhost:3000/api/v1/market-rates/ratesYou'll see trace output in your console:
[Trace] GET /api/v1/market-rates/rates - 45ms - a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6:a1b2c3d4e5f6g7h8
[Trace] Tags: { http.method: 'GET', http.url: '/api/v1/market-rates/rates', ... }
[Trace] database.query - 12ms - a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6:b2c3d4e5f6g7h8i9j0
[Trace] api_request.external_api - 89ms - a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6:c3d4e5f6g7h8i9j0k
- Open Jaeger UI: http://localhost:16686
- Select service:
stellarflow-backend - Click "Find Traces" to see recent requests
- Click on any trace to see the full span tree
- Log into Honeycomb.io
- Select your dataset:
stellarflow - View traces and create queries
A typical trace shows the complete data flow:
├── GET /api/v1/market-rates/rates (Root Span)
│ ├── relayer.request_validation
│ ├── api_request.external_provider
│ │ ├── HTTP GET https://api.example.com/rates
│ │ └── response_processing
│ ├── price_validation
│ ├── database.query
│ └── cache.set
HTTP Request → Relayer Validation → API Call → Data Processing → Storage → Response
HTTP Request → API Call → Error → Error Handling → Error Response
Request → Multi-sig Creation → Signature Collection → On-chain Submission → Confirmation
import { TracingService } from '../services/tracingService';
// In your route handler
router.post('/process', async (req, res) => {
const span = TracingService.traceRelayerRequest(req, 'my-relayer', 'process-data');
try {
// Your business logic
TracingService.addLog(span, 'info', 'Processing started');
const result = await processData(req.body);
TracingService.addLog(span, 'info', 'Processing completed');
TracingService.finishSpan(span);
res.json({ success: true, data: result });
} catch (error) {
TracingService.finishSpan(span, error);
res.status(500).json({ error: error.message });
}
});import { withTracing } from '../services/tracingService';
class PriceService {
@withTracing('price_fetch', { 'provider': 'external_api' })
async fetchPrice(currency: string) {
// Automatically traced
return await axios.get(`https://api.example.com/rates/${currency}`);
}
}- Check
TRACING_ENABLED=true - Verify middleware is loaded in
app.ts - Check console for initialization errors
- Ensure
tracingMiddlewareis loaded before other middleware - Check
axiosTracingMiddlewareis loaded - Verify axios interceptors are set up
- Check collector endpoint URLs
- Verify network connectivity
- Check API keys for cloud services
- Reduce
TRACING_SAMPLING_RATE - Decrease
TRACING_EXPORT_INTERVAL_MS - Check for unfinished spans
# Using Docker
docker run -d --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 14268:14268 \
jaegertracing/all-in-one:latest# Production settings
TRACING_ENABLED=true
TRACING_CONSOLE_EXPORTER=false
TRACING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces
TRACING_SAMPLING_RATE=0.1 # 10% sampling
TRACING_EXPORT_INTERVAL_MS=10000- Request Duration: Average time per endpoint
- API Provider Latency: External API response times
- Database Query Time: Database operation performance
- Cache Hit Rate: Cache effectiveness
- Error Rates: Failure frequency by operation
- On-chain Submission Time: Stellar transaction speed
- Use Consistent Naming: Standardize span names and tags
- Add Context: Include relevant business context in tags
- Handle Errors: Always finish spans, even on errors
- Monitor Performance: Watch tracing overhead
- Sample Appropriately: Adjust sampling based on traffic
- Set up Dashboards: Create monitoring dashboards
- Configure Alerts: Set up trace-based alerts
- Analyze Performance: Identify optimization opportunities
- Extend Coverage: Add tracing to more operations
- Integrate with Monitoring: Connect to existing monitoring tools
This quick start guide should help you get the tracing system running and understand the data flow through your application. For more detailed information, see the full implementation documentation.