Monoscope full color logo
Sign Up

OpenTelemetry Integration Guide

If your language or framework doesn’t have a native monoscope SDK, you can integrate directly using OpenTelemetry. Any language with an OpenTelemetry SDK — Rust, Ruby, Scala, C++, Swift, and many more — can send traces, metrics, and logs to monoscope.

Already using a language with a native SDK? Check our guides for Node.js, Python, Go, PHP, Java, .NET, or Elixir for richer integration features.


Prerequisites

Ensure you have completed the first three steps of the onboarding guide.

Configuration (Environment Variables)

The standard way to configure any OpenTelemetry SDK is through environment variables. Set these in your shell, .env file, Docker config, or deployment platform:

# Specifies the endpoint URL for the OpenTelemetry collector.
OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.monoscope.tech:4317"
# Specifies the name of the service.
OTEL_SERVICE_NAME="your-service-name"
# Adds your API KEY to the resource.
OTEL_RESOURCE_ATTRIBUTES="x-api-key=YOUR_API_KEY"
# Specifies the protocol to use for the OpenTelemetry exporter.
OTEL_EXPORTER_OTLP_PROTOCOL="grpc"

API key options: The legacy key at-project-key is also supported as a resource attribute. Alternatively, you can pass the API key as an OTLP header:
OTEL_EXPORTER_OTLP_HEADERS="x-api-key=YOUR_API_KEY"

Language Examples

Below are minimal examples for languages without a native monoscope SDK. Each example initializes OpenTelemetry and points it at monoscope.

Rust

Install dependencies in your Cargo.toml:

[dependencies]
opentelemetry = "0.24"
opentelemetry_sdk = { version = "0.24", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.17", features = ["grpc-tonic"] }
tracing = "0.1"
tracing-opentelemetry = "0.25"
tracing-subscriber = "0.3"

Check crates.io for the latest compatible versions. Initialize the tracer (reads OTEL_* env vars automatically):

use opentelemetry::global;
use opentelemetry_sdk::trace::SdkTracerProvider;
use opentelemetry_sdk::Resource;
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

fn init_tracer() {
    let exporter = opentelemetry_otlp::SpanExporter::builder()
        .with_tonic()
        .build()
        .expect("Failed to create OTLP exporter");

    let provider = SdkTracerProvider::builder()
        .with_batch_exporter(exporter)
        .with_resource(Resource::default())
        .build();

    global::set_tracer_provider(provider.clone());

    tracing_subscriber::registry()
        .with(OpenTelemetryLayer::new(provider.tracer("my-service")))
        .init();
}

#[tokio::main]
async fn main() {
    init_tracer();
    tracing::info!("Application started");
    global::shutdown_tracer_provider();
}

Ruby

Install the gems:

gem install opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all

Or add to your Gemfile:

gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'

Initialize OpenTelemetry (e.g., in a Rails initializer or at app startup):

require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'

# Reads OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME,
# OTEL_RESOURCE_ATTRIBUTES, and OTEL_EXPORTER_OTLP_PROTOCOL
# from environment variables automatically.
OpenTelemetry::SDK.configure do |c|
  c.use_all # Enables all available auto-instrumentation
end

Any Language

The general pattern works with any OpenTelemetry SDK:

  1. Install your language's OpenTelemetry SDK and OTLP exporter
  2. Set the four environment variables listed above
  3. Initialize the SDK — most SDKs auto-read OTEL_* env vars
  4. Run your application

Find your language's OpenTelemetry SDK at opentelemetry.io/docs/languages.

Languages with official OpenTelemetry SDKs include: C++, .NET, Erlang/Elixir, Go, Java, JavaScript, PHP, Python, Ruby, Rust, Swift, and more.

Using an OTel Collector as Proxy

If you prefer to run a local OpenTelemetry Collector — for example, to buffer telemetry, batch exports, or collect from multiple services — you can set one up as a proxy.

Collector Configuration

Create an otel-collector-config.yaml:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch:

exporters:
  otlp:
    endpoint: "otelcol.monoscope.tech:4317"
    tls:
      insecure: true
    headers:
      x-api-key: "YOUR_API_KEY"

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]

Docker Compose Setup

services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
    ports:
      - "4317:4317"
      - "4318:4318"

Then point your application’s OTEL_EXPORTER_OTLP_ENDPOINT to http://localhost:4317 instead of the monoscope endpoint directly. For a more comprehensive Docker-based collector setup with container metrics and log collection, see the Docker integration guide.

Feature Comparison: Native SDK vs Direct OpenTelemetry

Feature Native SDK Direct OTel
Traces, spans, metrics, logs Yes Yes
Request/response body capture Yes No
Automatic field redaction Yes No
Error reporting middleware Yes Manual
Endpoint detection Yes Yes

Native SDKs provide deeper integration features like automatic body capture and field redaction. Direct OpenTelemetry still gives you full observability for traces, metrics, and logs.


Verification

After configuring your application:

  1. Start your application with the OTEL_* environment variables set
  2. Send a few requests to your service
  3. Open the monoscope dashboard and check the API Log Explorer — your traces should appear within a few seconds

You can also use telemetrygen to verify your setup independently. See the Quick Test section in the onboarding guide.

Want a native SDK for your language? Send us an email and we'll prioritize based on demand.