Skip to content

Commit

Permalink
feat(otel): setup otel
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Oct 6, 2024
1 parent 39aabf4 commit 7bf3350
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ config :phoenix_live_view, :debug_heex_annotations, true
config :swoosh, :api_client, false

config :canary, :typesense, collection: "canary_dev"

config :opentelemetry, traces_exporter: :none
9 changes: 9 additions & 0 deletions core/config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ config :canary, :github_app_url, "https://github.com/apps/getcanary/installation

config :canary, :typesense, collection: "canary_prod"

config :opentelemetry,
traces_exporter: :otlp,
span_processor: :batch,
resource: [
service: [name: "core", namespace: "canary"],
deployment: [environment: "prod"]
],
sampler: {:parent_based, %{root: {:trace_id_ratio_based, 1.0}}}

config :sentry,
dsn:
"https://f6f1f6ab1218132660f6bd80e8634712@o4506190168522752.ingest.us.sentry.io/4508073135833088",
Expand Down
11 changes: 9 additions & 2 deletions core/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ config :canary, :github,
client_secret: System.get_env("GITHUB_CLIENT_SECRET"),
redirect_uri: System.get_env("GITHUB_REDIRECT_URI")

config :canary, :fly_api_key, System.get_env("FLY_API_KEY")
config :canary, :fly_app_name, System.get_env("FLY_APP_NAME")

if config_env() == :prod do
config :canary, :typesense,
base_url: System.get_env("TYPESENSE_BASE_URL"),
Expand All @@ -187,5 +190,9 @@ else
api_key: "canary"
end

config :canary, :fly_api_key, System.get_env("FLY_API_KEY")
config :canary, :fly_app_name, System.get_env("FLY_APP_NAME")
if config_env() == :prod do
config :opentelemetry_exporter,
otlp_protocol: :http_protobuf,
otlp_endpoint: System.fetch_env!("OTEL_COLLECTOR_URL"),
otlp_headers: [{"Authorization", "Bearer #{System.fetch_env!("OTEL_COLLECTOR_URL_AUTH")}"}]
end
10 changes: 10 additions & 0 deletions core/lib/canary.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
defmodule Canary do
def rest_client(opts \\ []) do
Req.new(opts)
|> attach_otel()
end

def graphql_client(opts \\ []) do
Req.new(opts)
|> attach_otel()
|> AbsintheClient.attach()
|> Req.Request.register_options([:graphql])
end

defp attach_otel(req) do
req
|> OpentelemetryReq.attach(
propagate_trace_ctx: true,
no_path_params: true
)
end
end
1 change: 1 addition & 0 deletions core/lib/canary/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Canary.Application do
def start(_type, _args) do
attach_oban_telemetry()
add_sentry_logger()
OpentelemetryEcto.setup([:canary, :repo])

:ok = Canary.Index.Collection.ensure(:webpage)
:ok = Canary.Index.Collection.ensure(:github_issue)
Expand Down
17 changes: 15 additions & 2 deletions core/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ defmodule Canary.MixProject do
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
consolidate_protocols: Mix.env() == :prod
consolidate_protocols: Mix.env() == :prod,
releases: [
canary: [
applications: [
opentelemetry_exporter: :permanent,
opentelemetry: :temporary
]
]
]
]
end

Expand Down Expand Up @@ -92,7 +100,12 @@ defmodule Canary.MixProject do
{:ex_json_schema, "~> 0.10"},
{:yaml_elixir, "~> 2.11"},
{:sentry, "~> 10.2.0"},
{:hackney, "~> 1.8"}
{:hackney, "~> 1.8"},
{:opentelemetry_exporter, "~> 1.2"},
{:opentelemetry, "~> 1.2"},
{:opentelemetry_api, "~> 1.2"},
{:opentelemetry_req, "~> 0.2.0"},
{:opentelemetry_ecto, "~> 1.0"}
] ++ deps_eval()
end

Expand Down
14 changes: 14 additions & 0 deletions core/mix.lock

Large diffs are not rendered by default.

0 comments on commit 7bf3350

Please sign in to comment.