scoutapp / scout_apm_elixir

ScoutAPM Elixir Agent. Supports Phoenix and other frameworks.
https://scoutapm.com
Other
36 stars 20 forks source link

"Scout Layer mismatch" when sampling transactions with `TrackedRequest.ignore()` #94

Closed bobics closed 5 years ago

bobics commented 5 years ago

I'm trying to only sample a fraction of our requests using ScoutApm.TrackedRequest.ignore() per the API docs in scout_apm_elixir, but seeing the following error:

[info] Scout Layer mismatch when stopping layer in %ScoutApm.TrackedRequest{children: [[%ScoutApm.Internal.Layer{backtrace: nil, children: [], desc: "SELECT ...", manual_duration: %ScoutApm.Internal.Duration{value: 7071}, name: "select#foo", scopable: true, started_at: -576460705648896, stopped_at: -576460705648889, type: "Ecto", uri: nil}]], collector_fn: #Function<2.87999675/1 in ScoutApm.TrackedRequest.build_collector_fn/1>, contexts: [], error: nil, ignored: true, ignoring_depth: 1, layers: [], root_layer: nil}

Following this per the docs: https://github.com/scoutapp/scout_apm_elixir/blob/master/lib/scout_apm/tracked_request.ex#L146

How we're calling it:

  @transaction_opts [...]
  join("my_channel", ...) do
    sample_transaction()
    ...
  end

  def sample_transaction do
    if :rand.uniform() > 0.05 do
      ScoutApm.TrackedRequest.ignore()
    end
  end

We're using Ecto 2, and we see this message flood our logs. Most of our transactions are for Phoenix channels (e.g. join and handle_in functions). We've been running Scout for a over month now without issues before this.

We're currently using a forked version of the latest official release (v0.14.5), with a single commit that's a workaround for this issue https://github.com/scoutapp/scout_apm_elixir/issues/89 (which I see is fixed in master). We can try using the latest master if you think that helps, but it doesn't look like any of the later commits are related to this particular issue.

https://github.com/bobics/scout_apm_elixir/commit/d5f07f17bbaaea5e888184b0e41eff667e00cc7d