Mix tasks for installing and invoking otelcol-contrib as a sidecar process to an Elixir application. Benefits:
* mTLS between collector and upstream
* local scrape of prometheus metrics
* capture logs for sending over OTLP
Copied from tailwind, with the intent of easily running an OpenTelemetry Collector next to the server, in development. It uses the contrib version to have as many options for export as possible.
Otelcol is intended as a development-only tool. Make sure to specify only: :dev in your mix.exs:
def deps do
[
{:otelcol, "~> 0.1", only: :dev}
]
endOnce installed, change your config/config.exs to pick your
otelcol version of choice:
config :otelcol, version: "0.110.0"Now you can install otelcol-contrib by running:
$ mix otelcol.installAnd invoke otelcol with:
$ mix otelcol defaultThe executable is kept at _build/otelcol-contrib.
The first argument to otelcol is the execution profile.
You can define multiple execution profiles with the current
directory, the OS environment, and default arguments to the
otelcol task:
config :otelcol,
version: "0.110.0",
default: [
args: ~w(
--config=config/otelcol-collector.yml
)
]When mix otelcol default is invoked, the task arguments will be appended
to the ones configured above. Note profiles must be configured in your
config/config.exs, as otelcol runs without starting your application
(and therefore it won't pick settings in config/runtime.exs).
To add otelcol to an application using Phoenix, you need one more step.
Installation requires that Phoenix watchers can accept module-function-args
tuples which is not built into Phoenix 1.5.9.
For development, we want to use "watch" mode, even though we're not really
watching any files. So find the watchers configuration in your
config/dev.exs and add:
otelcol: {Otelcol, :install_and_run, [:default, []]}The first time this package is installed, a default otelcol configuration
will be placed in a new config/otel-collector.yml file. See
the otelcol documentation
on configuration options.
Copyright (c) 2024 Kenichi Nakamura. copied/modded from https://github.com/phoenixframework/tailwind Copyright (c) 2021 Wojtek Mach, José Valim.
otelcol source code is licensed under the MIT License.