Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
go-sso
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
id
go-sso
Commits
a4b690e8
Commit
a4b690e8
authored
Nov 18, 2018
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade go-common (add tracing)
parent
1724c178
Pipeline
#1586
passed with stages
in 1 minute and 51 seconds
Changes
95
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
95 changed files
with
8963 additions
and
13 deletions
+8963
-13
vendor/git.autistici.org/ai3/go-common/clientutil/transport.go
...r/git.autistici.org/ai3/go-common/clientutil/transport.go
+4
-2
vendor/git.autistici.org/ai3/go-common/serverutil/http.go
vendor/git.autistici.org/ai3/go-common/serverutil/http.go
+23
-3
vendor/git.autistici.org/ai3/go-common/tracing/tracing.go
vendor/git.autistici.org/ai3/go-common/tracing/tracing.go
+130
-0
vendor/github.com/openzipkin/zipkin-go/LICENSE
vendor/github.com/openzipkin/zipkin-go/LICENSE
+201
-0
vendor/github.com/openzipkin/zipkin-go/Makefile
vendor/github.com/openzipkin/zipkin-go/Makefile
+28
-0
vendor/github.com/openzipkin/zipkin-go/README.md
vendor/github.com/openzipkin/zipkin-go/README.md
+79
-0
vendor/github.com/openzipkin/zipkin-go/appveyor.yml
vendor/github.com/openzipkin/zipkin-go/appveyor.yml
+21
-0
vendor/github.com/openzipkin/zipkin-go/circle.yml
vendor/github.com/openzipkin/zipkin-go/circle.yml
+11
-0
vendor/github.com/openzipkin/zipkin-go/context.go
vendor/github.com/openzipkin/zipkin-go/context.go
+23
-0
vendor/github.com/openzipkin/zipkin-go/doc.go
vendor/github.com/openzipkin/zipkin-go/doc.go
+6
-0
vendor/github.com/openzipkin/zipkin-go/endpoint.go
vendor/github.com/openzipkin/zipkin-go/endpoint.go
+66
-0
vendor/github.com/openzipkin/zipkin-go/idgenerator/idgenerator.go
...ithub.com/openzipkin/zipkin-go/idgenerator/idgenerator.go
+116
-0
vendor/github.com/openzipkin/zipkin-go/model/annotation.go
vendor/github.com/openzipkin/zipkin-go/model/annotation.go
+46
-0
vendor/github.com/openzipkin/zipkin-go/model/doc.go
vendor/github.com/openzipkin/zipkin-go/model/doc.go
+9
-0
vendor/github.com/openzipkin/zipkin-go/model/endpoint.go
vendor/github.com/openzipkin/zipkin-go/model/endpoint.go
+17
-0
vendor/github.com/openzipkin/zipkin-go/model/kind.go
vendor/github.com/openzipkin/zipkin-go/model/kind.go
+13
-0
vendor/github.com/openzipkin/zipkin-go/model/span.go
vendor/github.com/openzipkin/zipkin-go/model/span.go
+124
-0
vendor/github.com/openzipkin/zipkin-go/model/span_id.go
vendor/github.com/openzipkin/zipkin-go/model/span_id.go
+30
-0
vendor/github.com/openzipkin/zipkin-go/model/traceid.go
vendor/github.com/openzipkin/zipkin-go/model/traceid.go
+61
-0
vendor/github.com/openzipkin/zipkin-go/noop.go
vendor/github.com/openzipkin/zipkin-go/noop.go
+25
-0
vendor/github.com/openzipkin/zipkin-go/propagation/propagation.go
...ithub.com/openzipkin/zipkin-go/propagation/propagation.go
+16
-0
vendor/github.com/openzipkin/zipkin-go/reporter/http/http.go
vendor/github.com/openzipkin/zipkin-go/reporter/http/http.go
+218
-0
vendor/github.com/openzipkin/zipkin-go/reporter/reporter.go
vendor/github.com/openzipkin/zipkin-go/reporter/reporter.go
+27
-0
vendor/github.com/openzipkin/zipkin-go/sample.go
vendor/github.com/openzipkin/zipkin-go/sample.go
+113
-0
vendor/github.com/openzipkin/zipkin-go/span.go
vendor/github.com/openzipkin/zipkin-go/span.go
+38
-0
vendor/github.com/openzipkin/zipkin-go/span_implementation.go
...or/github.com/openzipkin/zipkin-go/span_implementation.go
+78
-0
vendor/github.com/openzipkin/zipkin-go/span_options.go
vendor/github.com/openzipkin/zipkin-go/span_options.go
+74
-0
vendor/github.com/openzipkin/zipkin-go/tags.go
vendor/github.com/openzipkin/zipkin-go/tags.go
+23
-0
vendor/github.com/openzipkin/zipkin-go/tracer.go
vendor/github.com/openzipkin/zipkin-go/tracer.go
+173
-0
vendor/github.com/openzipkin/zipkin-go/tracer_options.go
vendor/github.com/openzipkin/zipkin-go/tracer_options.go
+124
-0
vendor/go.opencensus.io/AUTHORS
vendor/go.opencensus.io/AUTHORS
+1
-0
vendor/go.opencensus.io/CONTRIBUTING.md
vendor/go.opencensus.io/CONTRIBUTING.md
+56
-0
vendor/go.opencensus.io/Gopkg.lock
vendor/go.opencensus.io/Gopkg.lock
+231
-0
vendor/go.opencensus.io/Gopkg.toml
vendor/go.opencensus.io/Gopkg.toml
+36
-0
vendor/go.opencensus.io/LICENSE
vendor/go.opencensus.io/LICENSE
+202
-0
vendor/go.opencensus.io/README.md
vendor/go.opencensus.io/README.md
+263
-0
vendor/go.opencensus.io/appveyor.yml
vendor/go.opencensus.io/appveyor.yml
+24
-0
vendor/go.opencensus.io/exemplar/exemplar.go
vendor/go.opencensus.io/exemplar/exemplar.go
+78
-0
vendor/go.opencensus.io/exporter/zipkin/zipkin.go
vendor/go.opencensus.io/exporter/zipkin/zipkin.go
+194
-0
vendor/go.opencensus.io/go.mod
vendor/go.opencensus.io/go.mod
+25
-0
vendor/go.opencensus.io/go.sum
vendor/go.opencensus.io/go.sum
+48
-0
vendor/go.opencensus.io/internal/internal.go
vendor/go.opencensus.io/internal/internal.go
+37
-0
vendor/go.opencensus.io/internal/sanitize.go
vendor/go.opencensus.io/internal/sanitize.go
+50
-0
vendor/go.opencensus.io/internal/tagencoding/tagencoding.go
vendor/go.opencensus.io/internal/tagencoding/tagencoding.go
+72
-0
vendor/go.opencensus.io/internal/traceinternals.go
vendor/go.opencensus.io/internal/traceinternals.go
+52
-0
vendor/go.opencensus.io/opencensus.go
vendor/go.opencensus.io/opencensus.go
+21
-0
vendor/go.opencensus.io/plugin/ochttp/client.go
vendor/go.opencensus.io/plugin/ochttp/client.go
+117
-0
vendor/go.opencensus.io/plugin/ochttp/client_stats.go
vendor/go.opencensus.io/plugin/ochttp/client_stats.go
+135
-0
vendor/go.opencensus.io/plugin/ochttp/doc.go
vendor/go.opencensus.io/plugin/ochttp/doc.go
+19
-0
vendor/go.opencensus.io/plugin/ochttp/propagation/b3/b3.go
vendor/go.opencensus.io/plugin/ochttp/propagation/b3/b3.go
+123
-0
vendor/go.opencensus.io/plugin/ochttp/route.go
vendor/go.opencensus.io/plugin/ochttp/route.go
+51
-0
vendor/go.opencensus.io/plugin/ochttp/server.go
vendor/go.opencensus.io/plugin/ochttp/server.go
+440
-0
vendor/go.opencensus.io/plugin/ochttp/span_annotating_client_trace.go
...encensus.io/plugin/ochttp/span_annotating_client_trace.go
+169
-0
vendor/go.opencensus.io/plugin/ochttp/stats.go
vendor/go.opencensus.io/plugin/ochttp/stats.go
+265
-0
vendor/go.opencensus.io/plugin/ochttp/trace.go
vendor/go.opencensus.io/plugin/ochttp/trace.go
+228
-0
vendor/go.opencensus.io/stats/doc.go
vendor/go.opencensus.io/stats/doc.go
+69
-0
vendor/go.opencensus.io/stats/internal/record.go
vendor/go.opencensus.io/stats/internal/record.go
+25
-0
vendor/go.opencensus.io/stats/internal/validation.go
vendor/go.opencensus.io/stats/internal/validation.go
+28
-0
vendor/go.opencensus.io/stats/measure.go
vendor/go.opencensus.io/stats/measure.go
+123
-0
vendor/go.opencensus.io/stats/measure_float64.go
vendor/go.opencensus.io/stats/measure_float64.go
+36
-0
vendor/go.opencensus.io/stats/measure_int64.go
vendor/go.opencensus.io/stats/measure_int64.go
+36
-0
vendor/go.opencensus.io/stats/record.go
vendor/go.opencensus.io/stats/record.go
+69
-0
vendor/go.opencensus.io/stats/units.go
vendor/go.opencensus.io/stats/units.go
+25
-0
vendor/go.opencensus.io/stats/view/aggregation.go
vendor/go.opencensus.io/stats/view/aggregation.go
+120
-0
vendor/go.opencensus.io/stats/view/aggregation_data.go
vendor/go.opencensus.io/stats/view/aggregation_data.go
+235
-0
vendor/go.opencensus.io/stats/view/collector.go
vendor/go.opencensus.io/stats/view/collector.go
+87
-0
vendor/go.opencensus.io/stats/view/doc.go
vendor/go.opencensus.io/stats/view/doc.go
+47
-0
vendor/go.opencensus.io/stats/view/export.go
vendor/go.opencensus.io/stats/view/export.go
+58
-0
vendor/go.opencensus.io/stats/view/view.go
vendor/go.opencensus.io/stats/view/view.go
+185
-0
vendor/go.opencensus.io/stats/view/worker.go
vendor/go.opencensus.io/stats/view/worker.go
+229
-0
vendor/go.opencensus.io/stats/view/worker_commands.go
vendor/go.opencensus.io/stats/view/worker_commands.go
+183
-0
vendor/go.opencensus.io/tag/context.go
vendor/go.opencensus.io/tag/context.go
+67
-0
vendor/go.opencensus.io/tag/doc.go
vendor/go.opencensus.io/tag/doc.go
+26
-0
vendor/go.opencensus.io/tag/key.go
vendor/go.opencensus.io/tag/key.go
+35
-0
vendor/go.opencensus.io/tag/map.go
vendor/go.opencensus.io/tag/map.go
+197
-0
vendor/go.opencensus.io/tag/map_codec.go
vendor/go.opencensus.io/tag/map_codec.go
+234
-0
vendor/go.opencensus.io/tag/profile_19.go
vendor/go.opencensus.io/tag/profile_19.go
+31
-0
vendor/go.opencensus.io/tag/profile_not19.go
vendor/go.opencensus.io/tag/profile_not19.go
+23
-0
vendor/go.opencensus.io/tag/validate.go
vendor/go.opencensus.io/tag/validate.go
+56
-0
vendor/go.opencensus.io/trace/basetypes.go
vendor/go.opencensus.io/trace/basetypes.go
+114
-0
vendor/go.opencensus.io/trace/config.go
vendor/go.opencensus.io/trace/config.go
+48
-0
vendor/go.opencensus.io/trace/doc.go
vendor/go.opencensus.io/trace/doc.go
+53
-0
vendor/go.opencensus.io/trace/exemplar.go
vendor/go.opencensus.io/trace/exemplar.go
+43
-0
vendor/go.opencensus.io/trace/export.go
vendor/go.opencensus.io/trace/export.go
+90
-0
vendor/go.opencensus.io/trace/internal/internal.go
vendor/go.opencensus.io/trace/internal/internal.go
+21
-0
vendor/go.opencensus.io/trace/propagation/propagation.go
vendor/go.opencensus.io/trace/propagation/propagation.go
+108
-0
vendor/go.opencensus.io/trace/sampling.go
vendor/go.opencensus.io/trace/sampling.go
+75
-0
vendor/go.opencensus.io/trace/spanbucket.go
vendor/go.opencensus.io/trace/spanbucket.go
+130
-0
vendor/go.opencensus.io/trace/spanstore.go
vendor/go.opencensus.io/trace/spanstore.go
+306
-0
vendor/go.opencensus.io/trace/status_codes.go
vendor/go.opencensus.io/trace/status_codes.go
+37
-0
vendor/go.opencensus.io/trace/trace.go
vendor/go.opencensus.io/trace/trace.go
+516
-0
vendor/go.opencensus.io/trace/trace_go11.go
vendor/go.opencensus.io/trace/trace_go11.go
+32
-0
vendor/go.opencensus.io/trace/trace_nongo11.go
vendor/go.opencensus.io/trace/trace_nongo11.go
+25
-0
vendor/go.opencensus.io/trace/tracestate/tracestate.go
vendor/go.opencensus.io/trace/tracestate/tracestate.go
+147
-0
vendor/vendor.json
vendor/vendor.json
+140
-8
No files found.
vendor/git.autistici.org/ai3/go-common/clientutil/transport.go
View file @
a4b690e8
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"net/http"
"net/http"
"sync"
"sync"
"time"
"time"
"git.autistici.org/ai3/go-common/tracing"
)
)
// The transportCache is just a cache of http transports, each
// The transportCache is just a cache of http transports, each
...
@@ -29,12 +31,12 @@ func newTransportCache(tlsConfig *tls.Config) *transportCache {
...
@@ -29,12 +31,12 @@ func newTransportCache(tlsConfig *tls.Config) *transportCache {
}
}
func
(
m
*
transportCache
)
newTransport
(
addr
string
)
http
.
RoundTripper
{
func
(
m
*
transportCache
)
newTransport
(
addr
string
)
http
.
RoundTripper
{
return
&
http
.
Transport
{
return
tracing
.
WrapTransport
(
&
http
.
Transport
{
TLSClientConfig
:
m
.
tlsConfig
,
TLSClientConfig
:
m
.
tlsConfig
,
DialContext
:
func
(
ctx
context
.
Context
,
network
,
_
string
)
(
net
.
Conn
,
error
)
{
DialContext
:
func
(
ctx
context
.
Context
,
network
,
_
string
)
(
net
.
Conn
,
error
)
{
return
netDialContext
(
ctx
,
network
,
addr
)
return
netDialContext
(
ctx
,
network
,
addr
)
},
},
}
}
)
}
}
func
(
m
*
transportCache
)
getTransport
(
addr
string
)
http
.
RoundTripper
{
func
(
m
*
transportCache
)
getTransport
(
addr
string
)
http
.
RoundTripper
{
...
...
vendor/git.autistici.org/ai3/go-common/serverutil/http.go
View file @
a4b690e8
...
@@ -3,16 +3,18 @@ package serverutil
...
@@ -3,16 +3,18 @@ package serverutil
import
(
import
(
"context"
"context"
"crypto/tls"
"crypto/tls"
"fmt"
"io"
"io"
"log"
"log"
"net"
"net"
"net/http"
"net/http"
"net/http/pprof"
_
"net/http/pprof"
"os"
"os"
"os/signal"
"os/signal"
"syscall"
"syscall"
"time"
"time"
"git.autistici.org/ai3/go-common/tracing"
"github.com/coreos/go-systemd/daemon"
"github.com/coreos/go-systemd/daemon"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/promhttp"
...
@@ -77,6 +79,10 @@ func (config *ServerConfig) buildHTTPServer(h http.Handler) (*http.Server, error
...
@@ -77,6 +79,10 @@ func (config *ServerConfig) buildHTTPServer(h http.Handler) (*http.Server, error
// the listener, otherwise it will handle graceful termination on
// the listener, otherwise it will handle graceful termination on
// SIGINT or SIGTERM and return nil.
// SIGINT or SIGTERM and return nil.
func
Serve
(
h
http
.
Handler
,
config
*
ServerConfig
,
addr
string
)
error
{
func
Serve
(
h
http
.
Handler
,
config
*
ServerConfig
,
addr
string
)
error
{
// Wrap with tracing handler (exclude metrics and other
// debugging endpoints).
h
=
tracing
.
WrapHandler
(
h
,
guessEndpointName
(
addr
))
// Create the HTTP server.
// Create the HTTP server.
srv
,
err
:=
config
.
buildHTTPServer
(
h
)
srv
,
err
:=
config
.
buildHTTPServer
(
h
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -139,8 +145,10 @@ func defaultHandler(h http.Handler) http.Handler {
...
@@ -139,8 +145,10 @@ func defaultHandler(h http.Handler) http.Handler {
// Add an endpoint to serve Prometheus metrics.
// Add an endpoint to serve Prometheus metrics.
root
.
Handle
(
"/metrics"
,
promhttp
.
Handler
())
root
.
Handle
(
"/metrics"
,
promhttp
.
Handler
())
// Add the net/http/pprof debug handlers.
// Let the default net/http handler deal with /debug/
root
.
Handle
(
"/debug/pprof/"
,
pprof
.
Handler
(
""
))
// URLs. Packages such as net/http/pprof register their
// handlers there in ways that aren't reproducible.
root
.
Handle
(
"/debug/"
,
http
.
DefaultServeMux
)
// Forward everything else to the main handler, adding
// Forward everything else to the main handler, adding
// Prometheus instrumentation (requests to /metrics and
// Prometheus instrumentation (requests to /metrics and
...
@@ -151,6 +159,18 @@ func defaultHandler(h http.Handler) http.Handler {
...
@@ -151,6 +159,18 @@ func defaultHandler(h http.Handler) http.Handler {
return
root
return
root
}
}
func
guessEndpointName
(
addr
string
)
string
{
_
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
return
addr
}
host
,
err
:=
os
.
Hostname
()
if
err
!=
nil
{
return
addr
}
return
fmt
.
Sprintf
(
"%s:%s"
,
host
,
port
)
}
// HTTP-related metrics.
// HTTP-related metrics.
var
(
var
(
// Since we instrument the root HTTP handler, we don't really
// Since we instrument the root HTTP handler, we don't really
...
...
vendor/git.autistici.org/ai3/go-common/tracing/tracing.go
0 → 100644
View file @
a4b690e8
package
tracing
import
(
"encoding/json"
"errors"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"sync"
openzipkin
"github.com/openzipkin/zipkin-go"
zipkinHTTP
"github.com/openzipkin/zipkin-go/reporter/http"
"go.opencensus.io/exporter/zipkin"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"
)
var
(
// Enabled reports whether tracing is globally enabled or not.
Enabled
bool
// The active tracing configuration, if Enabled is true.
config
tracingConfig
initOnce
sync
.
Once
)
const
globalTracingConfigPath
=
"/etc/tracing/client.conf"
type
tracingConfig
struct
{
ReportURL
string
`json:"report_url"`
}
// Read the global tracing configuration file. Its location is
// hardcoded, but it can be overriden using the TRACING_CONFIG
// environment variable.
func
readTracingConfig
()
error
{
// Read and decode configuration.
cfgPath
:=
globalTracingConfigPath
if
s
:=
os
.
Getenv
(
"TRACING_CONFIG"
);
s
!=
""
{
cfgPath
=
s
}
data
,
err
:=
ioutil
.
ReadFile
(
cfgPath
)
if
err
!=
nil
{
return
err
}
if
err
:=
json
.
Unmarshal
(
data
,
&
config
);
err
!=
nil
{
log
.
Printf
(
"warning: error in tracing configuration: %v, tracing disabled"
,
err
)
return
err
}
if
config
.
ReportURL
==
""
{
log
.
Printf
(
"warning: tracing configuration contains no report_url, tracing disabled"
)
return
errors
.
New
(
"no report_url"
)
}
return
nil
}
// Compute the service name for Zipkin: this is usually the program
// name (without path), but it can be overriden by the TRACING_SERVICE
// environment variable.
func
getServiceName
()
string
{
if
s
:=
os
.
Getenv
(
"TRACING_SERVICE"
);
s
!=
""
{
return
s
}
return
filepath
.
Base
(
os
.
Args
[
0
])
}
// Initialize tracing. Tracing will be enabled if the system-wide
// tracing configuration file is present and valid. Explicitly set
// TRACING_ENABLE=0 in the environment to disable tracing.
//
// We need to check the configuration as soon as possible, because
// it's likely that client transports are created before HTTP servers,
// and we need to wrap them with opencensus at creation time.
func
init
()
{
// Kill switch from environment.
if
s
:=
os
.
Getenv
(
"TRACING_ENABLE"
);
s
==
"0"
{
return
}
if
err
:=
readTracingConfig
();
err
!=
nil
{
return
}
Enabled
=
true
}
func
initTracing
(
endpointAddr
string
)
{
initOnce
.
Do
(
func
()
{
localEndpoint
,
err
:=
openzipkin
.
NewEndpoint
(
getServiceName
(),
endpointAddr
)
if
err
!=
nil
{
log
.
Printf
(
"warning: error creating tracing endpoint: %v, tracing disabled"
,
err
)
return
}
reporter
:=
zipkinHTTP
.
NewReporter
(
config
.
ReportURL
)
ze
:=
zipkin
.
NewExporter
(
reporter
,
localEndpoint
)
trace
.
RegisterExporter
(
ze
)
trace
.
ApplyConfig
(
trace
.
Config
{
DefaultSampler
:
trace
.
AlwaysSample
()})
log
.
Printf
(
"tracing enabled (report_url %s)"
,
config
.
ReportURL
)
Enabled
=
true
})
}
// WrapTransport optionally wraps a http.RoundTripper with OpenCensus
// tracing functionality, if it is globally enabled.
func
WrapTransport
(
t
http
.
RoundTripper
)
http
.
RoundTripper
{
if
Enabled
{
t
=
&
ochttp
.
Transport
{
Base
:
t
}
}
return
t
}
// WrapHandler wraps a http.Handler with OpenCensus tracing
// functionality, if globally enabled.
func
WrapHandler
(
h
http
.
Handler
,
endpointAddr
string
)
http
.
Handler
{
if
Enabled
{
initTracing
(
endpointAddr
)
h
=
&
ochttp
.
Handler
{
Handler
:
h
}
}
return
h
}
vendor/github.com/openzipkin/zipkin-go/LICENSE
0 → 100644
View file @
a4b690e8
This diff is collapsed.
Click to expand it.
vendor/github.com/openzipkin/zipkin-go/Makefile
0 → 100644
View file @
a4b690e8
.DEFAULT_GOAL
:=
test
.PHONY
:
test
test
:
go
test
-v
-race
-cover
./...
.PHONY
:
bench
bench
:
go
test
-v
-run
-
-bench
.
-benchmem
./...
.PHONY
:
protoc
protoc
:
protoc
--go_out
=
.
proto/v2/zipkin.proto
.PHONY
:
lint
lint
:
# Ignore grep's exit code since no match returns 1.
-
if
[[
!
$TRAVIS_GO_VERSION
=
1.8
*
]]
;
then
echo
'linting...'
;
golint ./...
;
fi
.PHONY
:
vet
vet
:
go vet ./...
.PHONY
:
all
all
:
vet lint test bench
.PHONY
:
example
vendor/github.com/openzipkin/zipkin-go/README.md
0 → 100644
View file @
a4b690e8
# Zipkin Library for Go
[

](https://travis-ci.org/openzipkin/zipkin-go)
[

](https://circleci.com/gh/openzipkin/zipkin-go)
[

](https://ci.appveyor.com/project/basvanbeek/zipkin-go)
[

](https://coveralls.io/github/openzipkin/zipkin-go?branch=master)
[

](https://goreportcard.com/report/github.com/openzipkin/zipkin-go)
[

](https://godoc.org/github.com/openzipkin/zipkin-go)
[

](https://gitter.im/openzipkin/zipkin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[

](https://sourcegraph.com/github.com/openzipkin/zipkin-go?badge)
Zipkin Go is the official Go Tracer implementation for Zipkin, supported by the
OpenZipkin community.
## package organization
`zipkin-go`
is built with interoperability in mind within the OpenZipkin
community and even 3rd parties, the library consists of several packages.
The main tracing implementation can be found in the root folder of this
repository. Reusable parts not considered core implementation or deemed
beneficiary for usage by others are placed in their own packages within this
repository.
### model
This library implements the Zipkin V2 Span Model which is available in the model
package. It contains a Go data model compatible with the Zipkin V2 API and can
automatically sanitize, parse and (de)serialize to and from the required JSON
representation as used by the official Zipkin V2 Collectors.
### propagation
The propagation package and B3 subpackage hold the logic for propagating
SpanContext (span identifiers and sampling flags) between services participating
in traces. Currently Zipkin B3 Propagation is supported for HTTP and GRPC.
### middleware
The middleware subpackages contain officially supported middleware handlers and
tracing wrappers.
#### http
An easy to use http.Handler middleware for tracing server side requests is
provided. This allows one to use this middleware in applications using
standard library servers as well as most available higher level frameworks. Some
frameworks will have their own instrumentation and middleware that maps better
for their ecosystem.
For HTTP client operations
`NewTransport`
can return a
`http.RoundTripper`
implementation that can either wrap the standard http.Client's Transport or a
custom provided one and add per request tracing. Since HTTP Requests can have
one or multiple redirects it is advisable to always enclose HTTP Client calls
with a
`Span`
either around the
`*http.Client`
call level or parent function
level.
For convenience
`NewClient`
is provided which returns a HTTP Client which embeds
`*http.Client`
and provides an
`application span`
around the HTTP calls when
calling the
`DoWithAppSpan()`
method.
#### grpc
gRPC middleware / interceptors are planned for the near future.
### reporter
The reporter package holds the interface which the various Reporter
implementations use. It is exported into its own package as it can be used by
3rd parties to use these Reporter packages in their own libraries for exporting
to the Zipkin ecosystem. The
`zipkin-go`
tracer also uses the interface to
accept 3rd party Reporter implementations.
#### HTTP Reporter
Most common Reporter type used by Zipkin users transporting Spans to the Zipkin
server using JSON over HTTP. The reporter holds a buffer and reports to the
backend asynchronously.
#### Kafka Reporter
High performance Reporter transporting Spans to the Zipkin server using a Kafka
Producer digesting JSON V2 Spans. The reporter uses the
[
Sarama async producer
](
https://godoc.org/github.com/Shopify/sarama#AsyncProducer
)
underneath.
## usage and examples
[
HTTP Server Example
](
example_httpserver_test.go
)
vendor/github.com/openzipkin/zipkin-go/appveyor.yml
0 → 100644
View file @
a4b690e8
version
:
v1.0.0.{build}
platform
:
x64
clone_folder
:
c:\gopath\src\github.com\openzipkin\zipkin-go
environment
:
GOPATH
:
c:\gopath
install
:
-
echo %PATH%
-
echo %GOPATH%
-
set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
-
go version
-
go env
build_script
:
-
go get -t -v ./...
-
go vet ./...
-
go test -v -race -cover ./...
-
go test -v -run - -bench . -benchmem ./...
vendor/github.com/openzipkin/zipkin-go/circle.yml
0 → 100644
View file @
a4b690e8
version
:
2
jobs
:
build
:
working_directory
:
/go/src/github.com/openzipkin/zipkin-go
parallelism
:
1
docker
:
-
image
:
circleci/golang
steps
:
-
checkout
-
run
:
go get -t -v -d ./...
-
run
:
make vet test bench
vendor/github.com/openzipkin/zipkin-go/context.go
0 → 100644
View file @
a4b690e8
package
zipkin
import
(
"context"
)
// SpanFromContext retrieves a Zipkin Span from Go's context propagation
// mechanism if found. If not found, returns nil.
func
SpanFromContext
(
ctx
context
.
Context
)
Span
{
if
s
,
ok
:=
ctx
.
Value
(
spanKey
)
.
(
Span
);
ok
{
return
s
}
return
nil
}
// NewContext stores a Zipkin Span into Go's context propagation mechanism.
func
NewContext
(
ctx
context
.
Context
,
s
Span
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
spanKey
,
s
)
}
type
ctxKey
struct
{}
var
spanKey
=
ctxKey
{}
vendor/github.com/openzipkin/zipkin-go/doc.go
0 → 100644
View file @
a4b690e8
/*
Package zipkin implements a native Zipkin instrumentation library for Go.
See https://zipkin.io for more information about Zipkin.
*/
package
zipkin
vendor/github.com/openzipkin/zipkin-go/endpoint.go
0 → 100644
View file @
a4b690e8
package
zipkin
import
(
"net"
"strconv"
"strings"
"github.com/openzipkin/zipkin-go/model"
)
// NewEndpoint creates a new endpoint given the provided serviceName and
// hostPort.
func
NewEndpoint
(
serviceName
string
,
hostPort
string
)
(
*
model
.
Endpoint
,
error
)
{
e
:=
&
model
.
Endpoint
{
ServiceName
:
serviceName
,
}
if
hostPort
==
""
||
hostPort
==
":0"
{
if
serviceName
==
""
{
// if all properties are empty we should not have an Endpoint object.
return
nil
,
nil
}
return
e
,
nil
}
if
strings
.
IndexByte
(
hostPort
,
':'
)
<
0
{
hostPort
+=
":0"
}
host
,
port
,
err
:=
net
.
SplitHostPort
(
hostPort
)
if
err
!=
nil
{
return
nil
,
err
}
p
,
err
:=
strconv
.
ParseUint
(
port
,
10
,
16
)
if
err
!=
nil
{
return
nil
,
err
}
e
.
Port
=
uint16
(
p
)
addrs
,
err
:=
net
.
LookupIP
(
host
)
if
err
!=
nil
{
return
nil
,
err
}
for
i
:=
range
addrs
{
addr
:=
addrs
[
i
]
.
To4
()
if
addr
==
nil
{
// IPv6 - 16 bytes
if
e
.
IPv6
==
nil
{
e
.
IPv6
=
addrs
[
i
]
.
To16
()
}
}
else
{
// IPv4 - 4 bytes
if
e
.
IPv4
==
nil
{
e
.
IPv4
=
addr
}
}
if
e
.
IPv4
!=
nil
&&
e
.
IPv6
!=
nil
{
// Both IPv4 & IPv6 have been set, done...
break
}
}
return
e
,
nil
}
vendor/github.com/openzipkin/zipkin-go/idgenerator/idgenerator.go
0 → 100644
View file @
a4b690e8
/*
Package idgenerator contains several Span and Trace ID generators which can be
used by the Zipkin tracer. Additional third party generators can be plugged in
if they adhere to the IDGenerator interface.
*/
package
idgenerator
import
(
"math/rand"
"sync"
"time"
"github.com/openzipkin/zipkin-go/model"
)
var
(
seededIDGen
=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
// NewSource returns a new pseudo-random Source seeded with the given value.
// Unlike the default Source used by top-level functions, this source is not
// safe for concurrent use by multiple goroutines. Hence the need for a mutex.
seededIDLock
sync
.
Mutex
)
// IDGenerator interface can be used to provide the Zipkin Tracer with custom
// implementations to generate Span and Trace IDs.
type
IDGenerator
interface
{
SpanID
(
traceID
model
.
TraceID
)
model
.
ID
// Generates a new Span ID
TraceID
()
model
.
TraceID
// Generates a new Trace ID
}
// NewRandom64 returns an ID Generator which can generate 64 bit trace and span
// id's
func
NewRandom64
()
IDGenerator
{
return
&
randomID64
{}
}
// NewRandom128 returns an ID Generator which can generate 128 bit trace and 64
// bit span id's
func
NewRandom128
()
IDGenerator
{
return
&
randomID128
{}
}
// NewRandomTimestamped generates 128 bit time sortable traceid's and 64 bit
// spanid's.
func
NewRandomTimestamped
()
IDGenerator
{
return
&
randomTimestamped
{}
}
// randomID64 can generate 64 bit traceid's and 64 bit spanid's.
type
randomID64
struct
{}
func
(
r
*
randomID64
)
TraceID
()
(
id
model
.
TraceID
)
{
seededIDLock
.
Lock
()
id
=
model
.
TraceID
{
Low
:
uint64
(
seededIDGen
.
Int63
()),
}
seededIDLock
.
Unlock
()
return
}
func
(
r
*
randomID64
)
SpanID
(
traceID
model
.
TraceID
)
(
id
model
.
ID
)
{
if
!
traceID
.
Empty
()
{
return
model
.
ID
(
traceID
.
Low
)
}
seededIDLock
.
Lock
()
id
=
model
.
ID
(
seededIDGen
.
Int63
())
seededIDLock
.
Unlock
()
return
}
// randomID128 can generate 128 bit traceid's and 64 bit spanid's.
type
randomID128
struct
{}
func
(
r
*
randomID128
)
TraceID
()
(
id
model
.
TraceID
)
{
seededIDLock
.
Lock
()
id
=
model
.
TraceID
{
High
:
uint64
(
seededIDGen
.
Int63
()),
Low
:
uint64
(
seededIDGen
.
Int63
()),
}
seededIDLock
.
Unlock
()
return
}
func
(
r
*
randomID128
)
SpanID
(
traceID
model
.
TraceID
)
(
id
model
.
ID
)
{
if
!
traceID
.
Empty
()
{
return
model
.
ID
(
traceID
.
Low
)
}
seededIDLock
.
Lock
()
id
=
model
.
ID
(
seededIDGen
.
Int63
())
seededIDLock
.
Unlock
()
return
}
// randomTimestamped can generate 128 bit time sortable traceid's compatible
// with AWS X-Ray and 64 bit spanid's.
type
randomTimestamped
struct
{}
func
(
t
*
randomTimestamped
)
TraceID
()
(
id
model
.
TraceID
)
{
seededIDLock
.
Lock
()
id
=
model
.
TraceID
{
High
:
uint64
(
time
.
Now
()
.
Unix
()
<<
32
)
+
uint64
(
seededIDGen
.
Int31
()),
Low
:
uint64
(
seededIDGen
.
Int63
()),
}
seededIDLock
.
Unlock
()
return
}
func
(
t
*
randomTimestamped
)
SpanID
(
traceID
model
.
TraceID
)
(
id
model
.
ID
)
{
if
!
traceID
.
Empty
()
{
return
model
.
ID
(
traceID
.
Low
)
}
seededIDLock
.
Lock
()
id
=
model
.
ID
(
seededIDGen
.
Int63
())
seededIDLock
.
Unlock
()
return
}
vendor/github.com/openzipkin/zipkin-go/model/annotation.go
0 → 100644
View file @
a4b690e8
package
model
import
(
"encoding/json"
"errors"
"time"
)
// ErrValidTimestampRequired error
var
ErrValidTimestampRequired
=
errors
.
New
(
"valid annotation timestamp required"
)
// Annotation associates an event that explains latency with a timestamp.
type
Annotation
struct
{
Timestamp
time
.
Time
Value
string
}
// MarshalJSON implements custom JSON encoding
func
(
a
*
Annotation
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
&
struct
{
Timestamp
int64
`json:"timestamp"`
Value
string
`json:"value"`
}{
Timestamp
:
a
.
Timestamp
.
Round
(
time
.
Microsecond
)
.
UnixNano
()
/
1e3
,
Value
:
a
.
Value
,
})
}
// UnmarshalJSON implements custom JSON decoding
func
(
a
*
Annotation
)
UnmarshalJSON
(
b
[]
byte
)
error
{
type
Alias
Annotation
annotation
:=
&
struct
{
TimeStamp
uint64
`json:"timestamp"`
*
Alias
}{
Alias
:
(
*
Alias
)(
a
),
}
if
err
:=
json
.
Unmarshal
(
b
,
&
annotation
);
err
!=
nil
{
return
err
}
if
annotation
.
TimeStamp
<
1
{
return
ErrValidTimestampRequired
}
a
.
Timestamp
=
time
.
Unix
(
0
,
int64
(
annotation
.
TimeStamp
)
*
1e3
)
return
nil
}
vendor/github.com/openzipkin/zipkin-go/model/doc.go
0 → 100644
View file @
a4b690e8
/*
Package model contains the Zipkin V2 model which is used by the Zipkin Go
tracer implementation.
Third party instrumentation libraries can use the model and transport packages
found in this Zipkin Go library to directly interface with the Zipkin Server or
Zipkin Collectors without the need to use the tracer implementation itself.
*/
package
model
vendor/github.com/openzipkin/zipkin-go/model/endpoint.go
0 → 100644
View file @
a4b690e8
package
model
import
"net"
// Endpoint holds the network context of a node in the service graph.
type
Endpoint
struct
{
ServiceName
string
`json:"serviceName,omitempty"`