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

# MongoDB server logs with OpenTelemetry

> Collect self-hosted MongoDB server logs with the OpenTelemetry Collector and forward them to Bronto to investigate slow queries, connection errors, and replica set events.

Collect logs from a self-hosted MongoDB server — connections, slow queries, replication, and errors — with the OpenTelemetry Collector. The same Collector can also forward traces and metrics from your apps — see [Connect OpenTelemetry Collector to Bronto](/agent-setup/open-telemetry).

## Prerequisites

* A Bronto account and API key ([how to create one](/Account-Management/API-Keys#create-a-new-api-key))
* MongoDB writing logs to a file (`systemLog.destination: file`). The default path is `/var/log/mongodb/mongod.log`
* An [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/installation/) (recommended) or [Fluent Bit](https://docs.fluentbit.io/manual/installation/getting-started-with-fluent-bit) installed on the same host

## Configure the Collector

MongoDB 4.4+ writes one structured JSON object per line. Parse it with the `json_parser` operator:

```yaml /etc/otel/config.yaml theme={"dark"}
receivers:
  filelog/mongodb:
    include:
      - /var/log/mongodb/mongod.log
    operators:
      - type: json_parser
    resource:
      service.name: mongodb
      service.namespace: <YOUR_COLLECTION_NAME>

processors:
  batch:

exporters:
  otlphttp/brontologs:
    logs_endpoint: "https://ingestion.<REGION>.bronto.io/v1/logs"
    compression: gzip
    headers:
      x-bronto-api-key: <YOUR_API_KEY>

service:
  pipelines:
    logs:
      receivers: [filelog/mongodb]
      processors: [batch]
      exporters: [otlphttp/brontologs]
```

Set `<REGION>` to `eu` or `us`.

## What you will see in Bronto

Open [Search](https://app.bronto.io/search) and filter by `service.name = mongodb`. Each entry carries a timestamp (`t`), severity (`s`), component (`c` — e.g. `NETWORK`, `QUERY`, `REPL`), context (`ctx`), and message (`msg`); slow operations include the command, namespace, and `durationMillis` under `attr`. The `json_parser` promotes these to searchable fields.

## Troubleshooting

* **Older MongoDB (pre-4.4)** writes plain text, not JSON. Drop the `json_parser` operator and let Bronto's [Custom Parser](/core-features/custom-parser) extract fields server-side.
* **Log volume:** raising `systemLog.verbosity` greatly increases output — keep it low in production.
* For general issues, see [OTel Collector troubleshooting](https://opentelemetry.io/docs/collector/troubleshooting/).

## Alternative: Fluent Bit

If you already run Fluent Bit, tail the MongoDB log file and forward it over HTTP:

```ini fluent-bit.conf theme={"dark"}
[INPUT]
    name  tail
    path  /var/log/mongodb/mongod.log
    tag   mongodb

[OUTPUT]
    name        http
    match       mongodb
    host        ingestion.<REGION>.bronto.io
    port        443
    tls         on
    format      json_lines
    compress    gzip
    header      x-bronto-api-key    <YOUR_API_KEY>
    header      x-bronto-dataset    mongodb
    header      x-bronto-collection <YOUR_COLLECTION_NAME>
```

Set **Format** to `json_lines`, not `json`. See [Connect Fluent Bit to Bronto](/agent-setup/fluent-bit) for installation.
