-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Commit: Add Tracing To Certs Service
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
- Loading branch information
1 parent
889b35e
commit 5470a7c
Showing
6 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Mainflux | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Package tracing provides tracing instrumentation for Mainflux Users Groups service. | ||
// | ||
// This package provides tracing middleware for Mainflux Users Groups service. | ||
// It can be used to trace incoming requests and add tracing capabilities to | ||
// Mainflux Users Groups service. | ||
// | ||
// For more details about tracing instrumentation for Mainflux messaging refer | ||
// to the documentation at https://docs.mainflux.io/tracing/. | ||
package tracing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Mainflux | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package tracing | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/mainflux/mainflux/certs" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var _ certs.Service = (*tracingMiddleware)(nil) | ||
|
||
type tracingMiddleware struct { | ||
tracer trace.Tracer | ||
svc certs.Service | ||
} | ||
|
||
// New returns a new certs service with tracing capabilities. | ||
func New(svc certs.Service, tracer trace.Tracer) certs.Service { | ||
return &tracingMiddleware{tracer, svc} | ||
} | ||
|
||
// IssueCert traces the "IssueCert" operation of the wrapped certs.Service. | ||
func (tm *tracingMiddleware) IssueCert(ctx context.Context, token, thingID, ttl string) (certs.Cert, error) { | ||
ctx, span := tm.tracer.Start(ctx, "svc_create_group", trace.WithAttributes( | ||
attribute.String("thing_id", thingID), | ||
attribute.String("ttl", ttl), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.IssueCert(ctx, token, thingID, ttl) | ||
} | ||
|
||
// ListCerts traces the "ListCerts" operation of the wrapped certs.Service. | ||
func (tm *tracingMiddleware) ListCerts(ctx context.Context, token, thingID string, offset, limit uint64) (certs.Page, error) { | ||
ctx, span := tm.tracer.Start(ctx, "svc_list_certs", trace.WithAttributes( | ||
attribute.String("thing_id", thingID), | ||
attribute.Int64("offset", int64(offset)), | ||
attribute.Int64("limit", int64(limit)), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.ListCerts(ctx, token, thingID, offset, limit) | ||
} | ||
|
||
// ListSerials traces the "ListSerials" operation of the wrapped certs.Service. | ||
func (tm *tracingMiddleware) ListSerials(ctx context.Context, token, thingID string, offset, limit uint64) (certs.Page, error) { | ||
ctx, span := tm.tracer.Start(ctx, "svc_list_serials", trace.WithAttributes( | ||
attribute.String("thing_id", thingID), | ||
attribute.Int64("offset", int64(offset)), | ||
attribute.Int64("limit", int64(limit)), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.ListSerials(ctx, token, thingID, offset, limit) | ||
} | ||
|
||
// ViewCert traces the "ViewCert" operation of the wrapped certs.Service. | ||
func (tm *tracingMiddleware) ViewCert(ctx context.Context, token, serialID string) (certs.Cert, error) { | ||
ctx, span := tm.tracer.Start(ctx, "svc_view_cert", trace.WithAttributes( | ||
attribute.String("serial_id", serialID), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.ViewCert(ctx, token, serialID) | ||
} | ||
|
||
// RevokeCert traces the "RevokeCert" operation of the wrapped certs.Service. | ||
func (tm *tracingMiddleware) RevokeCert(ctx context.Context, token, serialID string) (certs.Revoke, error) { | ||
ctx, span := tm.tracer.Start(ctx, "svc_revoke_cert", trace.WithAttributes( | ||
attribute.String("serial_id", serialID), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.RevokeCert(ctx, token, serialID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters