> ## 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 JavaScript SDK

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

<Note>
  Logs support in the OpenTelemetry JavaScript 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 JavaScript SDK to capture Bunyan logging calls and send logs from a JavaScript application to Honeycomb or an OpenTelemetry Collector.

<Steps titleSize="h2">
  <Step title="Acquire Dependencies">
    Install the OpenTelemetry Node.js SDK, Bunyan instrumentation, and Bunyan logging framework packages:

    ```shell theme={}
    npm install --save @opentelemetry/sdk-node \
        @opentelemetry/instrumentation-bunyan \
        bunyan
    ```
  </Step>

  <Step title="Configure the SDK">
    Create an initialization file (for example, `telemetry.js`) that sets up the SDK with Bunyan instrumentation.
    The exporter configuration is provided by the `otelconfig.yaml` file at runtime.

    ```js theme={}
    const { NodeSDK } = require('@opentelemetry/sdk-node');
    const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');

    const sdk = new NodeSDK({
      instrumentations: [
        new BunyanInstrumentation(),
      ]
    });
    // Start the SDK
    sdk.start();
    // Shut down the SDK gracefully before exiting to export all pending logs
    process.on('SIGTERM', () => {
        sdk
        .shutdown()
        .finally(() => process.exit(0));
    });
    ```

    Then, in your application, create and use Bunyan loggers to capture interesting things:

    ```javascript theme={}
    const bunyan = require('bunyan');

    // Create a logger and use it in your app
    const logger = bunyan.createLogger({name: 'myapp', level: 'info'});
    logger.info({'app.message':'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 node -r ./telemetry.js app.js
    ```
  </Step>
</Steps>

## Supported Logging Frameworks

The OpenTelemetry JavaScript SDK can automatically create logs from these supported logging frameworks:

* Bunyan
* Winston
