{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/comments/172665498","pull_request_review_id":101722629,"id":172665498,"diff_hunk":"@@ -51,16 +70,47 @@ export function getNamespace(): CLS.Namespace {\n   return cls.getNamespace(TRACE_NAMESPACE);\n }\n \n+/**\n+ * Get a RootContext object from continuation-local storage.\n+ */\n export function getRootContext(): RootContext {\n   // First getNamespace check is necessary in case any\n   // patched closures escaped before the agent was stopped and the\n   // namespace was destroyed.\n-  if (getNamespace() && getNamespace().get('root')) {\n-    return getNamespace().get('root');\n+  const namespace = getNamespace();\n+  if (namespace) {\n+    // A few things can be going on here:\n+    // 1. setRootContext has been called earlier to store a real root span\n+    //    in continuation-local storage, so retrieve it.\n+    // 2. setRootContext has been called earlier to explicitly specify that\n+    //    the request corresponding to this continuation is _not_ being traced\n+    //    (by being passed UNTRACED_SPAN), so retrieve it as well.\n+    // 3. setRootContext has _never_ been called in this continuation. This\n+    //    indicates that context was lost, and namespace.get('root') will\n+    //    return null. Therefore, explicitly return UNCORRELATED_SPAN to\n+    //    indicate that context was lost.\n+    return namespace.get('root') || UNCORRELATED_SPAN;\n+  } else {\n+    // No namespace indicates that the Trace Agent is disabled. This is a\n+    // special case where _all_ requests are explicitly not being traced,\n+    // so return UNTRACED_SPAN to be consistent with that.\n+    return UNTRACED_SPAN;\n   }\n-  return null;\n }\n \n+/**\n+ * Store a RootContext object in continuation-local storage.\n+ * @param rootContext Either a root span or UNTRACED_SPAN. It doesn't make\n+ * sense to pass UNCORRELATED_SPAN, which is a value specifically reserved for\n+ * when getRootContext is known to give an unusable value.\n+ */\n export function setRootContext(rootContext: RootContext): void {\n   getNamespace().set('root', rootContext);\n }\n+\n+// This is only used in tests (and is temporary), so it doesn't apply in the\n+// comment in getRootContext about the possible values of namespace.get('root').\n+// It's functionally identical to setRootContext(null).","path":"src/cls.ts","position":78,"original_position":78,"commit_id":"b23273e5b904ac8ccef9220a75bbc561ef4d2703","original_commit_id":"8d504492d1cdb7ef019d3e22c843634462144bfc","user":{"login":"ofrobots","id":79017,"avatar_url":"https://avatars1.githubusercontent.com/u/79017?v=4","gravatar_id":"","url":"https://api.github.com/users/ofrobots","html_url":"https://github.com/ofrobots","followers_url":"https://api.github.com/users/ofrobots/followers","following_url":"https://api.github.com/users/ofrobots/following{/other_user}","gists_url":"https://api.github.com/users/ofrobots/gists{/gist_id}","starred_url":"https://api.github.com/users/ofrobots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ofrobots/subscriptions","organizations_url":"https://api.github.com/users/ofrobots/orgs","repos_url":"https://api.github.com/users/ofrobots/repos","events_url":"https://api.github.com/users/ofrobots/events{/privacy}","received_events_url":"https://api.github.com/users/ofrobots/received_events","type":"User","site_admin":false},"body":"*Its","created_at":"2018-03-06T21:27:19Z","updated_at":"2018-03-06T21:41:41Z","html_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680#discussion_r172665498","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/comments/172665498"},"html":{"href":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680#discussion_r172665498"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680","id":172389092,"html_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680","diff_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680.diff","patch_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/680","number":680,"state":"open","locked":false,"title":"feat: ensure spans are non-null","user":{"login":"kjin","id":2365820,"avatar_url":"https://avatars3.githubusercontent.com/u/2365820?v=4","gravatar_id":"","url":"https://api.github.com/users/kjin","html_url":"https://github.com/kjin","followers_url":"https://api.github.com/users/kjin/followers","following_url":"https://api.github.com/users/kjin/following{/other_user}","gists_url":"https://api.github.com/users/kjin/gists{/gist_id}","starred_url":"https://api.github.com/users/kjin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjin/subscriptions","organizations_url":"https://api.github.com/users/kjin/orgs","repos_url":"https://api.github.com/users/kjin/repos","events_url":"https://api.github.com/users/kjin/events{/privacy}","received_events_url":"https://api.github.com/users/kjin/received_events","type":"User","site_admin":false},"body":"__DNR until tests pass__\r\n\r\nFixes #656\r\n\r\nThis PR changes the public API so that spans are never null (in `runInRootSpan` or `createChildSpan`). Instead, they now expose a `type` field which represents whether they are real or \"virtual spans\". The code docs for `SpanDataType` in [this file](https://github.com/kjin/cloud-trace-nodejs/blob/new-span-data/src/constants.ts) should explain the purpose of `type`.\r\n\r\nOpen questions:\r\n1. Is this semver-major?\r\n2. Does `SpanData#type` need to have distinct `ROOT` and `CHILD` values?","created_at":"2018-03-02T00:04:32Z","updated_at":"2018-03-06T21:41:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8885fa8649b95cd28b5e2f20aa3c62284fd6d208","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":253957371,"url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/labels/cla:%20yes","name":"cla: yes","color":"0e8a16","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/680/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/statuses/b23273e5b904ac8ccef9220a75bbc561ef4d2703","head":{"label":"kjin:new-span-data","ref":"new-span-data","sha":"b23273e5b904ac8ccef9220a75bbc561ef4d2703","user":{"login":"kjin","id":2365820,"avatar_url":"https://avatars3.githubusercontent.com/u/2365820?v=4","gravatar_id":"","url":"https://api.github.com/users/kjin","html_url":"https://github.com/kjin","followers_url":"https://api.github.com/users/kjin/followers","following_url":"https://api.github.com/users/kjin/following{/other_user}","gists_url":"https://api.github.com/users/kjin/gists{/gist_id}","starred_url":"https://api.github.com/users/kjin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjin/subscriptions","organizations_url":"https://api.github.com/users/kjin/orgs","repos_url":"https://api.github.com/users/kjin/repos","events_url":"https://api.github.com/users/kjin/events{/privacy}","received_events_url":"https://api.github.com/users/kjin/received_events","type":"User","site_admin":false},"repo":{"id":68134606,"name":"cloud-trace-nodejs","full_name":"kjin/cloud-trace-nodejs","owner":{"login":"kjin","id":2365820,"avatar_url":"https://avatars3.githubusercontent.com/u/2365820?v=4","gravatar_id":"","url":"https://api.github.com/users/kjin","html_url":"https://github.com/kjin","followers_url":"https://api.github.com/users/kjin/followers","following_url":"https://api.github.com/users/kjin/following{/other_user}","gists_url":"https://api.github.com/users/kjin/gists{/gist_id}","starred_url":"https://api.github.com/users/kjin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kjin/subscriptions","organizations_url":"https://api.github.com/users/kjin/orgs","repos_url":"https://api.github.com/users/kjin/repos","events_url":"https://api.github.com/users/kjin/events{/privacy}","received_events_url":"https://api.github.com/users/kjin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kjin/cloud-trace-nodejs","description":"Experimental Node.js support for Google Cloud Trace","fork":true,"url":"https://api.github.com/repos/kjin/cloud-trace-nodejs","forks_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/forks","keys_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/teams","hooks_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/hooks","issue_events_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/issues/events{/number}","events_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/events","assignees_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/assignees{/user}","branches_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/branches{/branch}","tags_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/tags","blobs_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/git/refs{/sha}","trees_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/statuses/{sha}","languages_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/languages","stargazers_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/stargazers","contributors_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/contributors","subscribers_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/subscribers","subscription_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/subscription","commits_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/commits{/sha}","git_commits_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/git/commits{/sha}","comments_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/comments{/number}","issue_comment_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/issues/comments{/number}","contents_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/contents/{+path}","compare_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/merges","archive_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/downloads","issues_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/issues{/number}","pulls_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/pulls{/number}","milestones_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/milestones{/number}","notifications_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/labels{/name}","releases_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/releases{/id}","deployments_url":"https://api.github.com/repos/kjin/cloud-trace-nodejs/deployments","created_at":"2016-09-13T18:12:30Z","updated_at":"2016-09-13T18:12:32Z","pushed_at":"2018-03-06T21:34:09Z","git_url":"git://github.com/kjin/cloud-trace-nodejs.git","ssh_url":"git@github.com:kjin/cloud-trace-nodejs.git","clone_url":"https://github.com/kjin/cloud-trace-nodejs.git","svn_url":"https://github.com/kjin/cloud-trace-nodejs","homepage":"https://cloud.google.com/cloud-trace/","size":2848,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":5,"license":null,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"GoogleCloudPlatform:master","ref":"master","sha":"ea9279af404e879157a3ecb46160074d334e2051","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars0.githubusercontent.com/u/2810941?v=4","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":41170869,"name":"cloud-trace-nodejs","full_name":"GoogleCloudPlatform/cloud-trace-nodejs","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars0.githubusercontent.com/u/2810941?v=4","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs","description":"Node.js agent for Stackdriver Trace: automatically gather latency data about your application","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/deployments","created_at":"2015-08-21T18:23:09Z","updated_at":"2018-03-01T00:26:01Z","pushed_at":"2018-03-06T21:34:10Z","git_url":"git://github.com/GoogleCloudPlatform/cloud-trace-nodejs.git","ssh_url":"git@github.com:GoogleCloudPlatform/cloud-trace-nodejs.git","clone_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs.git","svn_url":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs","homepage":"https://cloud.google.com/trace/","size":2325,"stargazers_count":132,"watchers_count":132,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":61,"mirror_url":null,"archived":false,"open_issues_count":26,"license":null,"forks":61,"open_issues":26,"watchers":132,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680"},"html":{"href":"https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/680"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/680"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/issues/680/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/pulls/680/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/cloud-trace-nodejs/statuses/b23273e5b904ac8ccef9220a75bbc561ef4d2703"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"ofrobots"}}