# OpenTelemetry Collector

Replace `<REGION>` in the hosts and samples on this page with your workspace's region code: `us`, `ca`, `eu`, `uk` or `au`.

## Overview

The [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) is a cross-platform high-performance agent to receive, process, and forward telemetry data, written in golang.
The OpenTelemetry Collector receives data from various sources, optionally performs data transformations, and then ships data to destinations (like SparkLogs).

Over 80 data sources (called [receivers](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver)) are supported. Popular receivers for logs include
[Windows event logs](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/windowseventlogreceiver),
[files](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver), [journald](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/journaldreceiver),
[syslog](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/syslogreceiver), [Kubernetes](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/k8slogreceiver),
[Kafka](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/kafkareceiver), and [netflow](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/netflowreceiver).

SparkLogs receives collector traffic over its native [OTLP/HTTP API](https://sparklogs.com/docs/ingest/tools/otlp-http.md) using the contrib distribution's `otlphttp` exporter. Refer to the [OTLP/HTTP API](https://sparklogs.com/docs/ingest/tools/otlp-http.md) page for the wire protocol, encoding/compression options, resource-attribute mapping, and reliability features in depth, as this page focuses on the collector itself.

Although [AutoExtract](https://sparklogs.com/docs/ingest/autoextract.md) will automatically extract structured field data from your raw logs and is recommended in the
typical case, you can also manually parse log data within the collector into structured fields using [receiver operators](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/types/operators.md).
You can also enrich your data using [processors](https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor), including commonly used ones
like [resource detection](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor) (add information
about the host system like hostname) and [attributes](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/attributesprocessor) (add custom attributes to each shipped event).

## How to Use

Follow these steps for each [Ingest Key](https://sparklogs.com/docs/ingest.md) that will receive data from OpenTelemetry Collector:

### 1. Consider deployment design and topology

In its simplest form, OpenTelemetry Collector is deployed as an agent on each machine and will send data directly to SparkLogs.
SparkLogs is highly scalable and can receive data from distributed OpenTelemetry Collector agents without bottlenecks.

OpenTelemetry Collector can also be deployed to aggregate log data locally, and then ship this aggregated log data to SparkLogs.
If you have complex requirements, review the [OpenTelemetry Collector deployment guide](https://opentelemetry.io/docs/collector/deployment/),
and [collector overview](https://opentelemetry.io/docs/collector/).

### 2. Create an Ingest Key and get config template

In the [app](https://sparklogs.app), click the Configure sidebar button:

![Configure button in the sidebar](https://sparklogs.com/img/ux/sidebar-configure.png)

and then click the `Ingest Keys` tab.

As appropriate, create a new Ingest Key, or highlight an existing Ingest Key and click `View Ingest Key`.
In the dialog that shows the configuration template, click the `OpenTelemetry Collector` tab
and copy the configuration template (ships data via [OTLP/HTTP](https://sparklogs.com/docs/ingest/tools/otlp-http.md)).

### 3. Customize configuration

Copy the configuration template and customize it based on your needs. At a minimum,
add receivers in the YAML config and modify the exporter with your SparkLogs authentication credentials.

**Example OpenTelemetry Collector config.yaml**

This example ships Windows event logs. Customize the receivers as appropriate (e.g., files, journald, syslog).

Make sure to get your configuration template from the app, as your ingestion endpoint
can vary based on your provisioned region. This is an example of what it will look like:

```yaml
extensions:
  health_check:
    endpoint: 127.0.0.1:13133
  basicauth/sparklogs:
    client_auth:
      username: "<INGEST-KEY-ID>"
      password: "<INGEST-KEY-ACCESS-TOKEN>"

receivers:
  windowseventlog/application:
    channel: application
  windowseventlog/system:
    channel: system
  windowseventlog/security:
    channel: security

processors:
  # Add host system information to events (hostname, etc.)
  resourcedetection:
    detectors: [system]
    system:
      hostname_sources: ["os"]
  # Tune batch sizes for SparkLogs ingest
  batch:
    send_batch_size: 2000
    send_batch_max_size: 5000
    timeout: 5s

exporters:
  debug:
    verbosity: basic
  otlphttp/sparklogs:
    logs_endpoint: "https://ingest-<REGION>.engine.sparklogs.app/v1/logs"
    compression: zstd
    encoding: proto
    auth:
      authenticator: basicauth/sparklogs

service:
  extensions: [health_check, basicauth/sparklogs]
  pipelines:
    logs:
      receivers: [windowseventlog/application, windowseventlog/system, windowseventlog/security]
      processors: [resourcedetection, batch]
      exporters: [otlphttp/sparklogs]
  telemetry:
    metrics:
      level: detailed
      readers:
        - pull:
            exporter:
              prometheus:
                host: 127.0.0.1
                port: 8888
```

### 4. Deploy OpenTelemetry Collector agents

On each system that will ship data to SparkLogs for this Ingest Key,
install the OpenTelemetry Collector. We recommend using the
[contrib distribution](https://github.com/open-telemetry/opentelemetry-collector-releases/releases), which includes common receivers and exporters.
For example, there are MSI installer files for Windows and packages for various Linux distributions.

Once installed, customize the `config.yaml` file with your configuration and make sure the collector starts as a service on system boot
(the Windows MSI installer and Linux packages already do this for you). On Linux the config file is typically at `/etc/otelcol-contrib/config.yaml`
and on Windows it will be at `C:\Program Files\OpenTelemetry Collector Contrib\config.yaml`.

---

Source: <https://sparklogs.com/docs/ingest/tools/opentelemetry-collector>
All SparkLogs documentation in Markdown: <https://sparklogs.com/llms.txt>
