@@ -667,6 +667,10 @@ type Options struct {
667
667
// for a route when it's available (e.g. for RouteGroups)
668
668
OpenTracingBackendNameTag bool
669
669
670
+ // OpenTracingTracer allows pre-created tracer to be passed on to skipper. Providing the
671
+ // tracer instance overrides options provided under OpenTracing property.
672
+ OpenTracingTracer ot.Tracer
673
+
670
674
// PluginDir defines the directory to load plugins from, DEPRECATED, use PluginDirs
671
675
PluginDir string
672
676
// PluginDirs defines the directories to load plugins from
@@ -1145,6 +1149,27 @@ func (o *Options) tlsConfig(cr *certregistry.CertRegistry) (*tls.Config, error)
1145
1149
return config , nil
1146
1150
}
1147
1151
1152
+ func (o * Options ) openTracingTracerInstance () (ot.Tracer , error ) {
1153
+ if o .OpenTracingTracer != nil {
1154
+ return o .OpenTracingTracer , nil
1155
+ }
1156
+
1157
+ if len (o .OpenTracing ) > 0 {
1158
+ return tracing .InitTracer (o .OpenTracing )
1159
+ } else {
1160
+ // always have a tracer available, so filter authors can rely on the
1161
+ // existence of a tracer
1162
+ tracer , err := tracing .LoadTracingPlugin (o .PluginDirs , []string {"noop" })
1163
+ if err != nil {
1164
+ return nil , err
1165
+ } else if tracer == nil {
1166
+ // LoadTracingPlugin unfortunately may return nil tracer
1167
+ return nil , fmt .Errorf ("failed to load tracing plugin from %v" , o .PluginDirs )
1168
+ }
1169
+ return tracer , nil
1170
+ }
1171
+ }
1172
+
1148
1173
func listen (o * Options , address string , mtr metrics.Metrics ) (net.Listener , error ) {
1149
1174
1150
1175
if ! o .EnableTCPQueue {
@@ -1468,33 +1493,24 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
1468
1493
1469
1494
o .PluginDirs = append (o .PluginDirs , o .PluginDir )
1470
1495
1471
- var tracer ot.Tracer
1472
- if len (o .OpenTracing ) > 0 {
1473
- tracer , err = tracing .InitTracer (o .OpenTracing )
1474
- if err != nil {
1475
- return err
1476
- }
1477
- } else {
1478
- // always have a tracer available, so filter authors can rely on the
1479
- // existence of a tracer
1480
- tracer , _ = tracing .LoadTracingPlugin (o .PluginDirs , []string {"noop" })
1496
+ tracer , err := o .openTracingTracerInstance ()
1497
+ if err != nil {
1498
+ return err
1481
1499
}
1482
1500
1483
- // tee filters override if we have a tracer
1484
- if len (o .OpenTracing ) > 0 {
1485
- o .CustomFilters = append (o .CustomFilters ,
1486
- // tee()
1487
- teefilters .WithOptions (teefilters.Options {
1488
- Tracer : tracer ,
1489
- NoFollow : false ,
1490
- }),
1491
- // teenf()
1492
- teefilters .WithOptions (teefilters.Options {
1493
- NoFollow : true ,
1494
- Tracer : tracer ,
1495
- }),
1496
- )
1497
- }
1501
+ // tee filters override with initialized tracer
1502
+ o .CustomFilters = append (o .CustomFilters ,
1503
+ // tee()
1504
+ teefilters .WithOptions (teefilters.Options {
1505
+ Tracer : tracer ,
1506
+ NoFollow : false ,
1507
+ }),
1508
+ // teenf()
1509
+ teefilters .WithOptions (teefilters.Options {
1510
+ NoFollow : true ,
1511
+ Tracer : tracer ,
1512
+ }),
1513
+ )
1498
1514
1499
1515
if o .OAuthTokeninfoURL != "" {
1500
1516
tio := auth.TokeninfoOptions {
0 commit comments