CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-langfuse--langfuse-java

Java client for the Langfuse API providing access to observability and analytics features for LLM applications

Overview
Eval results
Files

health.mddocs/

Health

The Health API provides health check endpoints for monitoring API and database availability.

Capabilities

HealthClient

Client for checking API and database health.

/**
 * Check health of API and database
 *
 * @param requestOptions Optional request configuration
 * @return Health status response
 * @throws ServiceUnavailableError if service is unavailable (503)
 */
HealthResponse health();
HealthResponse health(RequestOptions requestOptions);

Usage Examples:

import com.langfuse.client.LangfuseClient;
import com.langfuse.client.resources.health.types.*;
import com.langfuse.client.resources.health.errors.*;

LangfuseClient client = LangfuseClient.builder()
    .url("https://cloud.langfuse.com")
    .credentials("pk-lf-...", "sk-lf-...")
    .build();

try {
    HealthResponse health = client.health().health();
    System.out.println("Status: " + health.getStatus());
    System.out.println("Version: " + health.getVersion());
} catch (ServiceUnavailableError e) {
    System.err.println("Service unavailable: " + e.statusCode());
}

Response Types

HealthResponse

/**
 * Health check response
 */
public final class HealthResponse {
    String getStatus();   // Health status (e.g., "ok")
    String getVersion();  // API version

    static Builder builder();
}

Error Handling

ServiceUnavailableError

The health endpoint may throw a ServiceUnavailableError (503 status code) when the service is unavailable.

import com.langfuse.client.resources.health.errors.ServiceUnavailableError;

try {
    HealthResponse health = client.health().health();
    // Service is healthy
} catch (ServiceUnavailableError e) {
    // Service is unavailable
    System.err.println("Service unavailable: " + e.getMessage());
    System.err.println("Status code: " + e.statusCode());
}

Monitoring Example

import com.langfuse.client.LangfuseClient;
import com.langfuse.client.resources.health.types.*;
import com.langfuse.client.resources.health.errors.*;
import java.util.concurrent.*;

public class HealthMonitor {
    private final LangfuseClient client;
    private final ScheduledExecutorService scheduler;

    public HealthMonitor(LangfuseClient client) {
        this.client = client;
        this.scheduler = Executors.newScheduledThreadPool(1);
    }

    public void startMonitoring(int intervalSeconds) {
        scheduler.scheduleAtFixedRate(
            this::checkHealth,
            0,
            intervalSeconds,
            TimeUnit.SECONDS
        );
    }

    public void stopMonitoring() {
        scheduler.shutdown();
    }

    private void checkHealth() {
        try {
            HealthResponse health = client.health().health();
            System.out.println(
                "[" + java.time.Instant.now() + "] " +
                "Health: " + health.getStatus() +
                ", Version: " + health.getVersion()
            );
        } catch (ServiceUnavailableError e) {
            System.err.println(
                "[" + java.time.Instant.now() + "] " +
                "Service unavailable (503)"
            );
            // Trigger alert
        } catch (Exception e) {
            System.err.println(
                "[" + java.time.Instant.now() + "] " +
                "Health check failed: " + e.getMessage()
            );
        }
    }

    public static void main(String[] args) {
        LangfuseClient client = LangfuseClient.builder()
            .url("https://cloud.langfuse.com")
            .credentials("pk-lf-...", "sk-lf-...")
            .build();

        HealthMonitor monitor = new HealthMonitor(client);

        // Check health every 30 seconds
        monitor.startMonitoring(30);

        // Keep running
        try {
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException e) {
            monitor.stopMonitoring();
        }
    }
}

Best Practices

  1. Regular Checks: Implement periodic health checks for monitoring
  2. Error Handling: Handle ServiceUnavailableError gracefully
  3. Logging: Log health check results for debugging
  4. Alerting: Set up alerts for repeated failures
  5. Timeout: Use reasonable timeout for health checks
  6. Startup: Check health on application startup
  7. Dependencies: Health endpoint checks both API and database

Use Cases

Application Startup

public void initializeApplication() {
    LangfuseClient client = LangfuseClient.builder()
        .url("https://cloud.langfuse.com")
        .credentials("pk-lf-...", "sk-lf-...")
        .build();

    // Check health before starting
    try {
        HealthResponse health = client.health().health();
        System.out.println("Langfuse is available (version: " + health.getVersion() + ")");
    } catch (ServiceUnavailableError e) {
        System.err.println("WARNING: Langfuse is unavailable, starting in degraded mode");
    }
}

Load Balancer Health Check

@RestController
public class HealthController {
    private final LangfuseClient langfuseClient;

    @GetMapping("/health/langfuse")
    public ResponseEntity<String> checkLangfuseHealth() {
        try {
            HealthResponse health = langfuseClient.health().health();
            return ResponseEntity.ok("Langfuse: " + health.getStatus());
        } catch (ServiceUnavailableError e) {
            return ResponseEntity.status(503).body("Langfuse unavailable");
        }
    }
}

Circuit Breaker Pattern

import io.github.resilience4j.circuitbreaker.CircuitBreaker;

public class LangfuseHealthCircuitBreaker {
    private final LangfuseClient client;
    private final CircuitBreaker circuitBreaker;

    public boolean isHealthy() {
        return circuitBreaker.executeSupplier(() -> {
            try {
                HealthResponse health = client.health().health();
                return "ok".equals(health.getStatus());
            } catch (ServiceUnavailableError e) {
                return false;
            }
        });
    }
}

Related Documentation

  • Exceptions - Error types and handling
  • Client Configuration - Timeout configuration

Install with Tessl CLI

npx tessl i tessl/maven-com-langfuse--langfuse-java

docs

client-configuration.md

comments-annotations.md

common-types.md

datasets.md

exceptions.md

health.md

index.md

ingestion.md

media.md

metrics.md

models.md

pagination.md

projects-organizations.md

prompts.md

scim.md

scores.md

sessions.md

traces-observations.md

tile.json