1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 23:53:19 +08:00

Merge pull request #4506 from ipfs/feat/opentrace

Add Opentracing plugin support
This commit is contained in:
Whyrusleeping
2018-03-25 14:04:23 -07:00
committed by GitHub
3 changed files with 43 additions and 12 deletions

View File

@ -581,6 +581,12 @@
"hash": "QmQine7gvHncNevKtG9QXxf3nXcwSj6aDDmMm52mHofEEp",
"name": "tar-utils",
"version": "0.0.3"
},
{
"author": "frist",
"hash": "QmWLWmRVSiagqP15jczsGME1qpob6HDbtbHAY2he9W5iUo",
"name": "opentracing-go",
"version": "0.0.3"
}
],
"gxVersion": "0.10.0",

View File

@ -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"
)
@ -20,24 +21,37 @@ 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
}
err := ipldpl.RegisterBlockDecoders(ipld.DefaultBlockDecoder)
func runIPLDPlugin(pl plugin.PluginIPLD) error {
err := pl.RegisterBlockDecoders(ipld.DefaultBlockDecoder)
if err != nil {
return err
}
return ipldpl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
return pl.RegisterInputEncParsers(coredag.DefaultInputEncParsers)
}
func runTracerPlugin(pl plugin.PluginTracer) error {
tracer, err := pl.InitTracer()
if err != nil {
return err
}
opentracing.SetGlobalTracer(tracer)
return nil
}

11
plugin/tracer.go Normal file
View File

@ -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)
}