Skip to content

sathwikhbhat/api-execution-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Execution Tracker

Java 21+ Spring Boot 4+ Maven Central Maven License: MIT

Measure and log API execution time in Spring Boot with one annotation, automatic setup, and configurable thresholds.

Warning

Supports Spring Boot 4+ with Java 21+
Spring Boot 3.x and Java versions below 21 are not supported.

Why Use It

  • Track execution time using one annotation: @TrackExecutionTime
  • Web context logging: HTTP method + path + query string
  • Endpoint-level logging for request-driven flows
  • Configurable output unit and log threshold
  • Autoconfiguration when dependency is present

Installation

Maven

Add this dependency in your application pom.xml:

<dependency>
    <groupId>io.github.sathwikhbhat</groupId>
    <artifactId>api-execution-tracker</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

Add this dependency in your application build.gradle.kts:

implementation("io.github.sathwikhbhat:api-execution-tracker:1.0.0")

Note

You can also find this dependency and usage details for other build tools (sbt, ivy, grape etc.) on the Maven Central Repository page for API Execution Tracker.

Usage

Annotate a class or specific methods:

import io.github.sathwikhbhat.apiexecutiontracker.annotation.TrackExecutionTime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@TrackExecutionTime
public class DemoController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello";
    }
    
}

Configuration

Property prefix: tracker

tracker:
  enabled: true
  time-unit: milliseconds
  threshold: 0
Property Type Default Description
tracker.enabled boolean true Enables/disables tracking
tracker.time-unit seconds | milliseconds | microseconds | nanoseconds milliseconds Output time unit
tracker.threshold long 0 Minimum duration to log, interpreted in tracker.time-unit

Important

tracker.threshold always uses the same unit as tracker.time-unit.
By default, tracker.time-unit is milliseconds, so the threshold is in milliseconds.
If you set tracker.time-unit to seconds, the threshold will be read in seconds.

Example Logs

When called during an HTTP request:

GET /api/v1/users executed in 12 milliseconds

Important Behavior

  • Logging output is request-context driven.
  • If an annotated method runs during an active HTTP request (including service methods called by controllers), logs show the endpoint path (for example, GET /api/v1/xyz) instead of the Java method signature.
  • In practice for request-driven usage, expect endpoint-based logs rather than per-method signature logs.
  • Execution time is logged even when the request flow throws an error/exception.

Development / Contributing

For internals and contribution workflow, see DEVELOPER_README.

About

Annotation-based API execution time tracker

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages