We use cookies or similar technologies to personalize your online experience & tailor marketing to you. Many of our product features require cookies to function properly.

Read our privacy policy I accept cookies from this site

Instrumenting with OpenTelemetry

Quickstart Instructions  🔗

Follow these instructions to set up the Honeycomb OpenTelemetry Exporter for Go and automatically create traces/spans on HTTP requests in your Go application.

1. Choose the mux that’s right for your framework  🔗

Add a line to your import() stanza depending upon your request router:

  • If you are using gin/gonic:

    middleware "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin"
    
  • If you are using gorillamux:

    middleware "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
    
  • If you are using echo:

    middleware "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo"
    

2. Inject OpenTelemetry middleware  🔗

In your main() function, right after you create your primary router, inject the OpenTelemetry middleware:

router.Use(middleware.Middleware("service-name"))

At this point you can build and run your app and hit an HTTP endpoint to ensure that traces are being generated. You should see trace data in your terminal output.

3. Configure exporter to send to Honeycomb  🔗

Now you’ll be adding an additional package: the Honeycomb Exporter for Go.

Import the Honeycomb exporter in your main module:

import (
    "log" // optional
    "go.opentelemetry.io/otel/api/global"
    "github.com/honeycombio/opentelemetry-exporter-go/honeycomb"
    "go.opentelemetry.io/otel/api/global"
    sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

Configure the exporter to send to Honeycomb and initialize the OpenTelemetry tracer. This example handles both in a separate initTracer() function:

func initTracer() func() {
  // Get this via https://ui.honeycomb.io/account after signing up for Honeycomb
  apikey, _ := os.LookupEnv("HONEYCOMB_API_KEY")
  dataset, _ := os.LookupEnv("HONEYCOMB_DATASET")
  hny, err := honeycomb.NewExporter(
    honeycomb.Config{
      APIKey: apikey
    },
    honeycomb.TargetingDataset(dataset),
    honeycomb.WithServiceName("myapp"), // replace with your app's name
  )
  if err != nil {
    log.Fatal(err)
  }
  tp, err := sdktrace.NewTracerProvider(
    sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
    sdktrace.WithSyncer(hny),
  )
  if err != nil {
    log.Fatal(err)
  }
  global.SetTraceProvider(tp)
  return hny.Close
}

Then place the initialization code first in your main() function:

func main() {
  cleanup := initTracer()
  defer cleanup()
  // your own initialization code...
}

Follow these instructions to set up the Honeycomb OpenTelemetry Exporter for Python.

Install  🔗

pip install opentelemetry-ext-honeycomb

Initialize  🔗

from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.ext.honeycomb import HoneycombSpanExporter

exporter = HoneycombSpanExporter(
	service_name='myapp', # replace with your app's name
  # Get this via https://ui.honeycomb.io/account after signing up for Honeycomb
	writekey=OS.environ['HONEYCOMB_API_KEY'],
	dataset=OS.environ['HONEYCOMB_DATASET'],
)
span_processor = BatchExportSpanProcessor(exporter)
tracer.add_span_processor(span_processor)

And then activate the appropriate virtualenv.

Follow these instructions to set up the OpenTelemetry Honeycomb Exporter for .NET.

Install the required packages:

dotnet add package OpenTelemetry --version 0.2.0-alpha.179
dotnet add package OpenTelemetry.Collector.AspNetCore --version 0.2.0-alpha.179
dotnet add package OpenTelemetry.Collector.Dependencies --version 0.2.0-alpha.179
dotnet add package OpenTelemetry.Hosting --version 0.2.0-alpha.179
dotnet add package Honeycomb
dotnet add package Newtonsoft.Json
dotnet add package Honeycomb.OpenTelemetry --version 0.9.0-pre

Add the following to your Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    ...
    // Honeycomb Setup
    services.Configure<HoneycombApiSettings>(Configuration.GetSection("HoneycombSettings"));
    services.AddHttpClient("honeycomb");
    services.AddSingleton<IHoneycombService, HoneycombService>();
    services.AddSingleton<HoneycombExporter>();

    // OpenTelemetry Setup
    services.AddOpenTelemetry((sp, builder) => {
        builder.UseHoneycomb(sp)
            .AddRequestCollector()
            .AddDependencyCollector();
    });
    ...
}

Add the following to your appsettings.Development.json:

{
  ...
  "HoneycombSettings": {
    "TeamId": "HONEYCOMB_API_KEY", // Get this via https://ui.honeycomb.io/account after signing up for Honeycomb
    "DefaultDataSet": "my-dataset", // Required
    "BatchSize": 100,
    "SendFrequency": 10000
  }
  ...
}

Follow these instructions to set up the OpenTelemetry Honeycomb Exporter for Java.

Installation  🔗

Maven

<dependency>
    <groupId>io.honeycomb.opentelemetry</groupId>
    <artifactId>honeycomb-opentelemetry-exporters</artifactId>
    <version>0.1.0</version>
</dependency>

Gradle

dependencies {
    compile group: 'io.honeycomb.opentelemetry', name: 'honeycomb-opentelemetry-exporters', version: '0.1.0'
}

Configuration  🔗

You will need to name your service and provide your Honeycomb API Key. You can optionally set a dataset which is strongly recommended.

// Create span exporter
HoneycombSpanExporter exporter = HoneycombSpanExporter.newBuilder("my-app")
    .writeKey("my-api-key") // Get this via https://ui.honeycomb.io/account after signing up for Honeycomb
    .dataSet("my-dataset") // Required
    .build();

// Set span processor in OpenTelemetrySdk provider using the exporter
OpenTelemetrySdk.getTracerManagement().addSpanProcessor(
    SimpleSpanProcessor.newBuilder(exporter).build()
);

Choose the API and SDK for your language, or search the OpenTelemetry Registry.

Follow the instructions to install the required packages.

Set up the Honeycomb Collector-Exporter  🔗

Once you’ve added the API and SDK packages, you’ll need to set up the language-agnostic Honeycomb Collector-Exporter.

Docker image  🔗

Get the latest version of the otel/opentelemetry-collector-contrib Docker image:

docker pull otel/opentelemetry-collector-contrib

Create a configuration file called otel-local-config.yaml according to the instructions below. Then run the following Docker command:

docker run --rm -p 13133:13133 -p 14250:14250 -p 14268:14268 \
      -p 55678-55680:55678-55680 -p 6060:6060 -p 7276:7276 -p 8888:8888 \
      -p 9411:9411 -p 9943:9943 \
      -v "${PWD}/otel-local-config.yaml":/otel-local-config.yaml \
      --name otelcol otel/opentelemetry-collector-contrib \
      --config otel-local-config.yaml

RPM, Debian, and other Packages  🔗

Visit GitHub to get the latest release of the OpenTelemetry Collector Contrib package.

Configure the Honeycomb Collector-Exporter  🔗

Add the following configuration to your otel-local-config.yaml file:

receivers:
  otlp:
    protocols:
      grpc:
      http:

processors:
  batch:

exporters:
  honeycomb:
    api_key: <HONEYCOMB_API_KEY>
    dataset: <HONEYCOMB_DATASET>
  otlp:
    endpoint: otelcol:55680

extensions:
  health_check:
  pprof:
  zpages:

service:
  extensions: [health_check,pprof,zpages]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp, honeycomb]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]

Now you can start the collector.

From here you can build and run your application. Hit an HTTP endpoint and you’ll see data arrive in Honeycomb in seconds!

Go to the Honeycomb UI

Resources  🔗