OpenTelemetry Logs | Honeycomb

OpenTelemetry Logs

This guide details how to send OpenTelemetry Logs from OpenTelemetry SDKs to Honeycomb.

What are OpenTelemetry Logs? 

OpenTelemetry Logs are structured logs that wrap the bodies of existing logs and optionally correlate them with traces. For example, structured application logs from a logging framework in your application will be automatically correlated with any tracing you also add to that application. OpenTelemetry Logs also enable you to centrally process logs data along with traces and metrics within the OpenTelemetry Collector.

Send Logs from Your Application to Honeycomb 

You can send your structured application logs via OpenTelemetry to an endpoint, such as Honeycomb’s endpoint or the OpenTelemetry Collector. This option is especially useful if structured logging exists in your application, since it allows for automatic correlation of structured logs with traces later.

When you use an OpenTelemetry SDK to create OpenTelemetry Logs, you send to Honeycomb directly or an OpenTelemetry Collector configured to export to Honeycomb.

Note
Most OTLP Exporters for OpenTelemetry Logs are in the pre-release stage, but Java, Python, and .NET are supported. Refer to the status for each language.

Example: Send OpenTelemetry Logs from a .NET Application to Honeycomb 

This example configuration sends all logs created with an ILogger to Honeycomb, and uses .NET.

First, install the OTLP Logs exporter in your application:

dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs --prerelease

Then, create an ILogger exporter during application startup:

using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;

var appResourceBuilder = ResourceBuilder.CreateDefault()
    .AddService("your-service-name", "your-service-version");

using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(options =>
    {
        options.SetResourceBuilder(appResourceBuilder);
        options.AddOtlpExporter(option =>
        {
            option.Endpoint = new Uri("https://api.honeycomb.io");
            option.Headers = "x-honeycomb-team=YOUR_API_KEY";
        });
    });
});

var logger = loggerFactory.CreateLogger<Program>();

Then, run your application to create logs with ILogger. Logs will be sent to Honeycomb and located in the dataset that matches your configuration’s service name.

Example: Send OpenTelemetry Logs to an OpenTelemetry Collector 

It is generally a best practice to have applications send data to an OpenTelemetry Collector rather than Honeycomb directly, unless those applications are relatively small. By doing so, you can control API keys, data export concerns, and preprocessing of data in one place.

This configuration sends logs to a OpenTelemetry Collector and then to Honeycomb. Your SDK pipelines focus on sending logs to the Collector endpoint and the Honeycomb API key can be centrally managed at the Open Telemetry Collector level.

Note
This example OTLP exporter configuration is for .NET. As logging exporters become available for other languages, this page will be updated.

First, install the OTLP Logs exporter in your application:

dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs --prerelease

Then, create an ILogger exporter during application startup:

using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;

var appResourceBuilder = ResourceBuilder.CreateDefault()
    .AddService(serviceName: "your-service-name", serviceVersion: "0.1.0");

using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddOpenTelemetry(options =>
    {
        options.SetResourceBuilder(appResourceBuilder);
        options.AddOtlpExporter(option =>
        {
            // Default value is localhost:4317
            option.Endpoint = new Uri("YOUR_COLLECTOR_ENDPOINT");
        });
    });
});

var logger = loggerFactory.CreateLogger<Program>();

Then, configure your OpenTelemetry Collector to export to Honeycomb:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
processors:
  batch:
exporters:
  otlp/logs:
    endpoint: api.honeycomb.io:443
    headers:
      "x-honeycomb-team": YOUR_API_KEY
service:
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/logs]

Then, run your application and OpenTelemetry Collector. Logs will be sent to Honeycomb and located in the dataset that matches your configuration’s service name.