Skip to content

Commit

Permalink
feat: OTEL support for cowboy server (#2074)
Browse files Browse the repository at this point in the history
* feat: OTEL support for cowboy server

* chore: formatting

* feat: update docs, add env vars

* docs: add linmk to :opentelemetry_exporter docs

* chore: formatting

* docs: refine LOGFLARE_OTEL_ENDPOINT docs
  • Loading branch information
Ziinc authored Jun 5, 2024
1 parent 736a3d0 commit dddc164
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
4 changes: 4 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ config :grpc, start_server: true

config :logflare, Logflare.AlertsScheduler, init_task: {Logflare.Alerting, :init_alert_jobs, []}

config :opentelemetry,
span_processor: :batch,
traces_exporter: :otlp

import_config "#{Mix.env()}.exs"
11 changes: 11 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,14 @@ postgres_topology = [
config :libcluster,
topologies:
if(System.get_env("LIBCLUSTER_TOPOLOGY") == "postgres", do: postgres_topology, else: [])

if System.get_env("LOGFLARE_OTEL_ENDPOINT") do
config :opentelemetry_exporter,
otlp_protocol: :grpc,
otlp_endpoint: System.get_env("LOGFLARE_OTEL_ENDPOINT"),
otlp_compression: :gzip,
otlp_headers: [
{"x-source-id", System.get_env("LOGFLARE_OTEL_SOURCE_UUID")},
{"x-api-key", System.get_env("LOGFLARE_OTEL_ACCESS_TOKEN")}
]
end
7 changes: 6 additions & 1 deletion docs/docs.logflare.com/docs/self-hosting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ All browser authentication will be disabled when in single-tenant mode.
| `LOGFLARE_PUBSUB_POOL_SIZE` | Integer, defaults to `10` | Sets the number of `Phoenix.PubSub.PG2` partitions to be created. Should be configured to the number of cores of your server for optimal multi-node performance. |
| `LOGFLARE_ALERTS_ENABLED` | Boolean, defaults to `true` | Flag for enabling and disabling query alerts. |
| `LOGFLARE_ALERTS_MIN_CLUSTER_SIZE` | Integer, defaults to `1` | Sets the required cluster size for Query Alerts to be run. If cluster size is below the provided value, query alerts will not run. |
| `LOGFLARE_MIN_CLUSTER_SIZE` | Integer, defaults to `1` | Sets the target cluster size, and emits a warning log periodically if the cluster is below the set number of nodes.. |
| `LOGFLARE_MIN_CLUSTER_SIZE` | Integer, defaults to `1` | Sets the target cluster size, and emits a warning log periodically if the cluster is below the set number of nodes.. |
| `LOGFLARE_OTEL_ENDPOINT` | String, defaults to `nil` | Sets the OpenTelemetry Endpoint to send traces to via gRPC. Port number can be included, such as `https://logflare.app:443` |
| `LOGFLARE_OTEL_SOURCE_UUID` | String, defaults to `nil`, optionally required for OpenTelemetry. | Sets the appropriate header for ingesting OpenTelemetry events into a Logflare source. |
| `LOGFLARE_OTEL_ACCESS_TOKEN` | String, defaults to `nil`, optionally required for OpenTelemetry. | Sets the appropriate authentication header for ingesting OpenTelemetry events into a Logflare source. |

Additional environment variable configurations for the OpenTelemetry libraries used can be found [here](https://hexdocs.pm/opentelemetry_exporter/readme.html).perf/bq-pipeline-sharding

### BigQuery Backend Configuration

Expand Down
3 changes: 3 additions & 0 deletions lib/logflare/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ defmodule Logflare.Application do

children = get_children(env)

:opentelemetry_cowboy.setup()
OpentelemetryPhoenix.setup(adapter: :cowboy2)

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Logflare.Supervisor]
Expand Down
22 changes: 17 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ defmodule Logflare.Mixfile do
logflare: [
version: version(),
include_executables_for: [:unix],
applications: [runtime_tools: :permanent, ssl: :permanent]
applications: [
runtime_tools: :permanent,
ssl: :permanent,
opentelemetry_exporter: :permanent,
opentelemetry: :temporary
]
]
]
]
Expand Down Expand Up @@ -147,9 +152,9 @@ defmodule Logflare.Mixfile do
{:typed_ecto_schema, "~> 0.1.0", runtime: false},

# Telemetry & logging
{:telemetry, "~> 0.4.0"},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 0.5"},
{:telemetry, "~> 1.0"},
{:telemetry_metrics, "~> 1.0"},
{:telemetry_poller, "~> 1.1"},
{:logflare_logger_backend, "~> 0.11.4"},
{:logger_json, "~> 5.1"},

Expand Down Expand Up @@ -206,7 +211,14 @@ defmodule Logflare.Mixfile do
# https://github.com/falood/file_system/pull/87
#
# Credo is currently holding us back
{:file_system, "~> 1.0", override: true, only: [:dev, :test]}
{:file_system, "~> 1.0", override: true, only: [:dev, :test]},

# otel
{:opentelemetry, "~> 1.3"},
{:opentelemetry_api, "~> 1.2"},
{:opentelemetry_exporter, "~> 1.6"},
{:opentelemetry_phoenix, "~> 1.1"},
{:opentelemetry_cowboy, "~> 0.2"}
]
end

Expand Down
Loading

0 comments on commit dddc164

Please sign in to comment.