-
-
Notifications
You must be signed in to change notification settings - Fork 358
feat: initial work to set-up opentelemetry tracing #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bef576d
1a9d9af
3b643e7
95f67b3
2ec3c11
2707264
da9ea91
1321c5b
dc8713b
baaaf9a
cb4dce8
9282680
e70ca8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ defmodule RealtimeWeb.TenantController do | |
require Logger | ||
import Realtime.Logs | ||
|
||
alias OpenTelemetry.Tracer | ||
alias Realtime.Api | ||
alias Realtime.Api.Tenant | ||
alias Realtime.Database | ||
|
@@ -26,6 +25,8 @@ defmodule RealtimeWeb.TenantController do | |
|
||
action_fallback(RealtimeWeb.FallbackController) | ||
|
||
plug :set_observability_attributes when action in [:show, :edit, :update, :delete, :reload, :health] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ziinc I ended up using a This felt like a good compromise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the plug can handle the situation where there isn't a tenant_id in path param with a fallthrough so you don't have to explicitly state the actions, that would make it less verbose |
||
|
||
operation(:index, | ||
summary: "List tenants", | ||
parameters: [ | ||
|
@@ -70,9 +71,6 @@ defmodule RealtimeWeb.TenantController do | |
) | ||
|
||
def show(conn, %{"tenant_id" => id}) do | ||
Logger.metadata(external_id: id, project: id) | ||
Tracer.set_attributes(external_id: id) | ||
|
||
tenant = Api.get_tenant_by_external_id(id) | ||
|
||
case tenant do | ||
|
@@ -136,8 +134,6 @@ defmodule RealtimeWeb.TenantController do | |
) | ||
|
||
def update(conn, %{"tenant_id" => external_id, "tenant" => tenant_params}) do | ||
Logger.metadata(external_id: external_id, project: external_id) | ||
Tracer.set_attributes(external_id: external_id) | ||
tenant = Api.get_tenant_by_external_id(external_id) | ||
|
||
case tenant do | ||
|
@@ -153,7 +149,6 @@ defmodule RealtimeWeb.TenantController do | |
with {:ok, %Tenant{} = tenant} <- Api.create_tenant(%{tenant_params | "extensions" => extensions}), | ||
res when res in [:ok, :noop] <- Migrations.run_migrations(tenant) do | ||
Logger.metadata(external_id: tenant.external_id, project: tenant.external_id) | ||
Tracer.set_attributes(external_id: tenant.external_id) | ||
|
||
conn | ||
|> put_status(:created) | ||
|
@@ -192,9 +187,6 @@ defmodule RealtimeWeb.TenantController do | |
) | ||
|
||
def delete(conn, %{"tenant_id" => tenant_id}) do | ||
Logger.metadata(external_id: tenant_id, project: tenant_id) | ||
Tracer.set_attributes(external_id: tenant_id) | ||
|
||
stop_all_timeout = Enum.count(PostgresCdc.available_drivers()) * 1_000 | ||
|
||
with %Tenant{} = tenant <- Api.get_tenant_by_external_id(tenant_id, :primary), | ||
|
@@ -236,9 +228,6 @@ defmodule RealtimeWeb.TenantController do | |
) | ||
|
||
def reload(conn, %{"tenant_id" => tenant_id}) do | ||
Logger.metadata(external_id: tenant_id, project: tenant_id) | ||
Tracer.set_attributes(external_id: tenant_id) | ||
|
||
case Tenants.get_tenant_by_external_id(tenant_id) do | ||
nil -> | ||
log_error("TenantNotFound", "Tenant not found") | ||
|
@@ -274,9 +263,6 @@ defmodule RealtimeWeb.TenantController do | |
) | ||
|
||
def health(conn, %{"tenant_id" => tenant_id}) do | ||
Logger.metadata(external_id: tenant_id, project: tenant_id) | ||
Tracer.set_attributes(external_id: tenant_id) | ||
|
||
case Tenants.health_check(tenant_id) do | ||
{:ok, response} -> | ||
json(conn, %{data: response}) | ||
|
@@ -292,4 +278,12 @@ defmodule RealtimeWeb.TenantController do | |
|> render("not_found.json", tenant: nil) | ||
end | ||
end | ||
|
||
defp set_observability_attributes(conn, _opts) do | ||
tenant_id = conn.path_params["tenant_id"] | ||
OpenTelemetry.Tracer.set_attributes(external_id: tenant_id) | ||
Logger.metadata(external_id: tenant_id, project: tenant_id) | ||
|
||
conn | ||
end | ||
filipecabaco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end |
Uh oh!
There was an error while loading. Please reload this page.