Distributed tracing for Axon Framework with Sentry via OpenTelemetry
axon-sentry-tracing seamlessly integrates Sentry's performance monitoring and error tracking with Axon Framework applications through OpenTelemetry instrumentation. Get end-to-end visibility into your event-sourced, CQRS applications with minimal configuration.
- Automatic Tracing - Commands, events, queries, sagas, and event processors automatically traced
- OpenTelemetry Native - Built on industry-standard OpenTelemetry for maximum compatibility
- Sentry Integration - View traces and errors in Sentry's powerful UI
- Spring Boot Auto-Configuration - Zero-config setup for Spring Boot applications
- Distributed Tracing - Trace propagation across async boundaries and distributed systems
- Configurable - Fine-grained control over what gets traced and captured
- Production Ready - Optimized for performance with configurable sampling
- Type Safe - Written in Kotlin with full type safety
<dependency>
<groupId>io.github.yourusername</groupId>
<artifactId>axon-sentry-tracing</artifactId>
<version>0.1.0</version>
</dependency>implementation("io.github.yourusername:axon-sentry-tracing:0.1.0")Add to application.yml:
axon:
sentry:
tracing:
enabled: true
sentry-dsn: ${SENTRY_DSN}
environment: production
traces-sample-rate: 0.1 # Sample 10% of tracesThat's it! All Axon messages will now be traced and sent to Sentry.
@Aggregate
class BankAccount {
@AggregateIdentifier
private lateinit var accountId: UUID
@CommandHandler
constructor(command: CreateAccountCommand) {
// Command automatically traced
AggregateLifecycle.apply(AccountCreatedEvent(command.accountId))
}
}
@Component
class AccountProjection {
@EventHandler
fun on(event: AccountCreatedEvent) {
// Event handling automatically traced
// Link back to originating command
}
}
@Component
class AccountQueryHandler {
@QueryHandler
fun handle(query: FindAccountQuery): Account {
// Query automatically traced
return findAccount(query.accountId)
}
}Navigate to Sentry's Performance dashboard to see:
- Command execution spans (e.g.,
Command: CreateAccountCommand) - Event publication and processing (e.g.,
Handle: AccountCreatedEvent) - Query execution (e.g.,
Query: FindAccountQuery) - Full distributed traces across your application
- Performance metrics and error correlation
┌─────────────────┐
│ Axon Framework │
│ │
│ ┌───────────┐ │ ┌──────────────┐
│ │ Commands │◄─┼─────┤ Interceptors │
│ └───────────┘ │ └──────┬───────┘
│ ┌───────────┐ │ │
│ │ Events │◄─┼────────────┤
│ └───────────┘ │ │
│ ┌───────────┐ │ │
│ │ Queries │◄─┼────────────┤
│ └───────────┘ │ │
└─────────────────┘ │
│
┌──────────▼──────────┐
│ OpenTelemetry SDK │
│ │
│ • Span Creation │
│ • Context Prop. │
│ • Batching │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Sentry Exporter │
│ │
│ • Span Mapping │
│ • Transaction │
│ • Error Tracking │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Sentry.io │
│ │
│ Performance & Errors│
└─────────────────────┘
All configuration via axon.sentry.tracing prefix:
| Property | Default | Description |
|---|---|---|
enabled |
true |
Master switch for tracing |
trace-commands |
true |
Trace command execution |
trace-events |
true |
Trace event processing |
trace-queries |
true |
Trace query execution |
trace-event-processors |
true |
Trace event processors |
trace-sagas |
true |
Trace saga execution |
capture-command-payloads |
false |
Include command payloads (caution: sensitive data) |
capture-event-payloads |
false |
Include event payloads |
capture-query-payloads |
false |
Include query payloads |
sentry-dsn |
- | Sentry Data Source Name |
environment |
development |
Environment name |
traces-sample-rate |
1.0 |
Sample rate (0.0 to 1.0) |
tags |
{} |
Additional tags for all spans |
Add custom attributes to spans:
@Configuration
class TracingConfig {
@Bean
fun customAttributeProvider(): CustomAttributeProvider {
return CustomAttributeProvider { message ->
mapOf(
"tenant.id" to extractTenantId(message),
"user.id" to extractUserId(message)
)
}
}
}val config = TracingConfiguration.builder()
.enabled(true)
.sentryDsn("https://key@sentry.io/project")
.tracesSampleRate(0.25)
.addAttributeProvider { message ->
mapOf("custom.attribute" to "value")
}
.build()See the examples directory for complete working applications:
- Spring Boot Demo - Full-featured bank account application
- Coming soon: Microservices example, Saga example
- Implementation Issues - Detailed technical documentation
- API Documentation - Generated KDoc
- User Guide - Comprehensive usage guide
- Architecture Decisions - ADRs and design docs
- Java 17+
- Kotlin 1.9+
- Axon Framework 4.9+
- Spring Boot 3.2+ (for auto-configuration)
| axon-sentry-tracing | Axon Framework | Sentry | OpenTelemetry | Spring Boot |
|---|---|---|---|---|
| 0.1.x | 4.9.x | 7.x | 1.33+ | 3.2+ |
Overhead is minimal and configurable:
- Span Creation: ~10-50μs per span
- Metadata Enrichment: ~5-20μs
- Memory: ~100 bytes per span
- Network: Async batched export (configurable)
Use sampling (traces-sample-rate) to reduce overhead in high-throughput scenarios.
Contributions welcome! Please see CONTRIBUTING.md for:
- Code of conduct
- Development setup
- Testing requirements
- Pull request process
./gradlew build./gradlew test./gradlew detekt ktlint./gradlew publishToMavenLocal- Core tracing implementation
- Spring Boot auto-configuration
- Saga tracing
- Deadletter queue integration
- Metrics and monitoring
- Performance optimizations
- Kotlin Multiplatform support
See issues for detailed roadmap.
Q: Does this work with Axon Server? A: Yes! Tracing works with both embedded event stores and Axon Server.
Q: What's the performance impact? A: Minimal. Use sampling in production to reduce overhead. Typical overhead is <5%.
Q: Can I use this without Spring Boot? A: Yes! Manual configuration is available. See programmatic configuration.
Q: Does this support distributed tracing? A: Yes! Trace context propagates through Axon message metadata across process boundaries.
Q: Can I filter which messages are traced? A: Yes! Use configuration properties to enable/disable command, event, or query tracing.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Stack Overflow: Tag with
axon-frameworkandsentry
Apache License 2.0 - see LICENSE for details.
- Axon Framework - Excellent event sourcing and CQRS framework
- Sentry - Powerful error tracking and performance monitoring
- OpenTelemetry - Industry-standard observability framework
Status: In Development Version: 0.1.0-SNAPSHOT Maintainer: @yourusername