Convert webfinger to use service trace provider
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config/parser"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config/parser"
|
||||||
@@ -15,7 +16,6 @@ import (
|
|||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/server/debug"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/server/debug"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/server/http"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/server/http"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/service/v0"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/service/v0"
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/tracing"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||||
err := tracing.Configure(cfg)
|
traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
svc = service.NewInstrument(svc, metrics)
|
svc = service.NewInstrument(svc, metrics)
|
||||||
svc = service.NewLogging(svc, logger) // this logs service specific data
|
svc = service.NewLogging(svc, logger) // this logs service specific data
|
||||||
svc = service.NewTracing(svc)
|
svc = service.NewTracing(svc, traceProvider)
|
||||||
|
|
||||||
server, err := http.Server(
|
server, err := http.Server(
|
||||||
http.Logger(logger),
|
http.Logger(logger),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||||
|
|
||||||
// Tracing defines the available tracing configuration.
|
// Tracing defines the available tracing configuration.
|
||||||
type Tracing struct {
|
type Tracing struct {
|
||||||
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;WEBFINGER_TRACING_ENABLED" desc:"Activates tracing."`
|
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;WEBFINGER_TRACING_ENABLED" desc:"Activates tracing."`
|
||||||
@@ -7,3 +9,13 @@ type Tracing struct {
|
|||||||
Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBFINGER_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."`
|
Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;WEBFINGER_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent."`
|
||||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;WEBFINGER_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."`
|
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;WEBFINGER_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset."`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert Tracing to the tracing package's Config struct.
|
||||||
|
func (t Tracing) Convert() tracing.Config {
|
||||||
|
return tracing.Config{
|
||||||
|
Enabled: t.Enabled,
|
||||||
|
Type: t.Type,
|
||||||
|
Endpoint: t.Endpoint,
|
||||||
|
Collector: t.Collector,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,21 +4,22 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
webfingertracing "github.com/owncloud/ocis/v2/services/webfinger/pkg/tracing"
|
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/webfinger"
|
"github.com/owncloud/ocis/v2/services/webfinger/pkg/webfinger"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTracing returns a service that instruments traces.
|
// NewTracing returns a service that instruments traces.
|
||||||
func NewTracing(next Service) Service {
|
func NewTracing(next Service, tp trace.TracerProvider) Service {
|
||||||
return tracing{
|
return tracing{
|
||||||
next: next,
|
next: next,
|
||||||
|
tp: tp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type tracing struct {
|
type tracing struct {
|
||||||
next Service
|
next Service
|
||||||
|
tp trace.TracerProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webfinger implements the Service interface.
|
// Webfinger implements the Service interface.
|
||||||
@@ -30,7 +31,7 @@ func (t tracing) Webfinger(ctx context.Context, queryTarget *url.URL, rels []str
|
|||||||
attribute.KeyValue{Key: "rels", Value: attribute.StringSliceValue(rels)},
|
attribute.KeyValue{Key: "rels", Value: attribute.StringSliceValue(rels)},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
ctx, span := webfingertracing.TraceProvider.Tracer("webfinger").Start(ctx, "Webfinger", spanOpts...)
|
ctx, span := t.tp.Tracer("webfinger").Start(ctx, "Webfinger", spanOpts...)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
return t.next.Webfinger(ctx, queryTarget, rels)
|
return t.next.Webfinger(ctx, queryTarget, rels)
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package tracing
|
|
||||||
|
|
||||||
import (
|
|
||||||
pkgtrace "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
|
||||||
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config"
|
|
||||||
"go.opentelemetry.io/otel/trace"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// TraceProvider is the global trace provider for the proxy service.
|
|
||||||
TraceProvider = trace.NewNoopTracerProvider()
|
|
||||||
)
|
|
||||||
|
|
||||||
func Configure(cfg *config.Config) error {
|
|
||||||
var err error
|
|
||||||
if cfg.Tracing.Enabled {
|
|
||||||
if TraceProvider, err = pkgtrace.GetTraceProvider(cfg.Tracing.Endpoint, cfg.Tracing.Collector, cfg.Service.Name, cfg.Tracing.Type); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user