> ## Documentation Index
> Fetch the complete documentation index at: https://docs.honeycomb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Example: Send OpenTelemetry Logs with the OpenTelemetry Go SDK

> Configure the OpenTelemetry Go SDK to send structured logs from your Go application to Honeycomb or a Collector.

<Note>
  Logs support in the OpenTelemetry Go SDK is currently experimental and subject to change.
  To check the status for each language, refer to the [OpenTelemetry status page](https://opentelemetry.io/status/).
</Note>

This example shows how to configure the OpenTelemetry Go SDK with `slog` instrumentation to send logs from a Go application to Honeycomb or an OpenTelemetry Collector.

<Steps titleSize="h2">
  <Step title="Acquire Dependencies">
    Install the OpenTelemetry `otelconf` and `otelslog` bridge packages:

    ```shell theme={}
    go get \
      go.opentelemetry.io/contrib/otelconf \
      go.opentelemetry.io/contrib/bridges/otelslog
    ```
  </Step>

  <Step title="Configure the Logger Provider">
    During application setup, initialize the SDK from the config file and set the global logger provider:

    ```go theme={}
    package main

    import (
      "context"

      "go.opentelemetry.io/contrib/bridges/otelslog"
      "go.opentelemetry.io/contrib/otelconf"
      "go.opentelemetry.io/otel"
      "go.opentelemetry.io/otel/log/global"
    )

    func main() {
      // Set up the OpenTelemetry SDK from the config file
      sdk, err := otelconf.NewSDK()
      if err != nil {
        panic("failed to initialize OTel SDK")
      }
      defer sdk.Shutdown(context.Background())

      otel.SetTracerProvider(sdk.TracerProvider())
      otel.SetTextMapPropagator(sdk.Propagator())

      // Set the logger provider globally
      global.SetLoggerProvider(sdk.LoggerProvider())

      // Create a new slog logger instance
      logger := otelslog.NewLogger()

      // Use the logger directly anywhere in your app
      logger.Debug("Something interesting happened")
    }
    ```
  </Step>

  <Step title="Create a Config File">
    Create an `otelconfig.yaml` file to configure your exporter.

    To send logs to Honeycomb:

    ```yaml theme={}
    file_format: "1.0"

    resource:
      attributes:
        - name: service.name
          value: ${OTEL_SERVICE_NAME:-my-service}

    logger_provider:
      processors:
        - batch:
            exporter:
              otlp_http:
                endpoint: https://api.honeycomb.io
                headers:
                  - name: x-honeycomb-team
                    value: ${HONEYCOMB_API_KEY}
    ```

    To send logs to an OpenTelemetry Collector instead:

    ```yaml theme={}
    file_format: "1.0"

    resource:
      attributes:
        - name: service.name
          value: ${OTEL_SERVICE_NAME:-my-service}

    logger_provider:
      processors:
        - batch:
            exporter:
              otlp_grpc:
                endpoint: http://my-collector:4317
    ```
  </Step>

  <Step title="Run Your Application">
    Point the SDK at your configuration file using `OTEL_CONFIG_FILE`, then run your application:

    ```shell theme={}
    OTEL_CONFIG_FILE=./otelconfig.yaml go run app.go
    ```
  </Step>
</Steps>
