Skip to content

Commit

Permalink
Add tracer plugin
Browse files Browse the repository at this point in the history
define an interface for creating and configuring tracers
add the Jaeger tracer as a plugin

License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
  • Loading branch information
frrist committed Dec 19, 2017
1 parent 5ad9f4d commit 933eccf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
29 changes: 26 additions & 3 deletions plugin/loader/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ func initialize(plugins []plugin.Plugin) error {

func run(plugins []plugin.Plugin) error {
for _, pl := range plugins {
err := runIPLDPlugin(pl)
if err != nil {
return err
switch pl.(type) {
case plugin.PluginIPLD:
err := runIPLDPlugin(pl)
if err != nil {
return err
}
case plugin.PluginTracer:
err := runTracerPlugin(pl)
if err != nil {
return err
}
default:
//since this is a developer error if we hit this case
panic(pl)
}
}
return nil
Expand All @@ -41,3 +52,15 @@ func runIPLDPlugin(pl plugin.Plugin) error {

return ipldpl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
}

func runTracerPlugin(pl plugin.Plugin) error {
tracerpl, ok := pl.(plugin.PluginTracer)
if !ok {
return nil
}
err := tracerpl.InitGlobalTracer(nil)
if err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions plugin/loader/preload_list
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# name go-path number of the sub-plugin

#ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git 0
#jaegertracer github.com/ipfs/go-ipfs/plugin/plugins/jaeger 0
50 changes: 50 additions & 0 deletions plugin/plugins/jaeger/jaeger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package jaeger

import (
"github.com/ipfs/go-ipfs/plugin"
opentrace "github.com/opentracing/opentracing-go"
config "github.com/uber/jaeger-client-go/config"
)

// Plugins is exported list of plugins that will be loaded
var Plugins = []plugin.Plugin{
&jaegerPlugin{},
}

type jaegerPlugin struct{}

var _ plugin.PluginTracer = (*jaegerPlugin)(nil)

func (*jaegerPlugin) Name() string {
return "jaeger"
}

func (*jaegerPlugin) Version() string {
return "0.0.1"
}

func (*jaegerPlugin) Init() error {
return nil
}

//Initalize a Jaeger tracer and set it as the global tracer in opentracing api
func (*jaegerPlugin) InitGlobalTracer(cfg map[string]interface{}) error {
tracerCfg := &config.Configuration{
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &config.ReporterConfig{
LogSpans: false,
},
}
//service should be the ipfs node id
//we are ignoring the closer for now
tracer, _, err := tracerCfg.New("IPFS-NODE-ID")
if err != nil {
//probably failed to init the tracer
return err
}
opentrace.SetGlobalTracer(tracer)
return nil
}
7 changes: 7 additions & 0 deletions plugin/tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package plugin

// PluginTracer is an interface that can be implemented to add a tracer
type PluginTracer interface {
Plugin
InitGlobalTracer(cfg map[string]interface{}) error
}

0 comments on commit 933eccf

Please sign in to comment.