-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.*: 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]>
- Loading branch information
Showing
7 changed files
with
119 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package lightstep | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/lightstep/lightstep-tracer-go" | ||
"github.com/opentracing/opentracing-go" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// Config - YAML configuration. | ||
type Config struct { | ||
// AccessToken is the unique API key for your LightStep project. It is | ||
// available on your account page at https://app.lightstep.com/account. | ||
AccessToken string `yaml:"access_token"` | ||
|
||
// Collector is the host, port, and plaintext option to use | ||
// for the collector. | ||
Collector lightstep.Endpoint `yaml:"collector"` | ||
} | ||
|
||
// Tracer wraps the Lightstep tracer and the context. | ||
type Tracer struct { | ||
lightstep.Tracer | ||
ctx context.Context | ||
} | ||
|
||
// Close synchronously flushes the Lightstep tracer, then terminates it. | ||
func (t *Tracer) Close() error { | ||
t.Tracer.Close(t.ctx) | ||
|
||
return nil | ||
} | ||
|
||
// NewTracer creates a Tracer with the options present in the YAML config. | ||
func NewTracer(ctx context.Context, yamlConfig []byte) (opentracing.Tracer, io.Closer, error) { | ||
config := Config{} | ||
if err := yaml.Unmarshal(yamlConfig, &config); err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
options := lightstep.Options{ | ||
AccessToken: config.AccessToken, | ||
Collector: config.Collector, | ||
} | ||
lighstepTracer, err := lightstep.CreateTracer(options) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
t := &Tracer{ | ||
lighstepTracer, | ||
ctx, | ||
} | ||
return t, t, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters