Deploying OTel Collector on Railway
OTel Collector is available as an official Docker image (opens in a new tab) on Docker Hub. We can use it as a base image and layer in our configuration before deploying it on Railway You find the resources for the Deployment here (opens in a new tab).
To set up the OTel Collector instance, utilize Railway's repository deployment and leverage Dockerfile features (opens in a new tab).
Create a file named
otel-collector-config.yaml to specify a receiver endpoint for sending metrics from the instrumented application
As the OTel Collector acts as a proxy, we can define an exporter to send metrics. In this example, metrics are pushed to Prometheus's remote write receiver (opens in a new tab). Note that while Prometheus advises against this method for efficient sample ingestion, it is chosen here because Autometrics relies on Prometheus for superior querying and visualization capabilities.
enabled: true # Convert resource attributes to
You can find the full otel-config.yaml here (opens in a new tab).
The below Dockerfile (opens in a new tab) uses the base Otel Collector image and loads our configuration
ADD otel-collector-config.yaml /etc/otelcol/config.yaml
Create a Railway service from our newly created GitHub repo, it should pick up the configuration from the Dockerfile.
In order to make the OTel Collector accessible to other services in your Railway project or externally (optional) - you need to tell Railway which port to listen on using the "magic" PORT environment variable.
To add it go to Service > Variables and add just the port number.
Utilize the 'push' capabilities in your chosen Autometrics language library, detailed in each language's quickstart section. When initializing the OTLP exporter, specify the endpoint for your deployed OTel Collector. Note that the OTel Collector expects metrics at /v1/metrics.
If you have deployed the OTel collector with the port set to 4318 your internal Railway endpoint should look something like this: