mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-28 13:48:49 +08:00

* Fix linting errors Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(linters): add ineffassign linter This commit adds the `ineffassign` linter to the project's `.golangci.yml` configuration file. The `ineffassign` linter helps identify and flag assignments to variables that are never used, helping to improve code quality and maintainability. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Add extra linters Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(golangci): Add header check - Added goheader check to ensure all files have license headers - Added build tags for "nats" in the .golangci.yml file to include the necessary dependencies for the "nats" package during the build process. - Also, increased the maximum number of issues per linter and the maximum number of same issues reported by the linter to improve the code quality analysis. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(.golangci.yml): Add new linters Add the following new linters to the .golangci.yml configuration file: - asasalint - asciicheck - bidichk - contextcheck - decorder - dogsled - errchkjson - errname - execinquery - exportloopref - ginkgolinter - gocheckcompilerdirectives These linters will help improve code quality and catch potential issues during the code review process. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux/http"
|
|
"github.com/mainflux/mainflux/pkg/messaging"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
var _ http.Service = (*serviceMiddleware)(nil)
|
|
|
|
const publishOP = "publish"
|
|
|
|
// serviceMiddleware implements the http.Service interface, providing a middleware layer for tracing HTTP requests.
|
|
// It creates a new span for each request and sets it as the active span in the OpenTelemetry context.
|
|
type serviceMiddleware struct {
|
|
tracer trace.Tracer
|
|
svc http.Service
|
|
}
|
|
|
|
// New creates a new instance of the http.Service interface with tracing middleware.
|
|
func New(tracer trace.Tracer, svc http.Service) http.Service {
|
|
return &serviceMiddleware{
|
|
tracer: tracer,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
// Publish traces HTTP publish operations.
|
|
// It starts a new span as a child of the incoming span (if there is one) and sets it as the active span in the context.
|
|
func (sm *serviceMiddleware) Publish(ctx context.Context, token string, msg *messaging.Message) error {
|
|
ctx, span := sm.tracer.Start(ctx, publishOP)
|
|
defer span.End()
|
|
return sm.svc.Publish(ctx, token, msg)
|
|
}
|