Skip to content

Commit f840e18

Browse files
antonioGiedriusS
authored andcommitted
.*: Add support for tracing with Lightstep (#1678)
* Add support for tracing with Lightstep Signed-off-by: Antonio Santos <[email protected]> * Remove type cast Signed-off-by: Antonio Santos <[email protected]> * Add documentation for the exported methods and types Signed-off-by: Antonio Santos <[email protected]> * Apply suggestions from @bwplotka Co-Authored-By: Bartlomiej Plotka <[email protected]> Signed-off-by: Antonio Santos <[email protected]> * Inline variable Co-Authored-By: Povilas Versockas <[email protected]> Signed-off-by: Antonio Santos <[email protected]> * Update lightstep library and add proper error handling lightstep/lightstep-tracer-go#228 introduced a new method to create a Tracer that returns an error when it does not succeed, instead of nil Signed-off-by: Antonio Santos <[email protected]> * Remove unused import Signed-off-by: Antonio Santos <[email protected]>
1 parent ee72731 commit f840e18

File tree

7 files changed

+119
-154
lines changed

7 files changed

+119
-154
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
1313

1414
### Added
1515

16+
- [#1678](https://github.com/thanos-io/thanos/pull/1678) Add Lightstep as a tracing provider.
1617
- [#1687](https://github.com/thanos-io/thanos/pull/1687) Add a new `--grpc-grace-period` CLI option to components which serve gRPC to set how long to wait until gRPC Server shuts down.
1718
- [#1660](https://github.com/thanos-io/thanos/pull/1660) Add a new `--prometheus.ready_timeout` CLI option to the sidecar to set how long to wait until Prometheus starts up.
1819
- [#1573](https://github.com/thanos-io/thanos/pull/1573) `AliYun OSS` object storage, see [documents](docs/storage.md#aliyun-oss) for further information.

docs/tracing.md

+19
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,22 @@ config:
101101
service_version: ""
102102
service_environment: ""
103103
```
104+
105+
### Lightstep
106+
107+
Client for [Ligthstep](https://lightstep.com).
108+
109+
In order to configure Thanos to interact with Lightstep you need to provide at least an [access token](https://docs.lightstep.com/docs/create-and-use-access-tokens) in the configuration file. The `collector` key is optional and used when you have on-premise satellites.
110+
111+
[embedmd]:# (flags/config_tracing_lightstep.txt yaml)
112+
```yaml
113+
type: LIGHTSTEP
114+
config:
115+
access_token: ""
116+
collector:
117+
scheme: ""
118+
host: ""
119+
port: 0
120+
plaintext: false
121+
custom_ca_cert_file: ""
122+
```

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
github.com/jstemmer/go-junit-report v0.9.1 // indirect
5050
github.com/julienschmidt/httprouter v1.3.0 // indirect
5151
github.com/leanovate/gopter v0.2.4
52+
github.com/lightstep/lightstep-tracer-go v0.18.0
5253
github.com/lovoo/gcloud-opentracing v0.3.0
5354
github.com/mattn/go-ieproxy v0.0.0-20191113090002-7c0f6868bffe // indirect
5455
github.com/mattn/go-runewidth v0.0.6 // indirect

go.sum

+35-154
Large diffs are not rendered by default.

pkg/tracing/client/factory.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/prometheus/client_golang/prometheus"
1313
"github.com/thanos-io/thanos/pkg/tracing/elasticapm"
1414
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
15+
"github.com/thanos-io/thanos/pkg/tracing/lightstep"
1516
"github.com/thanos-io/thanos/pkg/tracing/stackdriver"
1617
"gopkg.in/yaml.v2"
1718
)
@@ -22,6 +23,7 @@ const (
2223
STACKDRIVER TracingProvider = "STACKDRIVER"
2324
JAEGER TracingProvider = "JAEGER"
2425
ELASTIC_APM TracingProvider = "ELASTIC_APM"
26+
LIGHTSTEP TracingProvider = "LIGHTSTEP"
2527
)
2628

2729
type TracingConfig struct {
@@ -53,6 +55,8 @@ func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Regis
5355
return jaeger.NewTracer(ctx, logger, metrics, config)
5456
case string(ELASTIC_APM):
5557
return elasticapm.NewTracer(config)
58+
case string(LIGHTSTEP):
59+
return lightstep.NewTracer(ctx, config)
5660
default:
5761
return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type)
5862
}

pkg/tracing/lightstep/lightstep.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package lightstep
2+
3+
import (
4+
"context"
5+
"io"
6+
7+
"github.com/lightstep/lightstep-tracer-go"
8+
"github.com/opentracing/opentracing-go"
9+
"gopkg.in/yaml.v2"
10+
)
11+
12+
// Config - YAML configuration.
13+
type Config struct {
14+
// AccessToken is the unique API key for your LightStep project. It is
15+
// available on your account page at https://app.lightstep.com/account.
16+
AccessToken string `yaml:"access_token"`
17+
18+
// Collector is the host, port, and plaintext option to use
19+
// for the collector.
20+
Collector lightstep.Endpoint `yaml:"collector"`
21+
}
22+
23+
// Tracer wraps the Lightstep tracer and the context.
24+
type Tracer struct {
25+
lightstep.Tracer
26+
ctx context.Context
27+
}
28+
29+
// Close synchronously flushes the Lightstep tracer, then terminates it.
30+
func (t *Tracer) Close() error {
31+
t.Tracer.Close(t.ctx)
32+
33+
return nil
34+
}
35+
36+
// NewTracer creates a Tracer with the options present in the YAML config.
37+
func NewTracer(ctx context.Context, yamlConfig []byte) (opentracing.Tracer, io.Closer, error) {
38+
config := Config{}
39+
if err := yaml.Unmarshal(yamlConfig, &config); err != nil {
40+
return nil, nil, err
41+
}
42+
43+
options := lightstep.Options{
44+
AccessToken: config.AccessToken,
45+
Collector: config.Collector,
46+
}
47+
lighstepTracer, err := lightstep.CreateTracer(options)
48+
if err != nil {
49+
return nil, nil, err
50+
}
51+
52+
t := &Tracer{
53+
lighstepTracer,
54+
ctx,
55+
}
56+
return t, t, nil
57+
}

scripts/cfggen/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
trclient "github.com/thanos-io/thanos/pkg/tracing/client"
2424
"github.com/thanos-io/thanos/pkg/tracing/elasticapm"
2525
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
26+
"github.com/thanos-io/thanos/pkg/tracing/lightstep"
2627
"github.com/thanos-io/thanos/pkg/tracing/stackdriver"
2728
kingpin "gopkg.in/alecthomas/kingpin.v2"
2829
yaml "gopkg.in/yaml.v2"
@@ -42,6 +43,7 @@ var (
4243
trclient.JAEGER: jaeger.Config{},
4344
trclient.STACKDRIVER: stackdriver.Config{},
4445
trclient.ELASTIC_APM: elasticapm.Config{},
46+
trclient.LIGHTSTEP: lightstep.Config{},
4547
}
4648
)
4749

0 commit comments

Comments
 (0)