Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry integration #292

Open
jamiemccarthy opened this issue Jul 8, 2023 · 2 comments
Open

OpenTelemetry integration #292

jamiemccarthy opened this issue Jul 8, 2023 · 2 comments

Comments

@jamiemccarthy
Copy link
Contributor

I'm writing an app with ruby-openai and it gives me a bit of a worry that I don't know how much I'm spending on OpenAI. I would like a pane on my Honeycomb.ai dashboard measuring how much data I'm sending and receiving. Adding alerting to my dashboard for unexpectedly high usage would give me peace of mind. And if latency of OpenAI's servers was also instrumented, so I could see that latency in traces, that would help me understand what performance I should expect as well.

OpenTelemetry seems like the natural way to instrument this. Here's a list of existing libraries. I'd love to add

  c.use "OpenTelemetry::Instrumentation::Openai"

to my config/initializers/opentelemetry.rb and have my ruby-openai usage magically become available on my Honeycomb dashboard. Or of course it would work for whatever other provider people are using.

My suggested implementation would be to make the telemetry class a separate gem, and add a check whether the gem's class is defined in OpenAI::HTTP#json_post and related methods. If so, wrap the methods' functionality in a tracing block. But I'm open to alternatives. I haven't actually written a telemetry module before, so maybe thinking it's easy is hubris on my part.

Alternatively, I could add a similar wrapper in my own app and just use it for personal use. But this seems like something that would benefit the community and might as well be shared.

@marckohlbrugge
Copy link

One approach is to make the gem more extendable. The HTTP gem does a great job at this. Here’s some examples:

https://github.com/httprb/http/tree/main/lib/http/features

If this gem would have the right hooks, it allow anyone anyone to more easily build features like telemetry on top of it.

@alexrudall
Copy link
Owner

@jamiemccarthy - v6.3 allows you to add custom Faraday middleware - see README - I think this could be used to link to OpenTelemetry?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants