# Ubuntu

> This document describes a sample setup for sending logs to Last9 via OpenTelemetry collector from Ubuntu instance

Source: https://last9.io/docs/integrations/observability/ubuntu/

## Installing OpenTelenetry collector on Ubuntu instance

Use Last9's OpenTelemetry endpoint to ingest logs from Ubuntu instances using Otel Collector.

## Prerequisites:

There are multiple ways to install the Otel Collector. One possible way is to use the package. Every Collector release includes APK, DEB, and RPM packaging for Linux amd64/arm64/i386 systems.

```bash
sudo apt-get update
sudo apt-get -y install wget systemctl
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.110.0/otelcol-contrib_0.110.0_linux_amd64.deb
sudo dpkg -i otelcol-contrib_0.110.0_linux_amd64.deb
```

More installation options can be found [here](https://opentelemetry.io/docs/collector/installation/).

## Sample Otel collector Configuration:

The default path for otel config is `/etc/otelcol-contrib/config.yaml`.

You can edit it and update it using the configuration below. The configuration for operators is essential to extract the timestamp and severity.

For JSON logs, you can use `json_parser` and use its keys for log attributes. For non-structured logs, use the `regex_parser`.

The configuration provides a sample example of a JSON parser.

```yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

  # Detailed configuration options can be found at https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver
  filelog:
    # File path to read logs from. You can add multiple files here.
    include: [/var/log/app/*.log]
    include_file_path: true
    operators:
      - type: json_parser
      - type: severity_parser
        parse_from: attributes.level
        mapping:
          critical: 50
          error: 40
          warning: 30
          info: 20
          debug: 10

processors:
  transform/add_timestamp:
    log_statements:
      - context: log
        statements:
          - set(observed_time, Now())
          - set(time, Now())
  attributes:
    actions:
      - key: test.name
        value: "jammytest"
        action: insert
      - key: deployment.environment
        value: "production"
        action: insert
      - key: otel.processed
        value: true
        action: insert
  batch:
    timeout: 1s
    send_batch_size: 1024

exporters:
  debug:
    verbosity: detailed
  otlp/last9:
    endpoint: <last9_otlp_endpoint>
    headers:
      "Authorization": <last9_auth_header>

service:
  pipelines:
    logs:
      receivers: [filelog]
      processors: [attributes, batch, transform/add_timestamp]
      exporters: [debug, otlp/last9]
```

## Run the otel collector using `systemctl` command

```bash
sudo systemctl start otelcol-contrib
sudo systemctl status otelcol-contrib
sudo systemctl restart otelcol-contrib
```

## Checking logs of otel collector

```bash
sudo journalctl -u otelcol-contrib -f
```

This will enable logs from the Ubuntu machine to be sent to Last9. To see the data in action, visit the [Logs Dashboard](https://app.last9.io/logs).

## Verification

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

![Logs in Last9](../../../../../../assets/content/docs/integrations/observability/opentelemetry/ubuntu/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.
