# Logs

Source: https://docs.interop.io/manager/opentelemetry-support/logs/index.html

## Overview

The **io.Manager** Server can be configured to export [logs](https://opentelemetry.io/docs/concepts/signals/metrics/) via OpenTelemetry.

By default, the **io.Manager** Server supports exporting logs to an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/). It's also possible to provide your own [custom](#customization) log exporter and log processor pointing to a different backend service.

## Enabling Logs Exports

Publishing logs is disabled by default. To enable publishing logs, you must [enable OpenTelemetry support](https://docs.interop.io/manager/opentelemetry-support/overview/index.md#enabling_opentelemetry_support) in the **io.Manager** Server and explicitly enable the logs feature via the configuration object for initializing the **io.Manager** Server, or via environment variables, depending on your [deployment](https://docs.interop.io/manager/deployment/index.md) approach.

### Environment Variables

To enable and configure publishing logs, register the following environment variables with the proper values. The `API_OTEL_LOGS_ENABLED` environment variable must be set to `true`:

| Environment Variable | Description |
|----------------------|-------------|
| `API_OTEL_LOGS_ENABLED` | If `true`, will enable publishing OpenTelemetry logs. Defaults to `false`. |
| `API_OTEL_LOGS_MAX_LEVEL` | The maximum event level to emit via the OpenTelemetry SDK. Possible values are `ALL`, `MARK`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. Defaults to `FATAL`. |
| `API_OTEL_LOGS_MIN_LEVEL` | The minimum event level to emit via the OpenTelemetry SDK. Possible values are `ALL`, `MARK`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. Defaults to `INFO`. |
| `API_OTEL_LOGS_PUBLISH_INTERVAL` | Interval in milliseconds between two consecutive log exports. Passed to the [`BatchLogRecordProcessor`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk-logs.BatchLogRecordProcessor.html) constructor. This is the default log processor used by the **io.Manager** Server. Ignored when a [custom log processor](#customization-log_processor) is used. Defaults to `5000`. |
| `API_OTEL_LOGS_URL` | URL pointing to an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) where the generated logs will be sent via HTTP. Passed to the [`OTLPLogExporter`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_exporter-logs-otlp-http.OTLPLogExporter.html) constructor. This is the default log exporter used by the **io.Manager** Server. Required if using the default log exporter and log processor. Ignored when either a [custom log exporter](#customization-log_exporter) or a [custom log processor](#customization-log_processor) is used. |

The following example demonstrates how to [enable OpenTelemetry support](https://docs.interop.io/manager/opentelemetry-support/overview/index.md#enabling_opentelemetry_support), how to enable publishing logs, and how to configure the minimum log level and the interval for publishing logs:

```cmd
# Enabling OpenTelemetry support.
API_OTEL_ENABLED=true
API_OTEL_RESOURCE_SERVICE_NAME=io-manager

# Enabling and configuring logs.
API_OTEL_LOGS_ENABLED=true
API_OTEL_LOGS_URL=http://localhost:4318/v1/logs
API_OTEL_LOGS_MIN_LEVEL=WARN
API_OTEL_LOGS_PUBLISH_INTERVAL=10000
```

### Configuration Object

To enable publishing logs, use the `logs` property under the `otel` top-level key of the optional `Config` object for initializing the **io.Manager** Server.

The following example demonstrates how to [enable OpenTelemetry support](https://docs.interop.io/manager/opentelemetry-support/overview/index.md#enabling_opentelemetry_support), how to enable publishing logs, and how to configure the minimum log level and the interval for publishing logs:

```javascript
import { start } from "@interopio/manager";

const config = {
    // Enabling OpenTelemetry support.
    otel: {
        enabled: true,
    	resource: {
    	    serviceName: "io-manager"
    	},
        // Enabling and configuring logs.
    	logs: {
    	    enabled: true,
    	    url: "http://localhost:4318/v1/logs",
            minLevel: "WARN",
            publishInterval: 10000
    	}
    }
};

const server = await start(config);
```

The `logs` object has the following properties:

| Property | Type | Description |
|----------|------|-------------|
| `customExporter` | `object` | [`LogRecordExporter`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-logs.LogRecordExporter.html) instance of a [custom log exporter](#customization-log_exporter) to be used instead of the default log exporter. Ignored when a [custom log processor](#customization-log_processor) is used. |
| `customProcessor` | `object` | [`LogRecordProcessor`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-logs.LogRecordProcessor.html) instance of a [custom log processor](#customization-log_processor) to be used instead of the default log processor. |
| `enabled` | `boolean` | If `true`, will enable publishing OpenTelemetry logs. Defaults to `false`. |
| `maxLevel` | `"ALL"` \| `"MARK"` \| `"TRACE"` \| `"DEBUG"` \| `"INFO"` \| `"WARN"` \| `"ERROR"` \| `"FATAL"` \| `"OFF"` | The maximum event level to emit via the OpenTelemetry SDK. Defaults to `"FATAL"`. |
| `minLevel` | `"ALL"` \| `"MARK"` \| `"TRACE"` \| `"DEBUG"` \| `"INFO"` \| `"WARN"` \| `"ERROR"` \| `"FATAL"` \| `"OFF"` | The minimum event level to emit via the OpenTelemetry SDK. Defaults to `"INFO"`. |
| `publishInterval` | `number` | Interval in milliseconds between two consecutive log exports. Passed to the [`BatchLogRecordProcessor`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk-logs.BatchLogRecordProcessor.html) constructor. This is the default log processor used by the **io.Manager** Server. Ignored when a [custom log processor](#customization-log_processor) is used. Defaults to `5000`. |
| `url` | `string` | URL pointing to an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) where the generated logs will be sent via HTTP. Passed to the [`OTLPLogExporter`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_exporter-logs-otlp-http.OTLPLogExporter.html) constructor. This is the default log exporter used by the **io.Manager** Server. Required if using the default log exporter and log processor. Ignored when either a [custom log exporter](#customization-log_exporter) or a [custom log processor](#customization-log_processor) is used. |

## Customization

### Log Exporter

The **io.Manager** Server provides an out-of-the-box implementation of an [`OTLPLogExporter`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_exporter-logs-otlp-http.OTLPLogExporter.html) for sending logs to an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) via HTTP.

For more advanced scenarios, it's possible to provide an instance of a custom log exporter by using the `customExporter` property of the `logs` object in the [configuration object](#enabling_logs_exports-configuration_object) for initializing the **io.Manager** Server.

> ⚠️ *Note that it isn't possible to provide a custom log exporter via environment variables.*

> ℹ️ *For a complete example of creating a custom log exporter, see the [OpenTelemetry Custom Log Exporter](https://github.com/InteropIO/manager-examples/tree/main/otel-custom-logs-exporter) example on GitHub.*

### Log Processor

The **io.Manager** Server provides an out-of-the-box implementation of a [`BatchLogRecordProcessor`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk-logs.BatchLogRecordProcessor.html) for exporting logs periodically.

For more advanced scenarios, it's possible to provide an instance of a custom log processor by using the `customProcessor` property of the `logs` object in the [configuration object](#enabling_logs_exports-configuration_object) for initializing the **io.Manager** Server.

> ⚠️ *Note that it isn't possible to provide a custom log processor via environment variables.*

> ℹ️ *For a complete example of creating a custom log processor, see the [OpenTelemetry Custom Log Processor](https://github.com/InteropIO/manager-examples/tree/main/otel-custom-logs-processor) example on GitHub.*
