Skip to content

Repository files navigation

Lite Java Tracing

There are cases when a very lite "tracing" is needed, i.e. having just a Correlation-ID in the log messages, by the support of Mapped Diagnostic Context (MDC) This library covers exactly this need.

Warning

Under active development 🚧

Features

  • Per-thread Correlation-ID context (LiteTracingContext)
  • LiteTracedRunnable propagating the context to another thread
  • LiteTracedThreadFactory wrapping tasks in LiteTracedRunnable, with support for platform and virtual threads
  • new LiteTracedExecutorService(...) for per-task propagation on pooled executors

Choosing the right mechanism

Scenario Use
Virtual threads / thread-per-task LiteTracedThreadFactory.ofVirtual()
Pooled executor, varying submitter contexts new LiteTracedExecutorService(executor)
Single manual thread LiteTracedRunnable

Requirements

Java 25

Usage

Add to your project

<dependencies>
    <dependency>
        <groupId>com.petromirdzhunev.libs</groupId>
        <artifactId>lite-tracing</artifactId>
    </dependency>
</dependencies>

Code

LiteTracingContext.set("correlation-id-123");

// Virtual threads
ExecutorService executor = Executors.newThreadPerTaskExecutor(LiteTracedThreadFactory.ofVirtual());

// Platform threads
ExecutorService pool = Executors.newCachedThreadPool(LiteTracedThreadFactory.ofPlatform());

// Pooled executor with per-task propagation (id captured at submission time)
ExecutorService traced = new LiteTracedExecutorService(Executors.newCachedThreadPool());

Development

Prerequisites

  1. Install SDKMAN
  2. Initialize SDKMAN environment
sdk env install

Check .sdkmanrc for all the tools installed with this command.

Build and publish SNAPSHOT versions to local repository

Change the version by adding a -SNAPSHOT suffix in the pom.xml file and then execute:

 mvnd -B clean install

Pointing to a SNAPSHOT version

<dependencies>
    <dependency>
        <groupId>com.petromirdzhunev.lib</groupId>
        <artifactId>lite-tracing</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

Support my work

Buy Me A Ko-fi Buy Me A Coffee GitHub Sponsor

About

A lightweight Java tracing

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages