本文整理汇总了Golang中github.com/go-kit/kit/tracing/zipkin.MakeNewSpanFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeNewSpanFunc函数的具体用法?Golang MakeNewSpanFunc怎么用?Golang MakeNewSpanFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeNewSpanFunc函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: testAnnotate
func testAnnotate(
annotate func(newSpan zipkin.NewSpanFunc, c zipkin.Collector) endpoint.Middleware,
wantAnnotations ...string,
) error {
const (
hostport = "1.2.3.4:1234"
serviceName = "some-service"
methodName = "some-method"
)
newSpan := zipkin.MakeNewSpanFunc(hostport, serviceName, methodName)
collector := &countingCollector{}
var e endpoint.Endpoint
e = func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
e = annotate(newSpan, collector)(e)
if want, have := 0, len(collector.annotations); want != have {
return fmt.Errorf("pre-invocation: want %d, have %d", want, have)
}
if _, err := e(context.Background(), struct{}{}); err != nil {
return fmt.Errorf("during invocation: %v", err)
}
if want, have := wantAnnotations, collector.annotations; !reflect.DeepEqual(want, have) {
return fmt.Errorf("after invocation: want %v, have %v", want, have)
}
return nil
}
开发者ID:omnistream,项目名称:kit,代码行数:29,代码来源:zipkin_test.go
示例2: TestToGRPCRequest
func TestToGRPCRequest(t *testing.T) {
const (
hostport = "5.5.5.5:5555"
serviceName = "foo-service"
methodName = "foo-method"
traceID int64 = 20
spanID int64 = 40
parentSpanID int64 = 90
)
newSpan := zipkin.MakeNewSpanFunc(hostport, serviceName, methodName)
span := newSpan(traceID, spanID, parentSpanID)
ctx := context.WithValue(context.Background(), zipkin.SpanContextKey, span)
md := &metadata.MD{}
ctx = zipkin.ToGRPCRequest(newSpan)(ctx, md)
for header, wantInt := range map[string]int64{
"x-b3-traceid": traceID,
"x-b3-spanid": spanID,
"x-b3-parentspanid": parentSpanID,
} {
if want, have := strconv.FormatInt(wantInt, 16), (*md)[header][0]; want != have {
t.Errorf("%s: want %q, have %q", header, want, have)
}
}
}
开发者ID:omnistream,项目名称:kit,代码行数:26,代码来源:zipkin_test.go
示例3: TestToRequest
func TestToRequest(t *testing.T) {
const (
hostport = "5.5.5.5:5555"
serviceName = "foo-service"
methodName = "foo-method"
traceID int64 = 20
spanID int64 = 40
parentSpanID int64 = 90
)
newSpan := zipkin.MakeNewSpanFunc(hostport, serviceName, methodName)
span := newSpan(traceID, spanID, parentSpanID)
ctx := context.WithValue(context.Background(), zipkin.SpanContextKey, span)
r, _ := http.NewRequest("GET", "https://best.horse", nil)
ctx = zipkin.ToRequest(newSpan)(ctx, r)
for header, wantInt := range map[string]int64{
"X-B3-TraceId": traceID,
"X-B3-SpanId": spanID,
"X-B3-ParentSpanId": parentSpanID,
} {
if want, have := strconv.FormatInt(wantInt, 16), r.Header.Get(header); want != have {
t.Errorf("%s: want %q, have %q", header, want, have)
}
}
}
开发者ID:omnistream,项目名称:kit,代码行数:26,代码来源:zipkin_test.go
示例4: TestToContext
func TestToContext(t *testing.T) {
const (
hostport = "5.5.5.5:5555"
serviceName = "foo-service"
methodName = "foo-method"
traceID int64 = 12
spanID int64 = 34
parentSpanID int64 = 56
sampled = "1"
)
r, _ := http.NewRequest("GET", "https://best.horse", nil)
r.Header.Set("X-B3-TraceId", strconv.FormatInt(traceID, 16))
r.Header.Set("X-B3-SpanId", strconv.FormatInt(spanID, 16))
r.Header.Set("X-B3-ParentSpanId", strconv.FormatInt(parentSpanID, 16))
r.Header.Set("X-B3-Sampled", sampled)
newSpan := zipkin.MakeNewSpanFunc(hostport, serviceName, methodName)
toContext := zipkin.ToContext(newSpan, log.NewLogfmtLogger(ioutil.Discard))
ctx := toContext(context.Background(), r)
val := ctx.Value(zipkin.SpanContextKey)
if val == nil {
t.Fatalf("%s returned no value", zipkin.SpanContextKey)
}
span, ok := val.(*zipkin.Span)
if !ok {
t.Fatalf("%s was not a Span object", zipkin.SpanContextKey)
}
for want, haveFunc := range map[int64]func() int64{
traceID: span.TraceID,
spanID: span.SpanID,
parentSpanID: span.ParentSpanID,
} {
if have := haveFunc(); want != have {
name := runtime.FuncForPC(reflect.ValueOf(haveFunc).Pointer()).Name()
name = strings.Split(name, "·")[0]
toks := strings.Split(name, ".")
name = toks[len(toks)-1]
t.Errorf("%s: want %d, have %d", name, want, have)
}
}
if want, have := true, span.IsSampled(); want != have {
t.Errorf("IsSampled: want %v, have %v", want, have)
}
}
开发者ID:xiejianzheng,项目名称:goddd,代码行数:47,代码来源:zipkin_test.go
示例5: TestToGRPCContext
func TestToGRPCContext(t *testing.T) {
const (
hostport = "5.5.5.5:5555"
serviceName = "foo-service"
methodName = "foo-method"
traceID int64 = 12
spanID int64 = 34
parentSpanID int64 = 56
)
md := metadata.MD{
"x-b3-traceid": []string{strconv.FormatInt(traceID, 16)},
"x-b3-spanid": []string{strconv.FormatInt(spanID, 16)},
"x-b3-parentspanid": []string{strconv.FormatInt(parentSpanID, 16)},
"x-b3-sampled": []string{"1"},
}
newSpan := zipkin.MakeNewSpanFunc(hostport, serviceName, methodName)
toContext := zipkin.ToGRPCContext(newSpan, log.NewLogfmtLogger(ioutil.Discard))
ctx := toContext(context.Background(), &md)
val := ctx.Value(zipkin.SpanContextKey)
if val == nil {
t.Fatalf("%s returned no value", zipkin.SpanContextKey)
}
span, ok := val.(*zipkin.Span)
if !ok {
t.Fatalf("%s was not a Span object", zipkin.SpanContextKey)
}
for want, haveFunc := range map[int64]func() int64{
traceID: span.TraceID,
spanID: span.SpanID,
parentSpanID: span.ParentSpanID,
} {
if have := haveFunc(); want != have {
name := runtime.FuncForPC(reflect.ValueOf(haveFunc).Pointer()).Name()
name = strings.Split(name, "·")[0]
toks := strings.Split(name, ".")
name = toks[len(toks)-1]
t.Errorf("%s: want %d, have %d", name, want, have)
}
}
if want, have := true, span.IsSampled(); want != have {
t.Errorf("IsSampled: want %v, have %v", want, have)
}
}
开发者ID:xiejianzheng,项目名称:goddd,代码行数:47,代码来源:zipkin_test.go
示例6: main
func main() {
// Flag domain. Note that gRPC transitively registers flags via its import
// of glog. So, we define a new flag set, to keep those domains distinct.
fs := flag.NewFlagSet("", flag.ExitOnError)
var (
debugAddr = fs.String("debug.addr", ":8000", "Address for HTTP debug/instrumentation server")
httpAddr = fs.String("http.addr", ":8001", "Address for HTTP (JSON) server")
grpcAddr = fs.String("grpc.addr", ":8002", "Address for gRPC server")
netrpcAddr = fs.String("netrpc.addr", ":8003", "Address for net/rpc server")
thriftAddr = fs.String("thrift.addr", ":8004", "Address for Thrift server")
thriftProtocol = fs.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = fs.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = fs.Bool("thrift.framed", false, "true to enable framing")
zipkinHostPort = fs.String("zipkin.host.port", "my.service.domain:12345", "Zipkin host:port")
zipkinServiceName = fs.String("zipkin.service.name", "addsvc", "Zipkin service name")
zipkinCollectorAddr = fs.String("zipkin.collector.addr", "", "Zipkin Scribe collector address (empty will log spans)")
zipkinCollectorTimeout = fs.Duration("zipkin.collector.timeout", time.Second, "Zipkin collector timeout")
zipkinCollectorBatchSize = fs.Int("zipkin.collector.batch.size", 100, "Zipkin collector batch size")
zipkinCollectorBatchInterval = fs.Duration("zipkin.collector.batch.interval", time.Second, "Zipkin collector batch interval")
)
flag.Usage = fs.Usage // only show our flags
if err := fs.Parse(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
os.Exit(1)
}
// package log
var logger log.Logger
{
logger = log.NewLogfmtLogger(os.Stderr)
logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC).With("caller", log.DefaultCaller)
stdlog.SetFlags(0) // flags are handled by Go kit's logger
stdlog.SetOutput(log.NewStdlibAdapter(logger)) // redirect anything using stdlib log to us
}
// package metrics
var requestDuration metrics.TimeHistogram
{
requestDuration = metrics.NewTimeHistogram(time.Nanosecond, metrics.NewMultiHistogram(
expvar.NewHistogram("request_duration_ns", 0, 5e9, 1, 50, 95, 99),
prometheus.NewSummary(stdprometheus.SummaryOpts{
Namespace: "myorg",
Subsystem: "addsvc",
Name: "duration_ns",
Help: "Request duration in nanoseconds.",
}, []string{"method"}),
))
}
// package tracing
var collector zipkin.Collector
{
zipkinLogger := log.NewContext(logger).With("component", "zipkin")
collector = loggingCollector{zipkinLogger} // TODO(pb)
if *zipkinCollectorAddr != "" {
var err error
if collector, err = zipkin.NewScribeCollector(
*zipkinCollectorAddr,
*zipkinCollectorTimeout,
zipkin.ScribeBatchSize(*zipkinCollectorBatchSize),
zipkin.ScribeBatchInterval(*zipkinCollectorBatchInterval),
zipkin.ScribeLogger(zipkinLogger),
); err != nil {
zipkinLogger.Log("err", err)
os.Exit(1)
}
}
}
// Business domain
var svc server.AddService
{
svc = pureAddService{}
svc = loggingMiddleware{svc, logger}
svc = instrumentingMiddleware{svc, requestDuration}
}
// Mechanical stuff
rand.Seed(time.Now().UnixNano())
root := context.Background()
errc := make(chan error)
go func() {
errc <- interrupt()
}()
// Debug/instrumentation
go func() {
transportLogger := log.NewContext(logger).With("transport", "debug")
transportLogger.Log("addr", *debugAddr)
errc <- http.ListenAndServe(*debugAddr, nil) // DefaultServeMux
}()
// Transport: HTTP/JSON
go func() {
var (
transportLogger = log.NewContext(logger).With("transport", "HTTP/JSON")
tracingLogger = log.NewContext(transportLogger).With("component", "tracing")
newSumSpan = zipkin.MakeNewSpanFunc(*zipkinHostPort, *zipkinServiceName, "sum")
newConcatSpan = zipkin.MakeNewSpanFunc(*zipkinHostPort, *zipkinServiceName, "concat")
//.........这里部分代码省略.........
开发者ID:simonjefford,项目名称:kit,代码行数:101,代码来源:main.go
示例7: main
func main() {
// Flag domain. Note that gRPC transitively registers flags via its import
// of glog. So, we define a new flag set, to keep those domains distinct.
fs := flag.NewFlagSet("", flag.ExitOnError)
var (
debugAddr = fs.String("debug.addr", ":8000", "Address for HTTP debug/instrumentation server")
httpAddr = fs.String("http.addr", ":8001", "Address for HTTP (JSON) server")
netrpcAddr = fs.String("netrpc.addr", ":8003", "Address for net/rpc server")
proxyHTTPAddr = fs.String("proxy.http.url", "", "if set, proxy requests over HTTP to this addsvc")
zipkinServiceName = fs.String("zipkin.service.name", "addsvc", "Zipkin service name")
zipkinCollectorAddr = fs.String("zipkin.collector.addr", "", "Zipkin Scribe collector address (empty will log spans)")
zipkinCollectorTimeout = fs.Duration("zipkin.collector.timeout", time.Second, "Zipkin collector timeout")
zipkinCollectorBatchSize = fs.Int("zipkin.collector.batch.size", 100, "Zipkin collector batch size")
zipkinCollectorBatchInterval = fs.Duration("zipkin.collector.batch.interval", time.Second, "Zipkin collector batch interval")
)
flag.Usage = fs.Usage // only show our flags
fs.Parse(os.Args[1:])
// `package log` domain
var logger kitlog.Logger
logger = kitlog.NewLogfmtLogger(os.Stderr)
logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC)
stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) // redirect stdlib logging to us
stdlog.SetFlags(0) // flags are handled in our logger
// `package metrics` domain
requests := metrics.NewMultiCounter(
expvar.NewCounter("requests"),
statsd.NewCounter(ioutil.Discard, "requests_total", time.Second),
prometheus.NewCounter(stdprometheus.CounterOpts{
Namespace: "addsvc",
Subsystem: "add",
Name: "requests_total",
Help: "Total number of received requests.",
}, []string{}),
)
duration := metrics.NewTimeHistogram(time.Nanosecond, metrics.NewMultiHistogram(
expvar.NewHistogram("duration_nanoseconds_total", 0, 1e9, 3, 50, 95, 99),
statsd.NewHistogram(ioutil.Discard, "duration_nanoseconds_total", time.Second),
prometheus.NewSummary(stdprometheus.SummaryOpts{
Namespace: "addsvc",
Subsystem: "add",
Name: "duration_nanoseconds_total",
Help: "Total nanoseconds spend serving requests.",
}, []string{}),
))
_, _ = requests, duration
// `package tracing` domain
zipkinHostPort := "localhost:1234" // TODO Zipkin makes overly simple assumptions about services
var zipkinCollector zipkin.Collector = loggingCollector{logger}
if *zipkinCollectorAddr != "" {
var err error
if zipkinCollector, err = zipkin.NewScribeCollector(
*zipkinCollectorAddr,
*zipkinCollectorTimeout,
zipkin.ScribeBatchSize(*zipkinCollectorBatchSize),
zipkin.ScribeBatchInterval(*zipkinCollectorBatchInterval),
zipkin.ScribeLogger(logger),
); err != nil {
logger.Log("err", err)
os.Exit(1)
}
}
zipkinMethodName := "add"
zipkinSpanFunc := zipkin.MakeNewSpanFunc(zipkinHostPort, *zipkinServiceName, zipkinMethodName)
// Our business and operational domain
var a add.Adder = pureAdd{}
if *proxyHTTPAddr != "" {
var e endpoint.Endpoint
e = add.NewAdderAddHTTPClient("GET", *proxyHTTPAddr, zipkin.ToRequest(zipkinSpanFunc))
e = zipkin.AnnotateClient(zipkinSpanFunc, zipkinCollector)(e)
a = add.MakeAdderClient(func(method string) endpoint.Endpoint {
if method != "Add" {
panic(fmt.Errorf("unknown method %s", method))
}
return e
})
}
// This could happen at endpoint level.
// a = logging(logger)(a)
// a = instrument(requests, duration)(a)
// Server domain
var e endpoint.Endpoint
e = add.MakeAdderEndpoints(a).Add
e = zipkin.AnnotateServer(zipkinSpanFunc, zipkinCollector)(e)
// Mechanical stuff
rand.Seed(time.Now().UnixNano())
root := context.Background()
errc := make(chan error)
go func() {
errc <- interrupt()
}()
//.........这里部分代码省略.........
开发者ID:sasha-s,项目名称:kit,代码行数:101,代码来源:main.go
示例8: main
func main() {
// Flag domain. Note that gRPC transitively registers flags via its import
// of glog. So, we define a new flag set, to keep those domains distinct.
fs := flag.NewFlagSet("", flag.ExitOnError)
var (
debugAddr = fs.String("debug.addr", ":8000", "Address for HTTP debug/instrumentation server")
httpAddr = fs.String("http.addr", ":8001", "Address for HTTP (JSON) server")
grpcAddr = fs.String("grpc.addr", ":8002", "Address for gRPC server")
netrpcAddr = fs.String("netrpc.addr", ":8003", "Address for net/rpc server")
thriftAddr = fs.String("thrift.addr", ":8004", "Address for Thrift server")
thriftProtocol = fs.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = fs.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = fs.Bool("thrift.framed", false, "true to enable framing")
proxyHTTPAddr = fs.String("proxy.http.url", "", "if set, proxy requests over HTTP to this addsvc")
zipkinServiceName = fs.String("zipkin.service.name", "addsvc", "Zipkin service name")
zipkinCollectorAddr = fs.String("zipkin.collector.addr", "", "Zipkin Scribe collector address (empty will log spans)")
zipkinCollectorTimeout = fs.Duration("zipkin.collector.timeout", time.Second, "Zipkin collector timeout")
zipkinCollectorBatchSize = fs.Int("zipkin.collector.batch.size", 100, "Zipkin collector batch size")
zipkinCollectorBatchInterval = fs.Duration("zipkin.collector.batch.interval", time.Second, "Zipkin collector batch interval")
)
flag.Usage = fs.Usage // only show our flags
fs.Parse(os.Args[1:])
// `package log` domain
var logger kitlog.Logger
logger = kitlog.NewLogfmtLogger(os.Stderr)
logger = kitlog.With(logger, "ts", kitlog.DefaultTimestampUTC)
stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) // redirect stdlib logging to us
stdlog.SetFlags(0) // flags are handled in our logger
// `package metrics` domain
requests := metrics.NewMultiCounter(
expvar.NewCounter("requests"),
statsd.NewCounter(ioutil.Discard, "requests_total", time.Second),
prometheus.NewCounter(stdprometheus.CounterOpts{
Namespace: "addsvc",
Subsystem: "add",
Name: "requests_total",
Help: "Total number of received requests.",
}, []string{}),
)
duration := metrics.NewTimeHistogram(time.Nanosecond, metrics.NewMultiHistogram(
expvar.NewHistogram("duration_nanoseconds_total", 0, 1e9, 3, 50, 95, 99),
statsd.NewHistogram(ioutil.Discard, "duration_nanoseconds_total", time.Second),
prometheus.NewSummary(stdprometheus.SummaryOpts{
Namespace: "addsvc",
Subsystem: "add",
Name: "duration_nanoseconds_total",
Help: "Total nanoseconds spend serving requests.",
}, []string{}),
))
// `package tracing` domain
zipkinHostPort := "localhost:1234" // TODO Zipkin makes overly simple assumptions about services
var zipkinCollector zipkin.Collector = loggingCollector{logger}
if *zipkinCollectorAddr != "" {
var err error
if zipkinCollector, err = zipkin.NewScribeCollector(
*zipkinCollectorAddr,
*zipkinCollectorTimeout,
*zipkinCollectorBatchSize,
*zipkinCollectorBatchInterval,
); err != nil {
logger.Log("err", err)
os.Exit(1)
}
}
zipkinMethodName := "add"
zipkinSpanFunc := zipkin.MakeNewSpanFunc(zipkinHostPort, *zipkinServiceName, zipkinMethodName)
zipkin.Log.Swap(logger) // log diagnostic/error details
// Our business and operational domain
var a Add = pureAdd
if *proxyHTTPAddr != "" {
var e endpoint.Endpoint
e = httpclient.NewClient("GET", *proxyHTTPAddr, zipkin.ToRequest(zipkinSpanFunc))
e = zipkin.AnnotateClient(zipkinSpanFunc, zipkinCollector)(e)
a = proxyAdd(e, logger)
}
a = logging(logger)(a)
a = instrument(requests, duration)(a)
// Server domain
var e endpoint.Endpoint
e = makeEndpoint(a)
e = zipkin.AnnotateServer(zipkinSpanFunc, zipkinCollector)(e)
// Mechanical stuff
rand.Seed(time.Now().UnixNano())
root := context.Background()
errc := make(chan error)
go func() {
errc <- interrupt()
}()
// Transport: HTTP (debug/instrumentation)
go func() {
//.........这里部分代码省略.........
开发者ID:EthanK28,项目名称:kit,代码行数:101,代码来源:main.go
注:本文中的github.com/go-kit/kit/tracing/zipkin.MakeNewSpanFunc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论