diff --git a/bootstrap/api/transport.go b/bootstrap/api/transport.go index 66c52b0668..1de61e809c 100644 --- a/bootstrap/api/transport.go +++ b/bootstrap/api/transport.go @@ -18,6 +18,7 @@ import ( mflog "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/errors" "github.com/prometheus/client_golang/prometheus/promhttp" + "go.opentelemetry.io/contrib/instrumentation/github.com/go-kit/kit/otelkit" ) const ( @@ -41,61 +42,61 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mf r := bone.New() r.Post("/things/configs", kithttp.NewServer( - addEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("add"))(addEndpoint(svc)), decodeAddRequest, encodeResponse, opts...)) r.Get("/things/configs/:configID", kithttp.NewServer( - viewEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("view"))(viewEndpoint(svc)), decodeEntityRequest, encodeResponse, opts...)) r.Put("/things/configs/:configID", kithttp.NewServer( - updateEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("update"))(updateEndpoint(svc)), decodeUpdateRequest, encodeResponse, opts...)) r.Patch("/things/configs/certs/:certID", kithttp.NewServer( - updateCertEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("update_cert"))(updateCertEndpoint(svc)), decodeUpdateCertRequest, encodeResponse, opts...)) r.Put("/things/configs/connections/:connID", kithttp.NewServer( - updateConnEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("update_connections"))(updateConnEndpoint(svc)), decodeUpdateConnRequest, encodeResponse, opts...)) r.Get("/things/configs", kithttp.NewServer( - listEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("list"))(listEndpoint(svc)), decodeListRequest, encodeResponse, opts...)) r.Get("/things/bootstrap/:externalID", kithttp.NewServer( - bootstrapEndpoint(svc, reader, false), + otelkit.EndpointMiddleware(otelkit.WithOperation("bootstrap"))(bootstrapEndpoint(svc, reader, false)), decodeBootstrapRequest, encodeResponse, opts...)) r.Get("/things/bootstrap/secure/:externalID", kithttp.NewServer( - bootstrapEndpoint(svc, reader, true), + otelkit.EndpointMiddleware(otelkit.WithOperation("bootstrap_secure"))(bootstrapEndpoint(svc, reader, true)), decodeBootstrapRequest, encodeSecureRes, opts...)) r.Put("/things/state/:thingID", kithttp.NewServer( - stateEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("state"))(stateEndpoint(svc)), decodeStateRequest, encodeResponse, opts...)) r.Delete("/things/configs/:configID", kithttp.NewServer( - removeEndpoint(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("remove"))(removeEndpoint(svc)), decodeEntityRequest, encodeResponse, opts...)) diff --git a/certs/api/transport.go b/certs/api/transport.go index 79deecb6f5..02f2d03d48 100644 --- a/certs/api/transport.go +++ b/certs/api/transport.go @@ -16,6 +16,7 @@ import ( "github.com/mainflux/mainflux/logger" "github.com/mainflux/mainflux/pkg/errors" "github.com/prometheus/client_golang/prometheus/promhttp" + "go.opentelemetry.io/contrib/instrumentation/github.com/go-kit/kit/otelkit" ) const ( @@ -35,28 +36,28 @@ func MakeHandler(svc certs.Service, logger logger.Logger, instanceID string) htt r := bone.New() r.Post("/certs", kithttp.NewServer( - issueCert(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("issue"))(issueCert(svc)), decodeCerts, encodeResponse, opts..., )) r.Get("/certs/:certID", kithttp.NewServer( - viewCert(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("view"))(viewCert(svc)), decodeViewCert, encodeResponse, opts..., )) r.Delete("/certs/:certID", kithttp.NewServer( - revokeCert(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("revoke"))(revokeCert(svc)), decodeRevokeCerts, encodeResponse, opts..., )) r.Get("/serials/:thingID", kithttp.NewServer( - listSerials(svc), + otelkit.EndpointMiddleware(otelkit.WithOperation("list_serials"))(listSerials(svc)), decodeListCerts, encodeResponse, opts..., diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 5607a0bf2d..942c53343a 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -123,6 +123,7 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } + hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, instanceID), logger) if cfg.SendTelemetry { diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 511adb0b81..4466d991f8 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -18,6 +18,7 @@ import ( vault "github.com/mainflux/mainflux/certs/pki" certsPg "github.com/mainflux/mainflux/certs/postgres" "github.com/mainflux/mainflux/internal" + jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger" "github.com/mainflux/mainflux/internal/env" "github.com/mainflux/mainflux/internal/server" httpserver "github.com/mainflux/mainflux/internal/server/http" @@ -46,6 +47,7 @@ type config struct { ThingsURL string `env:"MF_THINGS_URL" envDefault:"http://things:9000"` SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"` InstanceID string `env:"MF_CERTS_INSTANCE_ID" envDefault:""` + JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"` // Sign and issue certificates without 3rd party PKI SignCAPath string `env:"MF_CERTS_SIGN_CA_PATH" envDefault:"ca.crt"` @@ -112,6 +114,15 @@ func main() { if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err)) } + tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID) + if err != nil { + logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err)) + } + defer func() { + if err := tp.Shutdown(ctx); err != nil { + logger.Error(fmt.Sprintf("error shutting down tracer provider: %v", err)) + } + }() hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger) if cfg.SendTelemetry {