Collecting and visualizing OpenTelemetry logs with Elasticsearch and Kibana
Application logs are more useful when we can search them across services and see how their volume changes over time. OpenTelemetry gives us a common way to send those logs without making the application depend on a particular storage backend.
This post uses a small Go application, the OpenTelemetry Collector, Elasticsearch, and Kibana to build a local logging pipeline. OpenTelemetry also supports metrics and traces, but this example exports logs only.
Four components, one pipeline
Go application → OpenTelemetry Collector → Elasticsearch
↑
Kibana
Each component has a separate responsibility:
- Application: creates structured log records and sends them using the OpenTelemetry Protocol (OTLP).
- Collector: receives those records, batches them, and forwards them to Elasticsearch.
- Elasticsearch: stores and indexes the logs.
- Kibana: queries Elasticsearch so we can explore the logs and build visualizations.
Kibana is not part of the ingestion path. The application does not send logs to it.
The Collector also separates application instrumentation from backend configuration. To send the same logs somewhere else, like OpenSearch or Loki, we can just add them to the Collector’s exporters without changing the application’s logging calls.
Sending logs from the application
We need a current Go release and Docker with Compose support. The application will run on the host, while the Collector, Elasticsearch, and Kibana run in containers.
Create a working directory and initialize a Go module:
mkdir otel-logging
cd otel-logging
go mod init example.com/otel-logging
go get go.opentelemetry.io/contrib/bridges/otelslog \
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp \
go.opentelemetry.io/otel/sdk/log \
go.opentelemetry.io/otel/sdk/resource
Use a current Go release supported by these packages. Keep the generated go.mod and go.sum to record the dependency versions.
Create main.go:
package main
import (
"context"
"log"
"log/slog"
"math/rand/v2"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
sdklog "go.opentelemetry.io/otel/sdk/log"
"go.opentelemetry.io/otel/sdk/resource"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
exporter, err := otlploghttp.New(ctx)
if err != nil {
log.Fatal(err)
}
provider := sdklog.NewLoggerProvider(
sdklog.WithResource(resource.NewWithAttributes("",
attribute.String("service.name", "test-app"),
)),
sdklog.WithProcessor(sdklog.NewBatchProcessor(exporter)),
)
logger := slog.New(otelslog.NewHandler("test-app",
otelslog.WithLoggerProvider(provider),
))
mux := http.NewServeMux()
mux.HandleFunc("GET /api", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger.InfoContext(ctx, "Handling request")
n := rand.IntN(10)
if n <= 1 {
logger.ErrorContext(ctx, "Simulated error")
http.Error(w, "Simulated error", http.StatusInternalServerError)
return
}
if n == 2 {
logger.WarnContext(ctx, "Simulated warning")
}
logger.InfoContext(ctx, "Request handled")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"status":"ok"}`))
})
server := &http.Server{Addr: "127.0.0.1:8080", Handler: mux, ReadHeaderTimeout: 5 * time.Second}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Print(err)
stop()
}
}()
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = server.Shutdown(shutdownCtx)
if err := provider.Shutdown(shutdownCtx); err != nil {
log.Print(err)
}
}
The otelslog bridge connects Go’s structured logger to the OpenTelemetry log provider. The provider batches records and sends them through the OTLP HTTP exporter. Setting environment variables alone would not instrument an arbitrary Go application; this wiring is necessary.
The random branch produces errors for about 20% of requests and warnings for about 10%. A small sample will not necessarily match those proportions. This gives us different log severities to explore without needing a real application failure.
Configuring the Collector
In the same directory, create collector/config.yaml with the following contents:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_mib: 192
spike_limit_mib: 48
batch:
send_batch_size: 200
send_batch_max_size: 200
timeout: 1s
exporters:
otlp_http/elasticsearch:
endpoint: http://elasticsearch:9200/_otlp
service:
pipelines:
logs:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp_http/elasticsearch]
There are three stages:
- The receiver accepts OTLP records from the application.
- The processors limit memory pressure and group records into batches.
- The exporter sends the batches to Elasticsearch’s native OTLP endpoint.
Declaring a component is not enough to enable it. The service.pipelines.logs section connects the components into a working pipeline, in the order shown.
The exporter uses http://elasticsearch:9200/_otlp as its base endpoint and appends /v1/logs for logs. This is direct OTLP ingestion into Elasticsearch; it does not require an APM Server or a separate Elasticsearch exporter. It does require an Elasticsearch version that supports this endpoint.
The memory limiter can refuse incoming data under pressure; it is not a durable queue. Likewise, batching reduces export overhead but does not guarantee delivery.
Starting the stack
Create compose.yaml alongside main.go:
services:
collector:
image: otel/opentelemetry-collector-contrib
command: ["--config=/etc/otel-collector-config.yaml"]
ports:
- "127.0.0.1:4318:4318"
volumes:
- ./collector/config.yaml:/etc/otel-collector-config.yaml:ro
elasticsearch:
image: elasticsearch:9.5.5
ports:
- "127.0.0.1:9200:9200"
environment:
discovery.type: single-node
xpack.security.enabled: "false"
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
kibana:
image: kibana:9.5.5
ports:
- "127.0.0.1:5601:5601"
environment:
ELASTICSEARCH_HOSTS: '["http://elasticsearch:9200"]'
depends_on:
- elasticsearch
Start the containers:
docker compose up
This adds a single-node Elasticsearch instance and Kibana, both using image tag 9.5.5. Elasticsearch gets a 512 MiB JVM heap.
The relevant host endpoints are:
| Component | URL |
|---|---|
| Application | http://localhost:8080 |
| Elasticsearch | http://localhost:9200 |
| Kibana | http://localhost:5601 |
Wait for Elasticsearch and Kibana to finish starting before generating traffic. Compose’s depends_on controls startup order here, not application readiness. We can inspect the service output if something fails to start:
docker compose logs collector elasticsearch kibana
This is a local experiment, not a production deployment. Elasticsearch security is disabled and traffic uses HTTP. The published ports bind to loopback, but this is not a substitute for authentication and TLS in a shared environment. The Collector image is unpinned; pin a tested version for reproducible use.
Once the backend is ready, start the application in another terminal from the same directory:
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 go run .
The application runs on the host, so it reaches the Collector through the published port on localhost. The Collector uses elasticsearch, the Compose service name, to reach Elasticsearch inside the container network. If the application also ran in Compose, its endpoint would instead be http://collector:4318.
The HTTP exporter appends /v1/logs to the application endpoint. Port 4318 is the Collector’s OTLP HTTP listener; port 4317 is its OTLP gRPC listener, which this Compose file does not publish.
Generating and finding logs
In another terminal, send some requests:
for i in {1..100}; do
curl -sS http://localhost:8080/api > /dev/null
done
Some requests return HTTP 500 because of the simulated error branch. That is expected. Allow a few seconds for application export, Collector batching, and Elasticsearch refresh before looking for the records.
Open Kibana, then:
- Go to Management → Stack Management → Data → Index Management.
- Enable Include hidden indices.
- Search for
logs-generic.otel. - Open the matching index and select Open in Discover.
The default log data stream is logs-generic.otel-default; its backing indices are hidden. Searching for logs-generic.otel helps find them without needing the generated backing-index name.
If Discover asks for a data view, create one with the pattern logs-generic.otel-* and select @timestamp as the time field. Set the time range to include the requests, such as Last 15 minutes, and refresh.
Expand a record to inspect its message, severity, and resource attributes. Use the fields shown in the document to add useful columns or filters. The indexed record uses the backend’s OTLP field mapping, so inspect its fields rather than assuming names from a console logger.
We should see messages such as Handling request, Simulated error, and Request handled. Filter on the severity field of an error record to isolate the simulated failures.
If no records appear, first check the time range, then the application and Collector output for export errors. A successful HTTP response from the application does not prove that OTLP export or ingestion succeeded.
Stopping the experiment
Stop the application with Ctrl+C, which shuts down the server and flushes pending log records. Then stop and remove the containers:
docker compose down
The example does not configure a persistent Elasticsearch data volume. Treat the indexed logs and saved Kibana objects as disposable when removing the containers.
The useful separation is simple: the application produces OpenTelemetry records, the Collector controls processing and where they go, and Elasticsearch and Kibana provide storage and exploration. That gives us a small local setup for understanding the logging pipeline before adding authentication, persistent storage, and operational controls.