Giter Club home page Giter Club logo

go-openllmetry's Introduction

For Go

Open-source observability for your LLM application

OpenLLMetry is a set of extensions built on top of OpenTelemetry that gives you complete observability over your LLM application. Because it uses OpenTelemetry under the hood, it can be connected to your existing observability solutions - Datadog, Honeycomb, and others.

It's built and maintained by Traceloop under the Apache 2.0 license.

The repo contains standard OpenTelemetry instrumentations for LLM providers and Vector DBs, as well as a Traceloop SDK that makes it easy to get started with OpenLLMetry, while still outputting standard OpenTelemetry data that can be connected to your observability stack. If you already have OpenTelemetry instrumented, you can just add any of our instrumentations directly.

πŸš€ Getting Started

The easiest way to get started is to use our SDK. For a complete guide, go to our docs.

Install the SDK:

go get github.com/traceloop/go-openllmetry/traceloop-sdk

Then, initialize the SDK in your code:

package main

import (
	"context"

	sdk "github.com/traceloop/go-openllmetry/traceloop-sdk"
)

func main() {
    ctx := context.Background()

    traceloop := sdk.NewClient(ctx, sdk.Config{
		APIKey: os.Getenv("TRACELOOP_API_KEY"),
	})
	defer func() { traceloop.Shutdown(ctx) }()
}

That's it. You're now tracing your code with OpenLLMetry!

Now, you need to decide where to export the traces to.

⏫ Supported (and tested) destinations

See our docs for instructions on connecting to each one.

πŸͺ— What do we instrument?

OpenLLMetry is in early-alpha exploratory stage, and we're still figuring out what to instrument. As opposed to other languages, there aren't many official LLM libraries (yet?), so for now you'll have to manually log prompts:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/sashabaranov/go-openai"
	sdk "github.com/traceloop/go-openllmetry/traceloop-sdk"
)

func main() {
	ctx := context.Background()

	// Initialize Traceloop
	traceloop := sdk.NewClient(ctx, config.Config{
		APIKey:  os.Getenv("TRACELOOP_API_KEY"),
	})
	defer func() { traceloop.Shutdown(ctx) }()

	// Call OpenAI like you normally would
	resp, err := client.CreateChatCompletion(
		context.Background(),
		openai.ChatCompletionRequest{
			Model: openai.GPT3Dot5Turbo,
			Messages: []openai.ChatCompletionMessage{
				{
					Role:    openai.ChatMessageRoleUser,
					Content: "Tell me a joke about OpenTelemetry!",
				},
			},
		},
	)

    var promptMsgs []sdk.Message
    for i, message := range request.Messages {
    	promptMsgs = append(promptMsgs, sdk.Message{
    		Index:   i,
    		Content: message.Content,
    		Role:    message.Role,
    	})
    }

	// Log the request
    llmSpan, err := traceloop.LogPrompt(
    	ctx,
    	sdk.Prompt{
    		Vendor: "openai",
    		Mode:   "chat",
    		Model: request.Model,
    		Messages: promptMsgs,
    	},
    	sdk.TraceloopAttributes{
    		WorkflowName: "example-workflow",
    		EntityName:   "example-entity",
    	},
    )
    if err != nil {
    	fmt.Printf("LogPrompt error: %v\n", err)
    	return
    }

    client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
    resp, err := client.CreateChatCompletion(
    	context.Background(),
    	*request,
    )
    if err != nil {
    	fmt.Printf("ChatCompletion error: %v\n", err)
    	return
    }

    var completionMsgs []sdk.Message
    for _, choice := range resp.Choices {
    	completionMsgs = append(completionMsgs, sdk.Message{
    		Index:   choice.Index,
    		Content: choice.Message.Content,
    		Role:    choice.Message.Role,
    	})
    }

	// Log the response
    llmSpan.LogCompletion(ctx, sdk.Completion{
    	Model:    resp.Model,
    	Messages: completionMsgs,
    }, sdk.Usage{
    	TotalTokens:       resp.Usage.TotalTokens,
    	CompletionTokens:  resp.Usage.CompletionTokens,
    	PromptTokens:      resp.Usage.PromptTokens,
    })
}

🌱 Contributing

Whether it's big or small, we love contributions ❀️ Check out our guide to see how to get started.

Not sure where to get started? You can:

πŸ’š Community & Support

  • Slack (For live discussion with the community and the Traceloop team)
  • GitHub Discussions (For help with building and deeper conversations about features)
  • GitHub Issues (For any bugs and errors you encounter using OpenLLMetry)
  • Twitter (Get news fast)

πŸ™ Special Thanks

To @patrickdebois, who suggested the great name we're now using for this repo!

go-openllmetry's People

Contributors

galkleinman avatar nirga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.