Skip to content
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

Add spandex_ecto #78

Merged
merged 10 commits into from
Jun 29, 2020
Merged

Add spandex_ecto #78

merged 10 commits into from
Jun 29, 2020

Conversation

@ayrat555 ayrat555 force-pushed the ayrat555/integrate-spandex-ecto branch from ef841b3 to d26c5a8 Compare June 19, 2020 13:13
@ayrat555 ayrat555 marked this pull request as ready for review June 19, 2020 14:55
@@ -18,6 +18,10 @@ defmodule Engine.Application do

def start(_type, _args) do
attach_telemetry()

:ok =
:telemetry.attach("spandex-query-tracer", [:childchain, :repo], &SpandexEcto.TelemetryAdapter.handle_event/4, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could expand on the above attach_telemetry/0 and we do all the telementry setup there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to the attach_telemetry

@@ -18,6 +18,10 @@ defmodule Engine.Application do

def start(_type, _args) do
attach_telemetry()

:ok =
:telemetry.attach("spandex-query-tracer", [:childchain, :repo], &SpandexEcto.TelemetryAdapter.handle_event/4, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:telemetry.attach("spandex-query-tracer", [:childchain, :repo], &SpandexEcto.TelemetryAdapter.handle_event/4, nil)
:telemetry.attach("spandex-query-tracer", [:childchain, :repo, :query], &SpandexEcto.TelemetryAdapter.handle_event/4, nil)

I think we need the :query portion right? Where can we see example alerts for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example in the description

@@ -66,6 +66,8 @@ config :status, Status.Metric.Tracer,
type: :backend,
env: "local-development-childchain-v2"

config :engine, Engine.Repo, telemetry_prefix: [:childchain, :repo]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config :engine, Engine.Repo, telemetry_prefix: [:childchain, :repo]
config :engine, Engine.Repo, telemetry_prefix: [:engine, :repo]

should we just use the defaults? We can make it explicit too

_ = Logger.info("Attaching telemetry handlers #{inspect(Handler.supported_events())}")

case :telemetry.attach_many("alarm-handlers", Handler.supported_events(), &Handler.handle_event/4, nil) do
:ok -> :ok
{:error, :already_exists} -> :ok
end
end

defp submit_trace(arg1, arg2, arg3, arg4) do
Copy link
Contributor Author

@ayrat555 ayrat555 Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this function as a workaround. current_trace_id in https://github.com/spandex-project/spandex_ecto/blob/master/lib/spandex_ecto/ecto_logger.ex#L21 is always nil so without my wrapper traces are not submitted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the same thing! But it's really really odd that a project is this old and this was never reported.
spandex-project/spandex_ecto#2
spandex-project/spandex_ecto#17

It seems that spandex_ecto only works together with spandex_phoenix, so that spandex_phoenix starts a trace (like a HTTP requests) and spandex_ecto just updates the trace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue spandex-project/spandex_ecto#22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I think with this approach is that watcher info has endpoints that call into ecto:

scope "/", OMG.WatcherRPC.Web do
    pipe_through([:info_api])
    post("/block.all", Controller.Block, :get_blocks)
  end

our spandex web tracer would in this case start a trace in the cowboy request process (so current_trace_id would not be nil?),
and manually starting a trace would cause an error on spandex, perhaps?

Copy link
Contributor

@InoMurko InoMurko Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, I hope you understand what I mean, difficult to explain. Will we have overlapping traces in some cases (cases where the http request already starts a trace)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea. we can check if current trace id is set. if it is, we won't wrap a call to the ecto logger in a new trace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another idea! perhaps the correct way is to start a trace from the source code where the code initiated ecto? like so: https://github.com/omgnetwork/elixir-omg/blob/master/apps/omg/lib/omg/ethereum_event_listener.ex#L143

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@InoMurko do you mean to create a trace before every DB call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Because if I’m not mistaking, then the current solution would give datadog the idea that the ecto query started in the application module, right?

@ayrat555
Copy link
Contributor Author

ayrat555 commented Jun 24, 2020

it's not ready yet. spans for the same query are separated now. the correct one is omgnetwork/elixir-omg#1602

Copy link

@unnawut unnawut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm anyway!

@ayrat555 ayrat555 merged commit 61a3a61 into master Jun 29, 2020
@ayrat555 ayrat555 deleted the ayrat555/integrate-spandex-ecto branch June 29, 2020 14:53
@InoMurko
Copy link
Contributor

it's not ready yet. spans for the same query are separated now. the correct one is omgnetwork/elixir-omg#1602

Does this work now or is there another fix arriving?

@ayrat555
Copy link
Contributor Author

@InoMurko it works now

@InoMurko
Copy link
Contributor

oh great! so you didn't have to wrap Repo as in elixir-omg?

@ayrat555
Copy link
Contributor Author

@InoMurko yes, I had to pass the same tracer that is used in ecto_spandex

@InoMurko
Copy link
Contributor

noice! cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants