Skip to content

Commit

Permalink
Add tracer plugin support
Browse files Browse the repository at this point in the history
define interface for creating tracers for use with opentracing-api

License: MIT
Signed-off-by: ForrestWeston <forrest@protocol.ai>
  • Loading branch information
frrist committed Jan 30, 2018
1 parent b386088 commit 4b5fd5f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@
"hash": "QmWFAMPqsEyUX7gDUsRVmMWz59FxSpJ1b2v6bJ1yYzo7jY",
"name": "go-base58-fast",
"version": "0.1.1"
},
{
"author": "frist",
"hash": "QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo",
"name": "opentracing-go",
"version": "0.0.3"
}
],
"gxVersion": "0.10.0",
Expand Down
35 changes: 27 additions & 8 deletions plugin/loader/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package loader
import (
"github.com/ipfs/go-ipfs/core/coredag"
"github.com/ipfs/go-ipfs/plugin"
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"

ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)
Expand All @@ -20,24 +21,42 @@ 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 := 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:
panic(pl)
}
}
return nil
}

func runIPLDPlugin(pl plugin.Plugin) error {
ipldpl, ok := pl.(plugin.PluginIPLD)
if !ok {
return nil
func runIPLDPlugin(pl plugin.PluginIPLD) error {
err := pl.RegisterBlockDecoders(format.DefaultBlockDecoder)
if err != nil {
return err
}

err := ipldpl.RegisterBlockDecoders(ipld.DefaultBlockDecoder)
if err != nil {
return err
}
return pl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
}

return ipldpl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
func runTracerPlugin(pl plugin.PluginTracer) error {
tracer, err := pl.InitTracer()
if err != nil {
return err
}
opentracing.SetGlobalTracer(tracer)
return nil
}
11 changes: 11 additions & 0 deletions plugin/tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package plugin

import (
"gx/ipfs/QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo/opentracing-go"
)

// PluginTracer is an interface that can be implemented to add a tracer
type PluginTracer interface {
Plugin
InitTracer() (opentracing.Tracer, error)
}

0 comments on commit 4b5fd5f

Please sign in to comment.