{"action":"created","comment":{"url":"https://api.github.com/repos/pryin-io/pryin/pulls/comments/122266944","pull_request_review_id":44368846,"id":122266944,"diff_hunk":"@@ -133,86 +150,97 @@ defmodule PryIn.InteractionStore do\n   def handle_cast({:start_interaction, pid, interaction}, state) do\n     state = drop_running_interaction(pid, state)\n \n-    if stored_interacions_count(state) >= max_interactions() do\n+    if stored_interactions_count(state) >= max_interactions() do\n       Logger.info(\"[PryIn] Dropping interaction #{inspect pid} because buffer is full.\")\n       {:noreply, state}\n     else\n-      monitor_refs = Map.put(state.monitor_refs, pid, Process.monitor(pid))\n-      running_interactions = Map.put(state.running_interactions, pid, interaction)\n-      {:noreply, %{state |\n-                   running_interactions: running_interactions,\n-                   monitor_refs: monitor_refs}}\n+      ref = Process.monitor(pid)\n+      running_interaction = %RunningInteraction{type: :parent, interaction: interaction, ref: ref, child_pids: []}\n+      running_interactions = Map.put(state.running_interactions, pid, running_interaction)\n+      {:noreply, %{state | running_interactions: running_interactions}}\n     end\n   end\n \n   def handle_cast({:set_interaction_data, pid, data}, state) do\n-    interaction = state.running_interactions\n-    |> Map.get(pid)\n-    |> Map.merge(data)\n-    running_interactions = %{state.running_interactions | pid => interaction}\n-    {:noreply, %{state | running_interactions: running_interactions}}\n+    state = update_in(state.running_interactions[parent_pid(state, pid)].interaction,\n+      fn interaction -> Map.merge(interaction, data)\n+    end)\n+    {:noreply, state}\n   end\n \n   def handle_cast({:add_ecto_query, pid, data}, state) do\n-    interaction = Map.get(state.running_interactions, pid)\n-    case interaction do\n-      nil ->\n-        {:noreply, state}\n-      interaction ->\n-        ecto_query = Interaction.EctoQuery.new(data)\n-        interaction = Map.update!(interaction, :ecto_queries, &([ecto_query | &1]))\n-        running_interactions = %{state.running_interactions | pid => interaction}\n-        {:noreply, %{state | running_interactions: running_interactions}}\n-    end\n+    state = update_in(state.running_interactions[parent_pid(state, pid)].interaction,\n+      fn\n+        nil -> nil\n+        interaction ->\n+          ecto_query = Interaction.EctoQuery.new(data)\n+          Map.update!(interaction, :ecto_queries, &([ecto_query | &1]))\n+      end)\n+    {:noreply, state}\n   end\n \n   def handle_cast({:add_view_rendering, pid, data}, state) do\n-    interaction = Map.get(state.running_interactions, pid)\n-    case interaction do\n-      nil ->\n-        {:noreply, state}\n-      interaction ->\n-        view_rendering = Interaction.ViewRendering.new(data)\n-        interaction = Map.update!(interaction, :view_renderings, &([view_rendering | &1]))\n-        running_interactions = %{state.running_interactions | pid => interaction}\n-        {:noreply, %{state | running_interactions: running_interactions}}\n-    end\n+    state = update_in(state.running_interactions[parent_pid(state, pid)].interaction,\n+      fn\n+        nil -> nil\n+        interaction ->\n+          view_rendering = Interaction.ViewRendering.new(data)\n+          Map.update!(interaction, :view_renderings, &([view_rendering | &1]))\n+      end)\n+    {:noreply, state}\n   end\n \n   def handle_cast({:add_custom_metric, pid, data}, state) do\n-    interaction = Map.get(state.running_interactions, pid)\n-    case interaction do\n-      nil ->\n-        {:noreply, state}\n-      interaction ->\n-        custom_metric = Interaction.CustomMetric.new(data)\n-        interaction = Map.update!(interaction, :custom_metrics, &([custom_metric | &1]))\n-        running_interactions = %{state.running_interactions | pid => interaction}\n-        {:noreply, %{state | running_interactions: running_interactions}}\n-    end\n+    state = update_in(state.running_interactions[parent_pid(state, pid)].interaction,\n+      fn\n+        nil -> nil\n+        interaction ->\n+          custom_metric = Interaction.CustomMetric.new(data)\n+          Map.update!(interaction, :custom_metrics, &([custom_metric | &1]))\n+      end)\n+    {:noreply, state}\n   end\n \n   def handle_cast({:finish_interaction, pid}, state) do\n-    {monitor_ref, remaining_monitor_refs} = Map.pop(state.monitor_refs, pid)\n-    Process.demonitor(monitor_ref)\n-    {finished_interaction, running_interactions} = Map.pop(state.running_interactions, pid)\n-    finished_interaction = Map.update!(finished_interaction, :start_time, &trunc(&1 / 1000))\n+    {finished_running_interaction, running_interactions} = Map.pop(state.running_interactions, pid)\n+    Process.demonitor(finished_running_interaction.ref)\n+\n+    running_interactions = clear_children(running_interactions, finished_running_interaction.child_pids)","path":"lib/pryin/interaction_store.ex","position":139,"original_position":139,"commit_id":"763a348bfe271c2394ecb42ee90a9b71981ea667","original_commit_id":"763a348bfe271c2394ecb42ee90a9b71981ea667","user":{"login":"manukall","id":117418,"avatar_url":"https://avatars3.githubusercontent.com/u/117418?v=3","gravatar_id":"","url":"https://api.github.com/users/manukall","html_url":"https://github.com/manukall","followers_url":"https://api.github.com/users/manukall/followers","following_url":"https://api.github.com/users/manukall/following{/other_user}","gists_url":"https://api.github.com/users/manukall/gists{/gist_id}","starred_url":"https://api.github.com/users/manukall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manukall/subscriptions","organizations_url":"https://api.github.com/users/manukall/orgs","repos_url":"https://api.github.com/users/manukall/repos","events_url":"https://api.github.com/users/manukall/events{/privacy}","received_events_url":"https://api.github.com/users/manukall/received_events","type":"User","site_admin":false},"body":"raise if type != parent?","created_at":"2017-06-15T17:45:46Z","updated_at":"2017-06-15T17:55:08Z","html_url":"https://github.com/pryin-io/pryin/pull/6#discussion_r122266944","pull_request_url":"https://api.github.com/repos/pryin-io/pryin/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/comments/122266944"},"html":{"href":"https://github.com/pryin-io/pryin/pull/6#discussion_r122266944"},"pull_request":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/pryin-io/pryin/pulls/6","id":125030223,"html_url":"https://github.com/pryin-io/pryin/pull/6","diff_url":"https://github.com/pryin-io/pryin/pull/6.diff","patch_url":"https://github.com/pryin-io/pryin/pull/6.patch","issue_url":"https://api.github.com/repos/pryin-io/pryin/issues/6","number":6,"state":"open","locked":false,"title":"Multi process traces","user":{"login":"manukall","id":117418,"avatar_url":"https://avatars3.githubusercontent.com/u/117418?v=3","gravatar_id":"","url":"https://api.github.com/users/manukall","html_url":"https://github.com/manukall","followers_url":"https://api.github.com/users/manukall/followers","following_url":"https://api.github.com/users/manukall/following{/other_user}","gists_url":"https://api.github.com/users/manukall/gists{/gist_id}","starred_url":"https://api.github.com/users/manukall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manukall/subscriptions","organizations_url":"https://api.github.com/users/manukall/orgs","repos_url":"https://api.github.com/users/manukall/repos","events_url":"https://api.github.com/users/manukall/events{/privacy}","received_events_url":"https://api.github.com/users/manukall/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-06-11T15:45:18Z","updated_at":"2017-06-15T17:55:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3a462346626c550acdb5555a74342bbfed58ca94","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/pryin-io/pryin/pulls/6/commits","review_comments_url":"https://api.github.com/repos/pryin-io/pryin/pulls/6/comments","review_comment_url":"https://api.github.com/repos/pryin-io/pryin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pryin-io/pryin/issues/6/comments","statuses_url":"https://api.github.com/repos/pryin-io/pryin/statuses/763a348bfe271c2394ecb42ee90a9b71981ea667","head":{"label":"pryin-io:multi_process_traces","ref":"multi_process_traces","sha":"763a348bfe271c2394ecb42ee90a9b71981ea667","user":{"login":"pryin-io","id":24988798,"avatar_url":"https://avatars2.githubusercontent.com/u/24988798?v=3","gravatar_id":"","url":"https://api.github.com/users/pryin-io","html_url":"https://github.com/pryin-io","followers_url":"https://api.github.com/users/pryin-io/followers","following_url":"https://api.github.com/users/pryin-io/following{/other_user}","gists_url":"https://api.github.com/users/pryin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/pryin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pryin-io/subscriptions","organizations_url":"https://api.github.com/users/pryin-io/orgs","repos_url":"https://api.github.com/users/pryin-io/repos","events_url":"https://api.github.com/users/pryin-io/events{/privacy}","received_events_url":"https://api.github.com/users/pryin-io/received_events","type":"Organization","site_admin":false},"repo":{"id":87229763,"name":"pryin","full_name":"pryin-io/pryin","owner":{"login":"pryin-io","id":24988798,"avatar_url":"https://avatars2.githubusercontent.com/u/24988798?v=3","gravatar_id":"","url":"https://api.github.com/users/pryin-io","html_url":"https://github.com/pryin-io","followers_url":"https://api.github.com/users/pryin-io/followers","following_url":"https://api.github.com/users/pryin-io/following{/other_user}","gists_url":"https://api.github.com/users/pryin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/pryin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pryin-io/subscriptions","organizations_url":"https://api.github.com/users/pryin-io/orgs","repos_url":"https://api.github.com/users/pryin-io/repos","events_url":"https://api.github.com/users/pryin-io/events{/privacy}","received_events_url":"https://api.github.com/users/pryin-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pryin-io/pryin","description":"PryIn is a performance metrics platform for your Elixir/Phoenix application.","fork":false,"url":"https://api.github.com/repos/pryin-io/pryin","forks_url":"https://api.github.com/repos/pryin-io/pryin/forks","keys_url":"https://api.github.com/repos/pryin-io/pryin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pryin-io/pryin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pryin-io/pryin/teams","hooks_url":"https://api.github.com/repos/pryin-io/pryin/hooks","issue_events_url":"https://api.github.com/repos/pryin-io/pryin/issues/events{/number}","events_url":"https://api.github.com/repos/pryin-io/pryin/events","assignees_url":"https://api.github.com/repos/pryin-io/pryin/assignees{/user}","branches_url":"https://api.github.com/repos/pryin-io/pryin/branches{/branch}","tags_url":"https://api.github.com/repos/pryin-io/pryin/tags","blobs_url":"https://api.github.com/repos/pryin-io/pryin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pryin-io/pryin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pryin-io/pryin/git/refs{/sha}","trees_url":"https://api.github.com/repos/pryin-io/pryin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pryin-io/pryin/statuses/{sha}","languages_url":"https://api.github.com/repos/pryin-io/pryin/languages","stargazers_url":"https://api.github.com/repos/pryin-io/pryin/stargazers","contributors_url":"https://api.github.com/repos/pryin-io/pryin/contributors","subscribers_url":"https://api.github.com/repos/pryin-io/pryin/subscribers","subscription_url":"https://api.github.com/repos/pryin-io/pryin/subscription","commits_url":"https://api.github.com/repos/pryin-io/pryin/commits{/sha}","git_commits_url":"https://api.github.com/repos/pryin-io/pryin/git/commits{/sha}","comments_url":"https://api.github.com/repos/pryin-io/pryin/comments{/number}","issue_comment_url":"https://api.github.com/repos/pryin-io/pryin/issues/comments{/number}","contents_url":"https://api.github.com/repos/pryin-io/pryin/contents/{+path}","compare_url":"https://api.github.com/repos/pryin-io/pryin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pryin-io/pryin/merges","archive_url":"https://api.github.com/repos/pryin-io/pryin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pryin-io/pryin/downloads","issues_url":"https://api.github.com/repos/pryin-io/pryin/issues{/number}","pulls_url":"https://api.github.com/repos/pryin-io/pryin/pulls{/number}","milestones_url":"https://api.github.com/repos/pryin-io/pryin/milestones{/number}","notifications_url":"https://api.github.com/repos/pryin-io/pryin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pryin-io/pryin/labels{/name}","releases_url":"https://api.github.com/repos/pryin-io/pryin/releases{/id}","deployments_url":"https://api.github.com/repos/pryin-io/pryin/deployments","created_at":"2017-04-04T20:03:58Z","updated_at":"2017-05-10T15:15:39Z","pushed_at":"2017-06-15T17:33:08Z","git_url":"git://github.com/pryin-io/pryin.git","ssh_url":"git@github.com:pryin-io/pryin.git","clone_url":"https://github.com/pryin-io/pryin.git","svn_url":"https://github.com/pryin-io/pryin","homepage":"https://pryin.io","size":79,"stargazers_count":1,"watchers_count":1,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"pryin-io:master","ref":"master","sha":"e537ac2bb75310e8d4dc19188146801e548077be","user":{"login":"pryin-io","id":24988798,"avatar_url":"https://avatars2.githubusercontent.com/u/24988798?v=3","gravatar_id":"","url":"https://api.github.com/users/pryin-io","html_url":"https://github.com/pryin-io","followers_url":"https://api.github.com/users/pryin-io/followers","following_url":"https://api.github.com/users/pryin-io/following{/other_user}","gists_url":"https://api.github.com/users/pryin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/pryin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pryin-io/subscriptions","organizations_url":"https://api.github.com/users/pryin-io/orgs","repos_url":"https://api.github.com/users/pryin-io/repos","events_url":"https://api.github.com/users/pryin-io/events{/privacy}","received_events_url":"https://api.github.com/users/pryin-io/received_events","type":"Organization","site_admin":false},"repo":{"id":87229763,"name":"pryin","full_name":"pryin-io/pryin","owner":{"login":"pryin-io","id":24988798,"avatar_url":"https://avatars2.githubusercontent.com/u/24988798?v=3","gravatar_id":"","url":"https://api.github.com/users/pryin-io","html_url":"https://github.com/pryin-io","followers_url":"https://api.github.com/users/pryin-io/followers","following_url":"https://api.github.com/users/pryin-io/following{/other_user}","gists_url":"https://api.github.com/users/pryin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/pryin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pryin-io/subscriptions","organizations_url":"https://api.github.com/users/pryin-io/orgs","repos_url":"https://api.github.com/users/pryin-io/repos","events_url":"https://api.github.com/users/pryin-io/events{/privacy}","received_events_url":"https://api.github.com/users/pryin-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pryin-io/pryin","description":"PryIn is a performance metrics platform for your Elixir/Phoenix application.","fork":false,"url":"https://api.github.com/repos/pryin-io/pryin","forks_url":"https://api.github.com/repos/pryin-io/pryin/forks","keys_url":"https://api.github.com/repos/pryin-io/pryin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pryin-io/pryin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pryin-io/pryin/teams","hooks_url":"https://api.github.com/repos/pryin-io/pryin/hooks","issue_events_url":"https://api.github.com/repos/pryin-io/pryin/issues/events{/number}","events_url":"https://api.github.com/repos/pryin-io/pryin/events","assignees_url":"https://api.github.com/repos/pryin-io/pryin/assignees{/user}","branches_url":"https://api.github.com/repos/pryin-io/pryin/branches{/branch}","tags_url":"https://api.github.com/repos/pryin-io/pryin/tags","blobs_url":"https://api.github.com/repos/pryin-io/pryin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pryin-io/pryin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pryin-io/pryin/git/refs{/sha}","trees_url":"https://api.github.com/repos/pryin-io/pryin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pryin-io/pryin/statuses/{sha}","languages_url":"https://api.github.com/repos/pryin-io/pryin/languages","stargazers_url":"https://api.github.com/repos/pryin-io/pryin/stargazers","contributors_url":"https://api.github.com/repos/pryin-io/pryin/contributors","subscribers_url":"https://api.github.com/repos/pryin-io/pryin/subscribers","subscription_url":"https://api.github.com/repos/pryin-io/pryin/subscription","commits_url":"https://api.github.com/repos/pryin-io/pryin/commits{/sha}","git_commits_url":"https://api.github.com/repos/pryin-io/pryin/git/commits{/sha}","comments_url":"https://api.github.com/repos/pryin-io/pryin/comments{/number}","issue_comment_url":"https://api.github.com/repos/pryin-io/pryin/issues/comments{/number}","contents_url":"https://api.github.com/repos/pryin-io/pryin/contents/{+path}","compare_url":"https://api.github.com/repos/pryin-io/pryin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pryin-io/pryin/merges","archive_url":"https://api.github.com/repos/pryin-io/pryin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pryin-io/pryin/downloads","issues_url":"https://api.github.com/repos/pryin-io/pryin/issues{/number}","pulls_url":"https://api.github.com/repos/pryin-io/pryin/pulls{/number}","milestones_url":"https://api.github.com/repos/pryin-io/pryin/milestones{/number}","notifications_url":"https://api.github.com/repos/pryin-io/pryin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pryin-io/pryin/labels{/name}","releases_url":"https://api.github.com/repos/pryin-io/pryin/releases{/id}","deployments_url":"https://api.github.com/repos/pryin-io/pryin/deployments","created_at":"2017-04-04T20:03:58Z","updated_at":"2017-05-10T15:15:39Z","pushed_at":"2017-06-15T17:33:08Z","git_url":"git://github.com/pryin-io/pryin.git","ssh_url":"git@github.com:pryin-io/pryin.git","clone_url":"https://github.com/pryin-io/pryin.git","svn_url":"https://github.com/pryin-io/pryin","homepage":"https://pryin.io","size":79,"stargazers_count":1,"watchers_count":1,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/6"},"html":{"href":"https://github.com/pryin-io/pryin/pull/6"},"issue":{"href":"https://api.github.com/repos/pryin-io/pryin/issues/6"},"comments":{"href":"https://api.github.com/repos/pryin-io/pryin/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pryin-io/pryin/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/pryin-io/pryin/statuses/763a348bfe271c2394ecb42ee90a9b71981ea667"}}}}
{"actor":{"display_login":"manukall"}}