This project demonstrates how to implement OpenTelemetry logging in Go with a simple counter application that sends logs to an OpenTelemetry Collector.
- Go 1.23.5 or later
- Docker and Docker Compose
- OpenTelemetry Collector
The project consists of:
- A Go application that generates logs with a counter
- An OpenTelemetry Collector configuration
- Docker Compose setup for running the collector
-
Clone the repository:
git clone github.com/RichardBray/otel-log-sampling-go cd otel-log-sampling-go
-
Install dependencies:
go mod downloa
This configuration:
- Receives OTLP logs via gRPC (4317) and HTTP (4318)
- Processes logs in batches
- Exports logs to debug output for demonstration
-
Start the OpenTelemetry Collector:
docker-compose up
-
Run the Go application:
go run main.go
The application will:
- Initialize an OTLP HTTP log exporter
- Create a logger provider with batch processing
- Generate logs every second with an incrementing counter
The main application logic can be found in main.go
:
d
## Configuration
The OpenTelemetry Collector is configured in `otel-collector-config.yaml`:
This configuration:
- Receives OTLP logs via gRPC (4317) and HTTP (4318)
- Processes logs in batches
- Exports logs to debug output for demonstration
## Running the Application
1. Start the OpenTelemetry Collector:
```bash
docker-compose up
- Run the Go application:
go run main.go
The application will:
- Initialize an OTLP HTTP log exporter
- Create a logger provider with batch processing
- Generate logs every second with an incrementing counter