Skip to content

Seamlessly integrates Sentry performance monitoring with Axon Framework through OpenTelemetry. Automatically traces commands, events, queries, sagas & event processors with zero-config Spring Boot setup. Get distributed tracing across async boundaries, correlation with errors, and configurable sampling for production workloads.

Notifications You must be signed in to change notification settings

cwoskoski/axon-sentry-tracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Axon-Sentry-Tracing

License Kotlin Axon Framework

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.

Features

  • 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

Quick Start

Maven

<dependency>
    <groupId>io.github.yourusername</groupId>
    <artifactId>axon-sentry-tracing</artifactId>
    <version>0.1.0</version>
</dependency>

Gradle (Kotlin DSL)

implementation("io.github.yourusername:axon-sentry-tracing:0.1.0")

Configuration (Spring Boot)

Add to application.yml:

axon:
  sentry:
    tracing:
      enabled: true
      sentry-dsn: ${SENTRY_DSN}
      environment: production
      traces-sample-rate: 0.1  # Sample 10% of traces

That's it! All Axon messages will now be traced and sent to Sentry.

Usage Example

Domain Code (No Changes Required!)

@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)
    }
}

View in Sentry

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

Architecture

┌─────────────────┐
│  Axon Framework │
│                 │
│  ┌───────────┐  │     ┌──────────────┐
│  │ Commands  │◄─┼─────┤ Interceptors │
│  └───────────┘  │     └──────┬───────┘
│  ┌───────────┐  │            │
│  │  Events   │◄─┼────────────┤
│  └───────────┘  │            │
│  ┌───────────┐  │            │
│  │ Queries   │◄─┼────────────┤
│  └───────────┘  │            │
└─────────────────┘            │
                               │
                    ┌──────────▼──────────┐
                    │  OpenTelemetry SDK  │
                    │                     │
                    │  • Span Creation    │
                    │  • Context Prop.    │
                    │  • Batching         │
                    └──────────┬──────────┘
                               │
                    ┌──────────▼──────────┐
                    │   Sentry Exporter   │
                    │                     │
                    │  • Span Mapping     │
                    │  • Transaction      │
                    │  • Error Tracking   │
                    └──────────┬──────────┘
                               │
                    ┌──────────▼──────────┐
                    │      Sentry.io      │
                    │                     │
                    │  Performance & Errors│
                    └─────────────────────┘

Configuration Options

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

Advanced Usage

Custom Attributes

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)
            )
        }
    }
}

Programmatic Configuration

val config = TracingConfiguration.builder()
    .enabled(true)
    .sentryDsn("https://key@sentry.io/project")
    .tracesSampleRate(0.25)
    .addAttributeProvider { message ->
        mapOf("custom.attribute" to "value")
    }
    .build()

Examples

See the examples directory for complete working applications:

  • Spring Boot Demo - Full-featured bank account application
  • Coming soon: Microservices example, Saga example

Documentation

Requirements

  • Java 17+
  • Kotlin 1.9+
  • Axon Framework 4.9+
  • Spring Boot 3.2+ (for auto-configuration)

Compatibility

axon-sentry-tracing Axon Framework Sentry OpenTelemetry Spring Boot
0.1.x 4.9.x 7.x 1.33+ 3.2+

Performance

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.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for:

  • Code of conduct
  • Development setup
  • Testing requirements
  • Pull request process

Development

Build

./gradlew build

Test

./gradlew test

Code Quality

./gradlew detekt ktlint

Local Publishing

./gradlew publishToMavenLocal

Roadmap

  • 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.

FAQ

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.

Support

License

Apache License 2.0 - see LICENSE for details.

Acknowledgments

  • Axon Framework - Excellent event sourcing and CQRS framework
  • Sentry - Powerful error tracking and performance monitoring
  • OpenTelemetry - Industry-standard observability framework

Related Projects


Status: In Development Version: 0.1.0-SNAPSHOT Maintainer: @yourusername

About

Seamlessly integrates Sentry performance monitoring with Axon Framework through OpenTelemetry. Automatically traces commands, events, queries, sagas & event processors with zero-config Spring Boot setup. Get distributed tracing across async boundaries, correlation with errors, and configurable sampling for production workloads.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •