{"action":"created","comment":{"url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments/76072880","id":76072880,"diff_hunk":"@@ -0,0 +1,157 @@\n+/*\n+ * Copyright (c) 2016, Uber Technologies, Inc\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+package com.uber.jaeger.crossdock.resources.behavior;\n+\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+import com.uber.jaeger.Span;\n+import com.uber.jaeger.SpanContext;\n+import com.uber.jaeger.context.TracingUtils;\n+import com.uber.jaeger.crossdock.Constants;\n+import com.uber.jaeger.crossdock.JerseyServer;\n+import com.uber.jaeger.crossdock.resources.behavior.tchannel.TChannelServer;\n+import com.uber.jaeger.crossdock.tracetest.TracedService;\n+import com.uber.jaeger.crossdock.tracetest_manual.Downstream;\n+import com.uber.jaeger.crossdock.tracetest_manual.JoinTraceRequest;\n+import com.uber.jaeger.crossdock.tracetest_manual.ObservedSpan;\n+import com.uber.jaeger.crossdock.tracetest_manual.TraceResponse;\n+import com.uber.tchannel.api.SubChannel;\n+import com.uber.tchannel.api.TFuture;\n+import com.uber.tchannel.messages.ThriftRequest;\n+import com.uber.tchannel.messages.ThriftResponse;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import javax.ws.rs.client.Entity;\n+import javax.ws.rs.core.MediaType;\n+import javax.ws.rs.core.Response;\n+import java.io.IOException;\n+import java.net.InetAddress;\n+import java.net.UnknownHostException;\n+\n+public class TraceBehavior {\n+    private static final Logger logger = LoggerFactory.getLogger(TraceBehavior.class);\n+\n+    private static final ObjectMapper mapper = new ObjectMapper();\n+\n+    public TraceResponse prepareResponse(Downstream downstream) throws Exception {\n+        TraceResponse response = new TraceResponse(observeSpan());\n+\n+        if (downstream != null) {\n+            TraceResponse downstreamResponse = callDownstream(downstream);\n+            response.setDownstream(downstreamResponse);\n+        }\n+\n+        return response;\n+    }\n+\n+    private TraceResponse callDownstream(Downstream downstream) throws Exception {\n+        logger.info(\"Calling downstream {}\", downstream);\n+        String transport = downstream.getTransport();\n+        switch (transport) {\n+            case Constants.TRANSPORT_HTTP:\n+                return callDownstreamHTTP(downstream);\n+            case Constants.TRANSPORT_TCHANNEL:\n+                return callDownstreamTChannel(downstream);\n+            default:\n+                return new TraceResponse(\"Unrecognized transport received: %s\" + transport);\n+        }\n+    }\n+\n+    private TraceResponse callDownstreamHTTP(Downstream downstream) throws IOException {\n+        String downstreamURL = String.format(\n+                \"http://%s:%s/join_trace\", downstream.getHost(), downstream.getPort()\n+        );\n+        logger.info(\"Calling downstream http {} at {}\", downstream.getServiceName(), downstreamURL);\n+\n+        Response resp = JerseyServer.client.target(downstreamURL)\n+                .request(MediaType.APPLICATION_JSON)\n+                .post(Entity.json(new JoinTraceRequest(downstream.getServerRole(), downstream.getDownstream())));\n+\n+        String respStr = resp.readEntity(String.class);\n+        TraceResponse response = mapper.readValue(respStr, TraceResponse.class);\n+        logger.info(\"Received response {}\", response);\n+        return response;\n+    }\n+\n+    public TraceResponse callDownstreamTChannel(Downstream downstream) throws Exception {\n+        com.uber.jaeger.crossdock.tracetest.JoinTraceRequest joinTraceRequest =\n+                new com.uber.jaeger.crossdock.tracetest.JoinTraceRequest(downstream.getServerRole());\n+        joinTraceRequest.setDownstream(Downstream.toThrift(downstream.getDownstream()));\n+\n+        SubChannel subChannel = TChannelServer.server.makeSubChannel(downstream.getServiceName());\n+\n+        logger.info(\"Calling downstream tchannel {}\", joinTraceRequest);\n+        ThriftRequest<TracedService.joinTrace_args> thriftRequest = new ThriftRequest.Builder<TracedService.joinTrace_args>(\n+                downstream.getServiceName(),\n+                \"TracedService::joinTrace\"\n+        )\n+                    .setTimeout(2000)","path":"jaeger-crossdock/src/main/java/com/uber/jaeger/crossdock/resources/behavior/TraceBehavior.java","position":107,"original_position":107,"commit_id":"f33770405ffecc0b4d79935dbfe55d36642d81c3","original_commit_id":"f33770405ffecc0b4d79935dbfe55d36642d81c3","user":{"login":"black-adder","id":791791,"avatar_url":"https://avatars.githubusercontent.com/u/791791?v=3","gravatar_id":"","url":"https://api.github.com/users/black-adder","html_url":"https://github.com/black-adder","followers_url":"https://api.github.com/users/black-adder/followers","following_url":"https://api.github.com/users/black-adder/following{/other_user}","gists_url":"https://api.github.com/users/black-adder/gists{/gist_id}","starred_url":"https://api.github.com/users/black-adder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/black-adder/subscriptions","organizations_url":"https://api.github.com/users/black-adder/orgs","repos_url":"https://api.github.com/users/black-adder/repos","events_url":"https://api.github.com/users/black-adder/events{/privacy}","received_events_url":"https://api.github.com/users/black-adder/received_events","type":"User","site_admin":false},"body":"formatting?","created_at":"2016-08-24T14:57:19Z","updated_at":"2016-08-24T14:57:19Z","html_url":"https://github.com/uber/jaeger-client-java/pull/33#discussion_r76072880","pull_request_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments/76072880"},"html":{"href":"https://github.com/uber/jaeger-client-java/pull/33#discussion_r76072880"},"pull_request":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33","id":82479007,"html_url":"https://github.com/uber/jaeger-client-java/pull/33","diff_url":"https://github.com/uber/jaeger-client-java/pull/33.diff","patch_url":"https://github.com/uber/jaeger-client-java/pull/33.patch","issue_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/33","number":33,"state":"open","locked":false,"title":"Implement Crossdock TChannel requests","user":{"login":"yurishkuro","id":3523016,"avatar_url":"https://avatars.githubusercontent.com/u/3523016?v=3","gravatar_id":"","url":"https://api.github.com/users/yurishkuro","html_url":"https://github.com/yurishkuro","followers_url":"https://api.github.com/users/yurishkuro/followers","following_url":"https://api.github.com/users/yurishkuro/following{/other_user}","gists_url":"https://api.github.com/users/yurishkuro/gists{/gist_id}","starred_url":"https://api.github.com/users/yurishkuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurishkuro/subscriptions","organizations_url":"https://api.github.com/users/yurishkuro/orgs","repos_url":"https://api.github.com/users/yurishkuro/repos","events_url":"https://api.github.com/users/yurishkuro/events{/privacy}","received_events_url":"https://api.github.com/users/yurishkuro/received_events","type":"User","site_admin":false},"body":" * [ ] rename thrift package to crossdock.thrift\r\n * [ ] use master image for Go","created_at":"2016-08-24T04:14:01Z","updated_at":"2016-08-24T14:57:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8f8fc7eb8fd6f7a3d7a9a2fd27c5d13e8523737e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33/commits","review_comments_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33/comments","review_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/33/comments","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/f33770405ffecc0b4d79935dbfe55d36642d81c3","head":{"label":"uber:crossdock-tchannel","ref":"crossdock-tchannel","sha":"f33770405ffecc0b4d79935dbfe55d36642d81c3","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":56551000,"name":"jaeger-client-java","full_name":"uber/jaeger-client-java","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/jaeger-client-java","description":"Jaeger Bindings for Java OpenTracing API","fork":false,"url":"https://api.github.com/repos/uber/jaeger-client-java","forks_url":"https://api.github.com/repos/uber/jaeger-client-java/forks","keys_url":"https://api.github.com/repos/uber/jaeger-client-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/jaeger-client-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/jaeger-client-java/teams","hooks_url":"https://api.github.com/repos/uber/jaeger-client-java/hooks","issue_events_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/events{/number}","events_url":"https://api.github.com/repos/uber/jaeger-client-java/events","assignees_url":"https://api.github.com/repos/uber/jaeger-client-java/assignees{/user}","branches_url":"https://api.github.com/repos/uber/jaeger-client-java/branches{/branch}","tags_url":"https://api.github.com/repos/uber/jaeger-client-java/tags","blobs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/jaeger-client-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/jaeger-client-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/jaeger-client-java/languages","stargazers_url":"https://api.github.com/repos/uber/jaeger-client-java/stargazers","contributors_url":"https://api.github.com/repos/uber/jaeger-client-java/contributors","subscribers_url":"https://api.github.com/repos/uber/jaeger-client-java/subscribers","subscription_url":"https://api.github.com/repos/uber/jaeger-client-java/subscription","commits_url":"https://api.github.com/repos/uber/jaeger-client-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/jaeger-client-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/jaeger-client-java/contents/{+path}","compare_url":"https://api.github.com/repos/uber/jaeger-client-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/jaeger-client-java/merges","archive_url":"https://api.github.com/repos/uber/jaeger-client-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/jaeger-client-java/downloads","issues_url":"https://api.github.com/repos/uber/jaeger-client-java/issues{/number}","pulls_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/jaeger-client-java/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/jaeger-client-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/jaeger-client-java/labels{/name}","releases_url":"https://api.github.com/repos/uber/jaeger-client-java/releases{/id}","deployments_url":"https://api.github.com/repos/uber/jaeger-client-java/deployments","created_at":"2016-04-19T00:10:02Z","updated_at":"2016-07-20T16:13:20Z","pushed_at":"2016-08-24T04:14:01Z","git_url":"git://github.com/uber/jaeger-client-java.git","ssh_url":"git@github.com:uber/jaeger-client-java.git","clone_url":"https://github.com/uber/jaeger-client-java.git","svn_url":"https://github.com/uber/jaeger-client-java","homepage":"","size":230,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":2,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"4e21a6ef26356a53e4aa5d3ed8edc86330acbbc7","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":56551000,"name":"jaeger-client-java","full_name":"uber/jaeger-client-java","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/jaeger-client-java","description":"Jaeger Bindings for Java OpenTracing API","fork":false,"url":"https://api.github.com/repos/uber/jaeger-client-java","forks_url":"https://api.github.com/repos/uber/jaeger-client-java/forks","keys_url":"https://api.github.com/repos/uber/jaeger-client-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/jaeger-client-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/jaeger-client-java/teams","hooks_url":"https://api.github.com/repos/uber/jaeger-client-java/hooks","issue_events_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/events{/number}","events_url":"https://api.github.com/repos/uber/jaeger-client-java/events","assignees_url":"https://api.github.com/repos/uber/jaeger-client-java/assignees{/user}","branches_url":"https://api.github.com/repos/uber/jaeger-client-java/branches{/branch}","tags_url":"https://api.github.com/repos/uber/jaeger-client-java/tags","blobs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/jaeger-client-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/jaeger-client-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/jaeger-client-java/languages","stargazers_url":"https://api.github.com/repos/uber/jaeger-client-java/stargazers","contributors_url":"https://api.github.com/repos/uber/jaeger-client-java/contributors","subscribers_url":"https://api.github.com/repos/uber/jaeger-client-java/subscribers","subscription_url":"https://api.github.com/repos/uber/jaeger-client-java/subscription","commits_url":"https://api.github.com/repos/uber/jaeger-client-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/jaeger-client-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/jaeger-client-java/contents/{+path}","compare_url":"https://api.github.com/repos/uber/jaeger-client-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/jaeger-client-java/merges","archive_url":"https://api.github.com/repos/uber/jaeger-client-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/jaeger-client-java/downloads","issues_url":"https://api.github.com/repos/uber/jaeger-client-java/issues{/number}","pulls_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/jaeger-client-java/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/jaeger-client-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/jaeger-client-java/labels{/name}","releases_url":"https://api.github.com/repos/uber/jaeger-client-java/releases{/id}","deployments_url":"https://api.github.com/repos/uber/jaeger-client-java/deployments","created_at":"2016-04-19T00:10:02Z","updated_at":"2016-07-20T16:13:20Z","pushed_at":"2016-08-24T04:14:01Z","git_url":"git://github.com/uber/jaeger-client-java.git","ssh_url":"git@github.com:uber/jaeger-client-java.git","clone_url":"https://github.com/uber/jaeger-client-java.git","svn_url":"https://github.com/uber/jaeger-client-java","homepage":"","size":230,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33"},"html":{"href":"https://github.com/uber/jaeger-client-java/pull/33"},"issue":{"href":"https://api.github.com/repos/uber/jaeger-client-java/issues/33"},"comments":{"href":"https://api.github.com/repos/uber/jaeger-client-java/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/uber/jaeger-client-java/statuses/f33770405ffecc0b4d79935dbfe55d36642d81c3"}}}}
{"actor":{"display_login":"black-adder"}}