Docs
Install
Ruby on Rails

Ruby on Rails

This Guide Integrates:

✖️ Logs✖️ ️️Metrics✅ Traces

To send logs to HyperDX, please send logs using a platform integration (ex. Heroku or Kubernetes) or via the OpenTelemetry collector.

Getting Started

Install OpenTelemetry Packages

Use the following command to install the OpenTelemetry package.

bundle add opentelemetry-sdk opentelemetry-instrumentation-all opentelemetry-exporter-otlp

Configure OpenTelemetry + Logger Formatter

Next set up, you'll need to initialize the OpenTelemetry tracing instrumentation and configure the log message formatter for Rails logger so that logs can be tied back to traces automatically. Without the custom formatter, logs will not be automatically correlated together in HyperDX.

In config/initializers folder, create a file called hyperdx.rb and add the following to it:

# config/initializers/hyperdx.rb
 
require 'opentelemetry-exporter-otlp'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry/sdk'
 
OpenTelemetry::SDK.configure do |c|
  c.use_all() # enables all trace instrumentation!
end
 
Rails.application.configure do
  Rails.logger = Logger.new(STDOUT)
  # Rails.logger.log_level = Logger::INFO # default is DEBUG, but you might want INFO or above in production
  Rails.logger.formatter = proc do |severity, time, progname, msg|
    span_id = OpenTelemetry::Trace.current_span.context.hex_span_id
    trace_id = OpenTelemetry::Trace.current_span.context.hex_trace_id
    if defined? OpenTelemetry::Trace.current_span.name
      operation = OpenTelemetry::Trace.current_span.name
    else
      operation = 'undefined'
    end
 
    { "time" => time, "level" => severity, "message" => msg, "trace_id" => trace_id, "span_id" => span_id,
      "operation" => operation }.to_json + "\n"
  end
 
  Rails.logger.info "Logger initialized !! 🐱"
end

Configure Environment Variables

Afterwards you'll need to configure the following environment variables in your shell to ship telemetry to HyperDX:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://in-otel.hyperdx.io \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
OTEL_SERVICE_NAME='<NAME_OF_YOUR_APP_OR_SERVICE>' \
OTEL_EXPORTER_OTLP_HEADERS='authorization=<YOUR_HYPERDX_API_KEY_HERE>'

The OTEL_SERVICE_NAME environment variable is used to identify your service in the HyperDX app, it can be any name you want.

The OTEL_EXPORTER_OTLP_HEADERS environment variable is used to link your telemetry to your HyperDX account, and the API Key can be grabbed from the team page (opens in a new tab)

Hi, how can I help you?