This is an automated email from the ASF dual-hosted git repository. littlecui pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push: new 263cb08 SCB-321 Add opentracing and zipkin 263cb08 is described below commit 263cb086f45a40f253e12ea694a8b2a3f157c944 Author: little-cui <sure_0...@qq.com> AuthorDate: Tue Jan 30 10:54:08 2018 +0800 SCB-321 Add opentracing and zipkin --- scripts/create_gvt_manifest(exp).sh | 11 +++ server/bootstrap/bootstrap.go | 2 + server/handler/tracing/tracing.go | 70 ++++++++++++++ vendor/manifest | 183 ++++++++++++++++++++++++++---------- 4 files changed, 218 insertions(+), 48 deletions(-) diff --git a/scripts/create_gvt_manifest(exp).sh b/scripts/create_gvt_manifest(exp).sh index 78cc418..810be31 100755 --- a/scripts/create_gvt_manifest(exp).sh +++ b/scripts/create_gvt_manifest(exp).sh @@ -63,3 +63,14 @@ gvt fetch -precaire -no-recurse -revision 7b8002443fd4a3ce5f25ef93087c524546799a gvt fetch -precaire -no-recurse -revision 553a641470496b2327abcac10b36396bd98e45c9 github.com/golang/snappy gvt fetch -precaire -no-recurse -revision 3c33c26290b747350f8650c7d38bcc51b42dc785 github.com/grpc/grpc-go gvt fetch -precaire -no-recurse -revision aa2eb687b4d3e17154372564ad8d6bf11c3cf21f github.com/google/go-genproto +gvt fetch -precaire -no-recurse -revision 1949ddbfd147afd4d964a9f00b24eb291e0e7c38 github.com/opentracing/opentracing-go +gvt fetch -precaire -no-recurse -revision 6bb822a7f15fdc5800b9822a6ac1bfa0b7d9195d github.com/openzipkin/zipkin-go-opentracing +gvt fetch -precaire -no-recurse -revision 9bb4a68d57ff6f623363aa172f0a8297aa289ba7 github.com/Shopify/sarama +gvt fetch -precaire -no-recurse -revision 3d556248a8b97310da49939195330691dfe9d9ad github.com/apache/thrift +gvt fetch -precaire -no-recurse -revision 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 github.com/go-logfmt/logfmt +gvt fetch -precaire -no-recurse -revision a52f2342449246d5bcc273e65cbdcfa5f7d6c63c github.com/opentracing-contrib/go-observer +gvt fetch -precaire -no-recurse -revision 6cf5744a041a0022271cefed95ba843f6d87fd51 github.com/davecgh/go-spew +gvt fetch -precaire -no-recurse -revision 6800482f2c813e689c88b7ed3282262385011890 github.com/eapache/go-resiliency +gvt fetch -precaire -no-recurse -revision bb955e01b9346ac19dc29eb16586c90ded99a98c github.com/eapache/go-xerial-snappy +gvt fetch -precaire -no-recurse -revision ded5959c0d4e360646dc9e9908cff48666781367 github.com/eapache/queue +gvt fetch -precaire -no-recurse -revision cb6bfca970f6908083f26f39a79009d608efd5cd github.com/klauspost/crc32 diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go index 5c50e65..83fdb9c 100644 --- a/server/bootstrap/bootstrap.go +++ b/server/bootstrap/bootstrap.go @@ -48,6 +48,7 @@ import ( "github.com/apache/incubator-servicecomb-service-center/server/handler/cache" "github.com/apache/incubator-servicecomb-service-center/server/handler/context" "github.com/apache/incubator-servicecomb-service-center/server/handler/metric" + "github.com/apache/incubator-servicecomb-service-center/server/handler/tracing" "github.com/apache/incubator-servicecomb-service-center/server/interceptor" "github.com/apache/incubator-servicecomb-service-center/server/interceptor/access" "github.com/apache/incubator-servicecomb-service-center/server/interceptor/cors" @@ -64,6 +65,7 @@ func init() { // handle requests after routing. metric.RegisterHandlers() + tracing.RegisterHandlers() auth.RegisterHandlers() context.RegisterHandlers() cache.RegisterHandlers() diff --git a/server/handler/tracing/tracing.go b/server/handler/tracing/tracing.go new file mode 100644 index 0000000..caa04db --- /dev/null +++ b/server/handler/tracing/tracing.go @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package tracing + +import ( + "github.com/apache/incubator-servicecomb-service-center/pkg/chain" + "github.com/apache/incubator-servicecomb-service-center/pkg/rest" + "github.com/apache/incubator-servicecomb-service-center/server/core" + "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/ext" + zipkin "github.com/openzipkin/zipkin-go-opentracing" + "github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/zipkincore" + "net/http" +) + +var tracer opentracing.Tracer + +func init() { + collector, err := zipkin.NewHTTPCollector("127.0.0.1:9411") + if err != nil { + return + } + recorder := zipkin.NewRecorder(collector, false, "0.0.0.0:0", core.Service.ServiceName) + tracer, err = zipkin.NewTracer(recorder, zipkin.TraceID128Bit(true)) +} + +type TracingHandler struct { +} + +func (h *TracingHandler) Handle(i *chain.Invocation) { + w, request := i.Context().Value(rest.CTX_RESPONSE).(http.ResponseWriter), + i.Context().Value(rest.CTX_REQUEST).(*http.Request) + ctx, err := tracer.Extract(opentracing.TextMap, opentracing.HTTPHeadersCarrier(request.Header)) + switch err { + case nil: + case opentracing.ErrSpanContextNotFound: + default: + } + + span := tracer.StartSpan("api", ext.RPCServerOption(ctx)) + ext.SpanKindRPCServer.Set(span) + + cb := i.Func + i.Invoke(func(r chain.Result) { + cb(r) + span.SetTag(zipkincore.HTTP_METHOD, request.Method) + span.SetTag(zipkincore.HTTP_PATH, request.RequestURI) + span.SetTag(zipkincore.HTTP_STATUS_CODE, w.Header().Get("X-Response-Status")) + span.SetTag(zipkincore.HTTP_HOST, request.URL.Host) + span.Finish() + }) +} + +func RegisterHandlers() { + chain.RegisterHandler(rest.SERVER_CHAIN_NAME, &TracingHandler{}) +} diff --git a/vendor/manifest b/vendor/manifest index bbd49ce..c3b3fa5 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -1,4 +1,3 @@ - { "version": 0, "dependencies": [ @@ -11,6 +10,22 @@ "notests": true }, { + "importpath": "github.com/Shopify/sarama", + "repository": "https://github.com/Shopify/sarama", + "vcs": "git", + "revision": "9bb4a68d57ff6f623363aa172f0a8297aa289ba7", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "github.com/apache/thrift", + "repository": "https://github.com/apache/thrift", + "vcs": "git", + "revision": "3d556248a8b97310da49939195330691dfe9d9ad", + "branch": "HEAD", + "notests": true + }, + { "importpath": "github.com/astaxie/beego", "repository": "https://github.com/astaxie/beego", "vcs": "git", @@ -147,6 +162,14 @@ "notests": true }, { + "importpath": "github.com/davecgh/go-spew", + "repository": "https://github.com/davecgh/go-spew", + "vcs": "git", + "revision": "6cf5744a041a0022271cefed95ba843f6d87fd51", + "branch": "HEAD", + "notests": true + }, + { "importpath": "github.com/dustin/go-humanize", "repository": "https://github.com/dustin/go-humanize", "vcs": "git", @@ -155,6 +178,30 @@ "notests": true }, { + "importpath": "github.com/eapache/go-resiliency", + "repository": "https://github.com/eapache/go-resiliency", + "vcs": "git", + "revision": "6800482f2c813e689c88b7ed3282262385011890", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "github.com/eapache/go-xerial-snappy", + "repository": "https://github.com/eapache/go-xerial-snappy", + "vcs": "git", + "revision": "bb955e01b9346ac19dc29eb16586c90ded99a98c", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "github.com/eapache/queue", + "repository": "https://github.com/eapache/queue", + "vcs": "git", + "revision": "ded5959c0d4e360646dc9e9908cff48666781367", + "branch": "HEAD", + "notests": true + }, + { "importpath": "github.com/edsrzf/mmap-go", "repository": "https://github.com/edsrzf/mmap-go", "vcs": "git", @@ -179,26 +226,18 @@ "notests": true }, { - "importpath": "github.com/gogo/protobuf", - "repository": "https://github.com/gogo/protobuf", - "vcs": "git", - "revision": "baaac160ed234ed06b347cf51202683a0068efe4", - "branch": "HEAD", - "notests": true - }, - { - "importpath": "golang.org/x/crypto", - "repository": "https://github.com/golang/crypto", + "importpath": "github.com/go-logfmt/logfmt", + "repository": "https://github.com/go-logfmt/logfmt", "vcs": "git", - "revision": "5ef0053f77724838734b6945dd364d3847e5de1d", + "revision": "390ab7935ee28ec6b286364bba9b4dd6410cb3d5", "branch": "HEAD", "notests": true }, { - "importpath": "golang.org/x/net", - "repository": "https://github.com/golang/net", + "importpath": "github.com/gogo/protobuf", + "repository": "https://github.com/gogo/protobuf", "vcs": "git", - "revision": "c81e7f25cb61200d8bf0ae971a0bac8cb638d5bc", + "revision": "baaac160ed234ed06b347cf51202683a0068efe4", "branch": "HEAD", "notests": true }, @@ -219,22 +258,6 @@ "notests": true }, { - "importpath": "golang.org/x/text", - "repository": "https://github.com/golang/text", - "vcs": "git", - "revision": "6353ef0f924300eea566d3438817aa4d3374817e", - "branch": "HEAD", - "notests": true - }, - { - "importpath": "golang.org/x/time", - "repository": "https://github.com/golang/time", - "vcs": "git", - "revision": "8be79e1e0910c292df4e79c241bb7e8f7e725959", - "branch": "HEAD", - "notests": true - }, - { "importpath": "github.com/google/btree", "repository": "https://github.com/google/btree", "vcs": "git", @@ -243,14 +266,6 @@ "notests": true }, { - "importpath": "google.golang.org/genproto", - "repository": "https://github.com/google/go-genproto", - "vcs": "git", - "revision": "aa2eb687b4d3e17154372564ad8d6bf11c3cf21f", - "branch": "HEAD", - "notests": true - }, - { "importpath": "github.com/gorilla/websocket", "repository": "https://github.com/gorilla/websocket", "vcs": "git", @@ -259,14 +274,6 @@ "notests": true }, { - "importpath": "google.golang.org/grpc", - "repository": "https://github.com/grpc/grpc-go", - "vcs": "git", - "revision": "3c33c26290b747350f8650c7d38bcc51b42dc785", - "branch": "HEAD", - "notests": true - }, - { "importpath": "github.com/hsluoyz/casbin", "repository": "https://github.com/hsluoyz/casbin", "vcs": "git", @@ -291,6 +298,14 @@ "notests": true }, { + "importpath": "github.com/klauspost/crc32", + "repository": "https://github.com/klauspost/crc32", + "vcs": "git", + "revision": "cb6bfca970f6908083f26f39a79009d608efd5cd", + "branch": "HEAD", + "notests": true + }, + { "importpath": "github.com/kr/pty", "repository": "https://github.com/kr/pty", "vcs": "git", @@ -347,6 +362,30 @@ "notests": true }, { + "importpath": "github.com/opentracing-contrib/go-observer", + "repository": "https://github.com/opentracing-contrib/go-observer", + "vcs": "git", + "revision": "a52f2342449246d5bcc273e65cbdcfa5f7d6c63c", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "github.com/opentracing/opentracing-go", + "repository": "https://github.com/opentracing/opentracing-go", + "vcs": "git", + "revision": "1949ddbfd147afd4d964a9f00b24eb291e0e7c38", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "github.com/openzipkin/zipkin-go-opentracing", + "repository": "https://github.com/openzipkin/zipkin-go-opentracing", + "vcs": "git", + "revision": "6bb822a7f15fdc5800b9822a6ac1bfa0b7d9195d", + "branch": "HEAD", + "notests": true + }, + { "importpath": "github.com/pelletier/go-toml", "repository": "https://github.com/pelletier/go-toml", "vcs": "git", @@ -467,6 +506,54 @@ "notests": true }, { + "importpath": "golang.org/x/crypto", + "repository": "https://github.com/golang/crypto", + "vcs": "git", + "revision": "5ef0053f77724838734b6945dd364d3847e5de1d", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "golang.org/x/net", + "repository": "https://github.com/golang/net", + "vcs": "git", + "revision": "c81e7f25cb61200d8bf0ae971a0bac8cb638d5bc", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "golang.org/x/text", + "repository": "https://github.com/golang/text", + "vcs": "git", + "revision": "6353ef0f924300eea566d3438817aa4d3374817e", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "golang.org/x/time", + "repository": "https://github.com/golang/time", + "vcs": "git", + "revision": "8be79e1e0910c292df4e79c241bb7e8f7e725959", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "google.golang.org/genproto", + "repository": "https://github.com/google/go-genproto", + "vcs": "git", + "revision": "aa2eb687b4d3e17154372564ad8d6bf11c3cf21f", + "branch": "HEAD", + "notests": true + }, + { + "importpath": "google.golang.org/grpc", + "repository": "https://github.com/grpc/grpc-go", + "vcs": "git", + "revision": "3c33c26290b747350f8650c7d38bcc51b42dc785", + "branch": "HEAD", + "notests": true + }, + { "importpath": "gopkg.in/cheggaaa/pb.v1", "repository": "https://gopkg.in/cheggaaa/pb.v1", "vcs": "git", @@ -483,4 +570,4 @@ "notests": true } ] -} +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact little...@apache.org.