Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
go-common
Commits
2c5f006b
Commit
2c5f006b
authored
2 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Switch to go.opentelemetry.io API for tracing
parent
1eb6de82
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
go.mod
+6
-4
6 additions, 4 deletions
go.mod
go.sum
+42
-64
42 additions, 64 deletions
go.sum
tracing/tracing.go
+19
-18
19 additions, 18 deletions
tracing/tracing.go
with
67 additions
and
86 deletions
go.mod
+
6
−
4
View file @
2c5f006b
module
git.autistici.org/ai3/go-common
go 1.1
1
go 1.1
4
require (
contrib.go.opencensus.io/exporter/zipkin
v0.1.2
github.com/NYTimes/gziphandler
v1.1.1
github.com/amoghe/go-crypt
v0.0.0-20220222110647-20eada5f5964
github.com/bbrks/wrap/v2
v2.5.0
...
...
@@ -15,14 +14,17 @@ require (
github.com/go-asn1-ber/asn1-ber
v1.5.4
github.com/go-ldap/ldap/v3
v3.4.4
github.com/gofrs/flock
v0.8.0 // indirect
github.com/google/go-cmp
v0.5.
6
github.com/google/go-cmp
v0.5.
8
github.com/lunixbochs/struc
v0.0.0-20200707160740-784aaebc1d40
github.com/miscreant/miscreant.go
v0.0.0-20200214223636-26d376326b75
github.com/openzipkin/zipkin-go
v0.4.0
github.com/prometheus/client_golang
v1.12.2
github.com/russross/blackfriday/v2
v2.1.0
github.com/theckman/go-flock
v0.8.1
go.opencensus.io
v0.23.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
v0.34.0
go.opentelemetry.io/otel
v1.9.1-0.20220810155701-d96e8d2912af
go.opentelemetry.io/otel/exporters/zipkin
v1.9.0
go.opentelemetry.io/otel/sdk
v1.9.0
golang.org/x/crypto
v0.0.0-20220622213112-05595931fe9d
golang.org/x/sync
v0.0.0-20220722155255-886fb9371eb4
)
This diff is collapsed.
Click to expand it.
go.sum
+
42
−
64
View file @
2c5f006b
This diff is collapsed.
Click to expand it.
tracing/tracing.go
+
19
−
18
View file @
2c5f006b
...
...
@@ -11,11 +11,10 @@ import (
"strconv"
"sync"
openzipkin
"github.com/openzipkin/zipkin-go"
zipkinHTTP
"github.com/openzipkin/zipkin-go/reporter/http"
"contrib.go.opencensus.io/exporter/zipkin"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"
othttp
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/zipkin"
"go.opentelemetry.io/otel/sdk/trace"
)
var
(
...
...
@@ -97,31 +96,33 @@ func initTracing(endpointAddr string) {
return
}
initOnce
.
Do
(
func
()
{
localEndpoint
,
err
:=
open
zipkin
.
New
Endpoint
(
getServiceName
(),
endpointAddr
)
ze
,
err
:=
zipkin
.
New
(
config
.
ReportURL
)
if
err
!=
nil
{
log
.
Printf
(
"
warning:
error creating
trac
in
g
e
ndpoint: %v, tracing disabled
"
,
err
)
log
.
Printf
(
"error creating
Zipk
in e
xporter: %v
"
,
err
)
return
}
reporter
:=
zipkinHTTP
.
NewReporter
(
config
.
ReportURL
)
ze
:=
zipkin
.
NewExporter
(
reporter
,
localEndpoint
)
trace
.
RegisterExporter
(
ze
)
var
tc
trace
.
Config
var
sampler
trace
.
Sampler
switch
config
.
Sample
{
case
""
,
"always"
:
tc
.
DefaultS
ampler
=
trace
.
AlwaysSample
()
s
ampler
=
trace
.
AlwaysSample
()
case
"never"
:
tc
.
DefaultS
ampler
=
trace
.
NeverSample
()
s
ampler
=
trace
.
NeverSample
()
default
:
frac
,
err
:=
strconv
.
ParseFloat
(
config
.
Sample
,
64
)
if
err
!=
nil
{
log
.
Printf
(
"warning: error in tracing configuration: sample: %v, tracing disabled"
,
err
)
return
}
tc
.
DefaultS
ampler
=
trace
.
ProbabilitySampler
(
frac
)
s
ampler
=
trace
.
TraceIDRatioBased
(
frac
)
}
trace
.
ApplyConfig
(
tc
)
tp
:=
trace
.
NewTracerProvider
(
trace
.
WithSampler
(
sampler
),
trace
.
WithBatcher
(
ze
),
)
otel
.
SetTracerProvider
(
tp
)
log
.
Printf
(
"tracing enabled (report_url %s)"
,
config
.
ReportURL
)
...
...
@@ -138,7 +139,7 @@ func Init() {
// tracing functionality, if it is globally enabled.
func
WrapTransport
(
t
http
.
RoundTripper
)
http
.
RoundTripper
{
if
Enabled
{
t
=
&
oc
http
.
Transport
{
Base
:
t
}
t
=
ot
http
.
New
Transport
(
t
)
}
return
t
}
...
...
@@ -148,7 +149,7 @@ func WrapTransport(t http.RoundTripper) http.RoundTripper {
func
WrapHandler
(
h
http
.
Handler
,
endpointAddr
string
)
http
.
Handler
{
if
Enabled
{
initTracing
(
endpointAddr
)
h
=
&
oc
http
.
Handler
{
Handler
:
h
}
h
=
ot
http
.
New
Handler
(
h
,
getServiceName
())
}
return
h
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment