Ruby
Telemetry's HTTP API works with Ruby's standard library, so an additional client dependency is not required.
Send an event
require "json"
require "net/http"
require "uri"
api_key = ENV.fetch("TELEMETRY_API_KEY")
uri = URI("https://api.telemetry.sh/log")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = api_key
request["Content-Type"] = "application/json"
request.body = {
table: "api_requests",
data: {
route_template: "/api/projects/:id",
method: "GET",
status_code: 200,
latency_ms: 184
}
}.to_json
response = Net::HTTP.start(
uri.hostname,
uri.port,
use_ssl: true
) { |http| http.request(request) }
raise "Telemetry log failed: #{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
Telemetry adds timestamp_utc to the event. Keep API keys in server-side environment variables, and do not log credentials, auth headers, cookies, or raw private content.
Run a SQL query
Use a read-scoped key when the process only needs query access.
uri = URI("https://api.telemetry.sh/query")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = api_key
request["Content-Type"] = "application/json"
request.body = {
query: <<~SQL
SELECT
route_template,
COUNT(*) AS requests,
ROUND(AVG(latency_ms), 0) AS avg_latency_ms
FROM api_requests
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
GROUP BY route_template
ORDER BY requests DESC;
SQL
}.to_json
response = Net::HTTP.start(
uri.hostname,
uri.port,
use_ssl: true
) { |http| http.request(request) }
raise "Telemetry query failed: #{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
results = JSON.parse(response.body)
puts JSON.pretty_generate(results)
Production checklist
Set explicit open and read timeouts for long-running services, handle non-2xx responses without printing the API key, and retry only transient failures with backoff. Keep event names and field types stable as the table evolves. Exercise success, failure, retry, and timeout branches with synthetic events before creating an operational alert.
See the Log API, Query API, and SQL recipe library for more examples.