# Fluent Bit

> This document describes a sample setup for sending logs to Last9 via Fluent bit

Source: https://last9.io/docs/integrations/observability/fluent-bit/

[Fluent Bit](https://docs.fluentbit.io/manual) is a fast and lightweight telemetry agent for logs, metrics, and traces. This document provides step by step instructions
to send logs from Fluent Bit to Last9.

## Prerequisites

1. Create a Last9 cluster by following [Getting Started](/docs/onboard/) guide.
2. Keep the following information handy after creating the cluster from the [Integrations](https://app.last9.io/integrations?integration=OpenTelemetry) page:
   - `$last9_otlp_endpoint`: Last9's OTLP endpoint
   - `$last9_basic_auth_header`: OpenTelemetry Basic authorization header
   - `$last9_username`: OpenTelemetry username
   - `$last9_password`: OpenTelemetry password

## Fluent Bit Configuration

Fluent bit supports shipping logs to Last9 using the `opentelemetry` output plugin.

Add following output stanza in the Fluent Bit configuration file.

```
    [OUTPUT]
        Name                 opentelemetry
        Match                kube.*
        Host                 otlp.last9.io
        http_user            <last9_username>
        http_passwd          <last9_password>
        Port                 443
        Logs_uri             /v1/logs
        Tls                  On
        Tls.verify           On
        logs_body_key_attributes true
```

Read more on the configuration options provided by the `opentelemetry` plugin [here](https://docs.fluentbit.io/manual/pipeline/outputs/opentelemetry).

:::note
Please note that the `Match` field must match the value of Match field in the `Input` or `Filter` sections in the Fluent Bit configuration.
:::

This is the bare minimum configuration that you can add in the Fluent Bit config to start sending logs to Last9.

## Advanced Configuration

You can add advanced lua functions to parse the logs before sending to Last9.

```lua
    function set_fields(tag, timestamp, record)
      local new_record = {}

      local function flatten_table(prefix, t)
        for k, v in pairs(t) do
            if type(v) == "table" then
                flatten_table(prefix .. k .. ".", v)
            else
                new_record[prefix .. k] = v
            end
        end
      end
      flatten_table("", record)

      return 1, timestamp, new_record
    end
```

As an example, above lua function flattens the nested maps present in logs.

Additionally, it is highly recommended to add a unique tag to the log records per cluster or environment. It can be done by adding a modify Filter.

```
    [FILTER]
        Name modify
        Match kube.*
        Add env production
```

Read more on Fluent bit modify filter [here](https://docs.fluentbit.io/manual/pipeline/filters/modify).

## Verification

Login to Last9 and visit the [Logs](https://app.last9.io/logs) panel.

![Logs in Last9 via Fluent Bit](../../../../../../assets/content/docs/integrations/observability/logs/fluent-bit/levitate-logs.jpg)

---

## Troubleshooting

Please get in touch with us on [Discord](https://discord.com/invite/Q3p2EEucx9) or [Email](mailto:support@last9.io) if you have any questions.
