|
1 |
| -# go-openllmetry |
2 |
| -Sister project to OpenLLMetry, but in Go. Open-source observability for your LLM application, based on OpenTelemetry |
| 1 | +<p align="center"> |
| 2 | +<a href="https://www.traceloop.com/openllmetry#gh-light-mode-only"> |
| 3 | +<img width="600" src="https://raw.githubusercontent.com/traceloop/openllmetry/main/img/logo-light.png"> |
| 4 | +</a> |
| 5 | +<a href="https://www.traceloop.com/openllmetry#gh-dark-mode-only"> |
| 6 | +<img width="600" src="https://raw.githubusercontent.com/traceloop/openllmetry/main/img/logo-dark.png"> |
| 7 | +</a> |
| 8 | +</p> |
| 9 | +<h1 align="center">For Go</h1> |
| 10 | +<p align="center"> |
| 11 | + <p align="center">Open-source observability for your LLM application</p> |
| 12 | +</p> |
| 13 | +<h4 align="center"> |
| 14 | + <a href="https://traceloop.com/docs/openllmetry/getting-started-go"><strong>Get started »</strong></a> |
| 15 | + <br /> |
| 16 | + <br /> |
| 17 | + <a href="https://traceloop.com/slack">Slack</a> | |
| 18 | + <a href="https://traceloop.com/docs/openllmetry/introduction">Docs</a> | |
| 19 | + <a href="https://www.traceloop.com">Website</a> |
| 20 | +</h4> |
| 21 | + |
| 22 | +<h4 align="center"> |
| 23 | + <a href="https://github.com/traceloop/go-openllmetry/blob/main/LICENSE"> |
| 24 | + <img src="https://img.shields.io/badge/license-Apache 2.0-blue.svg" alt="OpenLLMetry is released under the Apache-2.0 License"> |
| 25 | + </a> |
| 26 | + <a href="https://www.ycombinator.com/companies/traceloop"><img src="https://img.shields.io/website?color=%23f26522&down_message=Y%20Combinator&label=Backed&logo=ycombinator&style=flat-square&up_message=Y%20Combinator&url=https%3A%2F%2Fwww.ycombinator.com"></a> |
| 27 | + <a href="https://github.com/traceloop/go-openllmetry/blob/main/CONTRIBUTING.md"> |
| 28 | + <img src="https://img.shields.io/badge/PRs-Welcome-brightgreen" alt="PRs welcome!" /> |
| 29 | + </a> |
| 30 | + <a href="https://github.com/traceloop/go-openllmetry/issues"> |
| 31 | + <img src="https://img.shields.io/github/commit-activity/m/traceloop/go-openllmetry" alt="git commit activity" /> |
| 32 | + </a> |
| 33 | + <a href="https://traceloop.com/slack"> |
| 34 | + <img src="https://img.shields.io/badge/chat-on%20Slack-blueviolet" alt="Slack community channel" /> |
| 35 | + </a> |
| 36 | + <a href="https://twitter.com/traceloopdev"> |
| 37 | + <img src="https://img.shields.io/badge/follow-%40traceloopdev-1DA1F2?logo=twitter&style=social" alt="Traceloop Twitter" /> |
| 38 | + </a> |
| 39 | +</h4> |
| 40 | + |
| 41 | +OpenLLMetry is a set of extensions built on top of [OpenTelemetry](https://opentelemetry.io/) 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. |
| 42 | + |
| 43 | +It's built and maintained by Traceloop under the Apache 2.0 license. |
| 44 | + |
| 45 | +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. |
| 46 | +If you already have OpenTelemetry instrumented, you can just add any of our instrumentations directly. |
| 47 | + |
| 48 | +## 🚀 Getting Started |
| 49 | + |
| 50 | +The easiest way to get started is to use our SDK. |
| 51 | +For a complete guide, go to our [docs](https://traceloop.com/docs/openllmetry/getting-started-go). |
| 52 | + |
| 53 | +Install the SDK: |
| 54 | + |
| 55 | +```bash |
| 56 | +go get traceloop-sdk |
| 57 | +``` |
| 58 | + |
| 59 | +Then, initialize the SDK in your code: |
| 60 | + |
| 61 | +```go |
| 62 | +package main |
| 63 | + |
| 64 | +import ( |
| 65 | + "context" |
| 66 | + |
| 67 | + sdk "github.com/traceloop/go-openllmetry/traceloop-sdk" |
| 68 | + "github.com/traceloop/go-openllmetry/traceloop-sdk/config" |
| 69 | +) |
| 70 | + |
| 71 | +func main() { |
| 72 | + ctx := context.Background() |
| 73 | + |
| 74 | + traceloop := sdk.NewClient(config.Config{ |
| 75 | + BaseURL: "api.traceloop.com", |
| 76 | + APIKey: os.Getenv("TRACELOOP_API_KEY"), |
| 77 | + }) |
| 78 | + defer func() { traceloop.Shutdown(ctx) }() |
| 79 | + |
| 80 | + traceloop.Initialize(ctx) |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +That's it. You're now tracing your code with OpenLLMetry! |
| 85 | + |
| 86 | +Now, you need to decide where to export the traces to. |
| 87 | + |
| 88 | +## ⏫ Supported (and tested) destinations |
| 89 | + |
| 90 | +- [x] [Traceloop](https://www.traceloop.com/docs/openllmetry/integrations/traceloop) |
| 91 | +- [x] [Dynatrace](https://www.traceloop.com/docs/openllmetry/integrations/dynatrace) |
| 92 | +- [x] [Datadog](https://www.traceloop.com/docs/openllmetry/integrations/datadog) |
| 93 | +- [x] [New Relic](https://www.traceloop.com/docs/openllmetry/integrations/newrelic) |
| 94 | +- [x] [Honeycomb](https://www.traceloop.com/docs/openllmetry/integrations/honeycomb) |
| 95 | +- [x] [Grafana Tempo](https://www.traceloop.com/docs/openllmetry/integrations/grafana) |
| 96 | +- [x] [HyperDX](https://www.traceloop.com/docs/openllmetry/integrations/hyperdx) |
| 97 | +- [x] [SigNoz](https://www.traceloop.com/docs/openllmetry/integrations/signoz) |
| 98 | +- [x] [OpenTelemetry Collector](https://www.traceloop.com/docs/openllmetry/integrations/otel-collector) |
| 99 | + |
| 100 | +See [our docs](https://traceloop.com/docs/openllmetry/integrations/exporting) for instructions on connecting to each one. |
| 101 | + |
| 102 | +## 🪗 What do we instrument? |
| 103 | + |
| 104 | +OpenLLMetry is in early-alpha exploratory stage, and we're still figuring out what to instrument. |
| 105 | +As opposed to other languages, there aren't many official LLM libraries (yet?), so for now you'll have to manually log prompts: |
| 106 | + |
| 107 | +```go |
| 108 | +package main |
| 109 | + |
| 110 | +import ( |
| 111 | + "context" |
| 112 | + "fmt" |
| 113 | + "os" |
| 114 | + |
| 115 | + "github.com/sashabaranov/go-openai" |
| 116 | + sdk "github.com/traceloop/go-openllmetry/traceloop-sdk" |
| 117 | + "github.com/traceloop/go-openllmetry/traceloop-sdk/config" |
| 118 | + "github.com/traceloop/go-openllmetry/traceloop-sdk/dto" |
| 119 | +) |
| 120 | + |
| 121 | +func main() { |
| 122 | + ctx := context.Background() |
| 123 | + |
| 124 | + // Initialize Traceloop |
| 125 | + traceloop := sdk.NewClient(config.Config{ |
| 126 | + BaseURL: "api.traceloop.com", |
| 127 | + APIKey: os.Getenv("TRACELOOP_API_KEY"), |
| 128 | + }) |
| 129 | + defer func() { traceloop.Shutdown(ctx) }() |
| 130 | + |
| 131 | + traceloop.Initialize(ctx) |
| 132 | + |
| 133 | + // Call OpenAI like you normally would |
| 134 | + resp, err := client.CreateChatCompletion( |
| 135 | + context.Background(), |
| 136 | + openai.ChatCompletionRequest{ |
| 137 | + Model: openai.GPT3Dot5Turbo, |
| 138 | + Messages: []openai.ChatCompletionMessage{ |
| 139 | + { |
| 140 | + Role: openai.ChatMessageRoleUser, |
| 141 | + Content: "Tell me a joke about OpenTelemetry!", |
| 142 | + }, |
| 143 | + }, |
| 144 | + }, |
| 145 | + ) |
| 146 | + |
| 147 | + // Log the request and the response |
| 148 | + log := dto.PromptLogAttributes{ |
| 149 | + Prompt: dto.Prompt{ |
| 150 | + Vendor: "openai", |
| 151 | + Mode: "chat", |
| 152 | + Model: request.Model, |
| 153 | + }, |
| 154 | + Completion: dto.Completion{ |
| 155 | + Model: resp.Model, |
| 156 | + }, |
| 157 | + Usage: dto.Usage{ |
| 158 | + TotalTokens: resp.Usage.TotalTokens, |
| 159 | + CompletionTokens: resp.Usage.CompletionTokens, |
| 160 | + PromptTokens: resp.Usage.PromptTokens, |
| 161 | + }, |
| 162 | + } |
| 163 | + |
| 164 | + for i, message := range request.Messages { |
| 165 | + log.Prompt.Messages = append(log.Prompt.Messages, dto.Message{ |
| 166 | + Index: i, |
| 167 | + Content: message.Content, |
| 168 | + Role: message.Role, |
| 169 | + }) |
| 170 | + } |
| 171 | + |
| 172 | + for _, choice := range resp.Choices { |
| 173 | + log.Completion.Messages = append(log.Completion.Messages, dto.Message{ |
| 174 | + Index: choice.Index, |
| 175 | + Content: choice.Message.Content, |
| 176 | + Role: choice.Message.Role, |
| 177 | + }) |
| 178 | + } |
| 179 | + |
| 180 | + traceloop.LogPrompt(ctx, log) |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +## 🌱 Contributing |
| 185 | + |
| 186 | +Whether it's big or small, we love contributions ❤️ Check out our guide to see how to [get started](https://traceloop.com/docs/openllmetry/contributing/overview). |
| 187 | + |
| 188 | +Not sure where to get started? You can: |
| 189 | + |
| 190 | +- [Book a free pairing session with one of our teammates ](mailto:[email protected]?subject=Pairing%20session&body=I'd%20like%20to%20do%20a%20pairing%20session!)! |
| 191 | +- Join our <a href="https://join.slack.com/t/traceloopcommunity/shared_invite/zt-1plpfpm6r-zOHKI028VkpcWdobX65C~g">Slack</a>, and ask us any questions there. |
| 192 | + |
| 193 | +## 💚 Community & Support |
| 194 | + |
| 195 | +- [Slack](https://join.slack.com/t/traceloopcommunity/shared_invite/zt-1plpfpm6r-zOHKI028VkpcWdobX65C~g) (For live discussion with the community and the Traceloop team) |
| 196 | +- [GitHub Discussions](https://github.com/traceloop/go-openllmetry/discussions) (For help with building and deeper conversations about features) |
| 197 | +- [GitHub Issues](https://github.com/traceloop/go-openllmetry/issues) (For any bugs and errors you encounter using OpenLLMetry) |
| 198 | +- [Twitter](https://twitter.com/traceloopdev) (Get news fast) |
| 199 | + |
| 200 | +## 🙏 Special Thanks |
| 201 | + |
| 202 | +To @patrickdebois, who [suggested the great name](https://x.com/patrickdebois/status/1695518950715473991?s=46&t=zn2SOuJcSVq-Pe2Ysevzkg) we're now using for this repo! |
0 commit comments