Use a Receiver to Collect Logs
The OpenTelemetry Collector supports a large number of receivers that can be used to collect logs from a variety of sources.Setup
- Make sure you’re using the Collector Contrib distribution of the OpenTelemetry Collector, which contains contributions that are not part of the core repository and core distribution of the OpenTelemetry Collector.
-
Prepare your collector configuration file by adding the following boilerplate:
If you are sending OTLP logs from a service with a
service.namedefined, then the dataset for those logs will be the name of the service, and thex-honeycomb-datasetheader will not be used.
Collect any Log with the Filelog Receiver
The Filelog Receiver supports reading and parsing any arbitrary log written to a file on a server. The Filelog Receiver is the most flexible receiver, but depending on the shape of your logs, it may require additional configuration to parse your logs correctly. For example, here is a configuration that reads an NGINX access log and parses it into a structured log:Logs with Mixed Formats
Sometimes, logs have a mix of structured and unstructured information, such as an info log with JSON inside. To parse these, you need to parse each piece of the log into a specific element, and also know how to handle the structured information. For example, let’s say you have a log at/var/log/name-service/0.log that mixes text and JSON:
filelogreceiver configuration to do the following:
- Read the log from
/var/log/name-service/*.log. - Parse the full text of the log into a timestamp, severity, file name, message, and “details”.
- Parse the “details” text using a JSON parser, where each key in the JSON object is turned into an attribute for the log.
- Parse the service name from the file path.
- Sets the
service.nameresource with the parsed service name.
filelogreceiver configuration completes the required tasks:
Log Sources
You can configure many different receivers to collect logs from a specific source.AWS Cloudwatch
The AWS Cloudwatch Receiver supports autodiscovery of log groups and log streams in AWS Cloudwatch, with optional filtering of those sources. For example, here is a configuration that autodiscovers only EKS logs fromus-west-1: