Skip to content

alibaba/loongsuite-java

Repository files navigation

LoongSuite Java GenAI Utils

Introduction

LoongSuite Java GenAI Utils is a key component of LoongSuite, Alibaba's unified observability data collection suite, providing shared telemetry lifecycle management for Java GenAI instrumentation.

LoongSuite includes the following key components:

Built on OTel GenAI Semantic Conventions v1.41.1, this library is the Java counterpart of opentelemetry-util-genai.

Maven Coordinates

Replace ${otel-util-genai.version} with the latest otel-util-genai release from Maven Central.

<dependency>
    <groupId>com.alibaba.loongsuite</groupId>
    <artifactId>otel-util-genai</artifactId>
    <version>${otel-util-genai.version}</version>
</dependency>

Installation

Replace ${otel-util-genai.version} and ${opentelemetry.version} with the latest releases of otel-util-genai and opentelemetry-bom from Maven Central.

Maven

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-bom</artifactId>
            <version>${opentelemetry.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>com.alibaba.loongsuite</groupId>
        <artifactId>otel-util-genai</artifactId>
        <version>${otel-util-genai.version}</version>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-sdk</artifactId>
    </dependency>
    <dependency>
        <groupId>io.opentelemetry</groupId>
        <artifactId>opentelemetry-exporter-otlp</artifactId>
    </dependency>
</dependencies>

Gradle

// Use the latest releases from Maven Central
def otelUtilGenaiVersion = '...'      // otel-util-genai
def opentelemetryBomVersion = '...'   // opentelemetry-bom

implementation platform("io.opentelemetry:opentelemetry-bom:${opentelemetryBomVersion}")
implementation "com.alibaba.loongsuite:otel-util-genai:${otelUtilGenaiVersion}"
implementation 'io.opentelemetry:opentelemetry-sdk'
implementation 'io.opentelemetry:opentelemetry-exporter-otlp'

This library depends only on the OTel API. Without an SDK and exporter, operations are no-ops.

Quick Start

OpenTelemetry openTelemetry =
    AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk();
GenAiTelemetryHandler handler = GenAiTelemetryHandler.create(openTelemetry);

try (InferenceInvocation inv = handler.inference("openai", "gpt-4o")) {
    inv.setInputMessages(
        Collections.singletonList(
            new InputMessage("user", Collections.singletonList(new TextPart("Hello")))));
    // Call your LLM client here, then record the response:
    inv.setOutputMessages(
        Collections.singletonList(
            new OutputMessage(
                "assistant",
                Collections.singletonList(new TextPart("Hi there!")),
                "stop")));
}

See docs/USAGE.md for all operation types, streaming, error handling, environment variables, and CompletionHook.

Documentation

Document Description
docs/USAGE.md Usage guide (operations, config, hooks)
examples/README.md Spring Boot example (7 GenAI operations)

Requirements

  • Java 8+
  • OpenTelemetry API (use the latest opentelemetry-bom release)

Community

We are looking forward to your feedback and suggestions. You can join our DingTalk user group and DingTalk developer group to engage with us.

User Group Developer Group

Resources

License

This project is licensed under the Apache License 2.0

About

LoongSuite Java GenAI telemetry utility library, built on OpenTelemetry GenAI Semantic Conventions.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages