Instrumenting Vapor 4 with Swift OTel
In complex systems it's often a good thing to be able to figure out why the system is behaving in a certain way without having to look into the code. When we want to be able to have a more high level view of what happens in the application without opening up the black box, we're looking for observability. Observability is the concept of collecting information about a system's execution and internal state, based on the data it generates.
→ blog.vapor.codes/posts/otel-integration
The tutorial guides developers through instrumenting a Vapor 4 application with OpenTelemetry for metrics collection, visualised in Grafana, emphasising observability’s role in understanding system behaviour without code inspection.
Observability comprises logs for event details, metrics for instantaneous measurements like HTTP requests per second, and traces for data flow across components. The process uses Vapor’s built-in swift-metrics support to emit metrics, with swift-otel sending them to an OpenTelemetry Collector via OTLP, configured in configure.swift with a OTelLifecycleHandler.
A Docker Compose setup runs the Collector, exporting to Prometheus, with Grafana for visualisation, using a provided dashboard JSON. Deployment on AWS ECS Fargate involves a sidecar Collector, AWS Managed Prometheus for storage, and Managed Grafana for dashboards, ensuring scalable monitoring. This setup enables real-time performance insights, leveraging Swift’s ecosystem for robust server-side observability.
Category:
Tag:
Year: