forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support Elastic APM for tracing (thanos-io#1482)
* support Elastic APM for tracing Signed-off-by: Wing924 <weihe924stephen@gmail.com> * fix docs Signed-off-by: Wing924 <weihe924stephen@gmail.com> * retry job Signed-off-by: Wing924 <weihe924stephen@gmail.com> * format code Signed-off-by: Wing924 <weihe924stephen@gmail.com>
- Loading branch information
Showing
6 changed files
with
89 additions
and
3 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,43 @@ | ||
package elasticapm | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/opentracing/opentracing-go" | ||
"go.elastic.co/apm" | ||
"go.elastic.co/apm/module/apmot" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
ServiceName string `yaml:"service_name"` | ||
ServiceVersion string `yaml:"service_version"` | ||
ServiceEnvironment string `yaml:"service_environment"` | ||
} | ||
|
||
func NewTracer(conf []byte) (opentracing.Tracer, io.Closer, error) { | ||
config := Config{} | ||
if err := yaml.Unmarshal(conf, &config); err != nil { | ||
return nil, nil, err | ||
} | ||
tracer, err := apm.NewTracerOptions(apm.TracerOptions{ | ||
ServiceName: config.ServiceName, | ||
ServiceVersion: config.ServiceVersion, | ||
ServiceEnvironment: config.ServiceEnvironment, | ||
}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
return apmot.New(apmot.WithTracer(tracer)), tracerCloser{tracer}, nil | ||
} | ||
|
||
type tracerCloser struct { | ||
tracer *apm.Tracer | ||
} | ||
|
||
func (t tracerCloser) Close() error { | ||
if t.tracer != nil { | ||
t.tracer.Close() | ||
} | ||
return 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