Files
comet-ml--opik/apps/opik-documentation/documentation/fern/docs/reference/ruby-otel-sdk/overview.mdx
T
wehub-resource-sync 5a558eb09e
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / render-equality (push) Has been cancelled
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Has been cancelled
Python BE E2E Tests / Python BE E2E (push) Has been cancelled
Python Backend Tests / run-python-backend-tests (push) Has been cancelled
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
SDK E2E Libraries Integration Tests / Check Secrets (push) Has been cancelled
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Has been cancelled
SDK E2E Libraries Integration Tests / build-opik (push) Has been cancelled
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Has been cancelled
TypeScript SDK Build & Publish / build-and-publish (push) Has been cancelled
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Has been cancelled
Backend Tests / discover-tests (push) Has been cancelled
Backend Tests / ${{ matrix.name }} (push) Has been cancelled
Build and Publish SDK / build-and-publish (push) Has been cancelled
Build Opik Docker Images / set-version (push) Has been cancelled
Build Opik Docker Images / build-backend (push) Has been cancelled
Build Opik Docker Images / build-sandbox-executor-python (push) Has been cancelled
Build Opik Docker Images / build-python-backend (push) Has been cancelled
Build Opik Docker Images / build-frontend (push) Has been cancelled
Build Opik Docker Images / create-git-tag (push) Has been cancelled
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Has been cancelled
Docs - Publish / run (push) Has been cancelled
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Has been cancelled
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Has been cancelled
Frontend Unit Tests / Test on Node 20 (push) Has been cancelled
Guardrails E2E Tests / Select Python version matrix (push) Has been cancelled
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Guardrails E2E Tests / 📢 Slack Notification (push) Has been cancelled
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Has been cancelled
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Has been cancelled
Lint Opik Helm Chart / unittest-helm-chart (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:25:44 +08:00

126 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
headline: OpenTelemetry Ruby SDK | Opik Documentation
og:description: Configure OpenTelemetry SDK in your Ruby app to send telemetry data
to Opik efficiently and enhance your observability.
og:site_name: Opik Documentation
og:title: OpenTelemetry Ruby SDK Integration with Opik
title: OpenTelemetry Ruby SDK
canonical-url: https://www.comet.com/docs/opik/integrations/opentelemetry-ruby-sdk
---
## Integration with Opik
As of today, `Opik` does not provide a Ruby SDK. However, you can use the Opik OpenTelemetry integration to send telemetry data to Opik.
## Opik Configuration
You can configure your application to use OpenTelemetry SDK by setting up the following dependencies:
```ruby
# gemfile
# ... other gems
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'
```
Next, you need to set up the OpenTelemetry SDK and configure it to use the Opik as the traces backend.
```ruby
# opentelemetry_config.rb
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
module OpenTelemetryConfig
def self.configure
# This is the url for the Opik API endpoint for Otel traces
opik_endpoint = ENV.fetch('OPIK_OTEL_TRACES_ENDPOINT', 'https://www.comet.com/opik/api/v1/private/otel/v1/traces')
# Here you can set the Opik API key, project name and workspace name
# Set any default values but make sure to set them correctly in your environment variables
opik_api_key = ENV.fetch('OPIK_API_KEY', '<any-api-key-value>')
opik_project_name = ENV.fetch('OPIK_PROJECT_NAME', '<any-project-name-value>')
opik_workspace_name = ENV.fetch('OPIK_COMET_WORKSPACE', '<default-workspace>')
# This is very important, you need to set the headers for the Opik API calls to be able to authenticate against Opik
otlp_headers = {
'Authorization' => opik_api_key,
'projectName' => opik_project_name,
'Comet-Workspace' => opik_workspace_name
}
# Configure the exporter to use the Opik API endpoint and headers
ENV['OTEL_EXPORTER_OTLP_PROTOCOL'] = 'http/protobuf' # Use the OTLP HTTP/Protobuf protocol
ENV['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'] = opik_endpoint
ENV['OTEL_EXPORTER_OTLP_TRACES_HEADERS'] = otlp_headers.map { |k, v| "#{k}=#{v}" }.join(',')
OpenTelemetry::SDK.configure do |c|
c.service_name = opik_project_name
c.use_all # Enable automatic instrumentation for common libraries
end
end
end
OpenTelemetryConfig.configure
```
## Usage
Once configured, you can start using the OpenTelemetry SDK in your application. The following example demonstrates how to create a simple trace and span:
```ruby
# app.rb
require_relative './opentelemetry_config'
require 'net/http'
require 'uri'
require 'json'
TRACER = OpenTelemetry.tracer_provider.tracer('opik-tracer', '1.0.0')
uri = URI("https://jsonplaceholder.typicode.com/posts/1")
# Create a trace and spans via OpenTelemetry instrumentation
TRACER.in_span('JSONPlaceholder API Call', kind: :client, attributes: {
'http.url' => uri.to_s,
'http.method' => 'GET',
}) do |span|
# Your application logic ...
# For example, making an HTTP request to JSONPlaceholder
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request["Content-Type"] = "application/json"
response = http.request(request)
span.set_attribute('http.status_code', response.code.to_i)
puts "Response from JSONPlaceholder: #{response.body}"
span.set_attribute('output', response.body)
end
```
It's important to note that OpenTelemetry (otel) auto-instrumentations dont automatically align with Opiks schema, so you may need to manually set certain attributes, like the `output` attribute in the example above.
Opik supports mapping of attributes to Opik traces, for the following libraries:
- `python/OpenInference`
- `python/Pydantic`
- `python/GenAI`
In the future we may add more integrations to Opik. If you have any suggestions on what else could be integrated into Opik, please let us know!
<Tip>
If your application is a short-lived process, you may need to call `OpenTelemetry.tracer_provider.force_flush(timeout: <timeout>)` or similar method at the end of your application to ensure all telemetry data is flushed before exiting.
</Tip>
## Conclusion
This guide provided an overview of how to integrate Opik with the OpenTelemetry SDK in Ruby. By following the steps outlined above, you can easily set up your application to send telemetry data to Opik for monitoring and analysis.
Feel free to reach out to us if you have any questions or issues with the integration, via the [GitHub repository](https://github.com/comet-ml/opik/issues), or join our [Slack](https://chat.comet.com) channel.