Setting up Traceloop SDK for Middleware (Ruby)
This guide will walk you through the process of setting up the Traceloop SDK to work with Middleware for LLM Observability in a Ruby environment.
1. Install the SDK
Run one of the following commands in your terminal:
gem
gem install traceloop-sdk
2. Initialize the SDK
In your LLM application, initialize the Traceloop tracer:
require "traceloop/sdk" traceloop = Traceloop::SDK::Traceloop.new( base_url: "https://<MW_UID>.middleware.io:443", api_key: "<MW_API_KEY>" ) # Add headers traceloop.add_headers({ "Authorization" => "<MW_API_KEY>",
If you're using Rails, this initialization should be in config/initializers/traceloop.rb
.
3. Log Your Prompts
Currently, automatic instrumentation is not available for Ruby libraries. You'll need to manually log your prompts and completions.
Here's an example of how to log prompts and completions when using the OpenAI library:
require "openai" client = OpenAI::Client.new # This tracks the latency of the call and the response traceloop.llm_call(provider: "openai", model: "gpt-3.5-turbo") do |tracer| # Log the prompt tracer.log_prompt(user_prompt: "Tell me a joke about OpenTelemetry") # Call OpenAI like you normally would
Viewing Your Traces
After setting up the Traceloop SDK with Middleware, you'll be able to view your LLM application traces in your Middleware LLM Observability Section.
This integration provides instant visibility into everything happening within your LLM, including calls to vector databases or other external services.
For more detailed information on setting up Traceloop with Ruby, please refer to the Traceloop Ruby documentation
Need assistance or want to learn more about using Traceloop with Middleware? Contact our support team in Slack.