-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: rodneyosodo <[email protected]>
- Loading branch information
1 parent
a903ca2
commit c6f6912
Showing
3 changed files
with
84 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Package tracing provides tracing instrumentation for cocos auth service. | ||
// | ||
// This package provides tracing middleware for cocos auth service. | ||
// It can be used to trace incoming requests and add tracing capabilities to | ||
// cocos auth service. | ||
// | ||
// For more details about tracing instrumentation 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,70 @@ | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ultravioletrs/agent/agent" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var _ agent.Service = (*tracingMiddleware)(nil) | ||
|
||
type tracingMiddleware struct { | ||
tracer trace.Tracer | ||
svc agent.Service | ||
} | ||
|
||
// New returns a new auth service with tracing capabilities. | ||
func New(svc agent.Service, tracer trace.Tracer) agent.Service { | ||
return &tracingMiddleware{tracer, svc} | ||
} | ||
|
||
func (tm *tracingMiddleware) Ping(secret string) (string, error) { | ||
_, span := tm.tracer.Start(context.Background(), "ping", trace.WithAttributes( | ||
attribute.String("secret", secret), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.Ping(secret) | ||
} | ||
|
||
func (tm *tracingMiddleware) Run(ctx context.Context, cmp agent.Computation) (string, error) { | ||
ctx, span := tm.tracer.Start(context.Background(), "run", trace.WithAttributes( | ||
attribute.String("id", cmp.ID), | ||
attribute.String("name", cmp.Name), | ||
attribute.String("description", cmp.Description), | ||
attribute.String("status", cmp.Status), | ||
attribute.String("start_time", cmp.StartTime.String()), | ||
attribute.String("end_time", cmp.EndTime.String()), | ||
attribute.StringSlice("dataset_providers", cmp.DatasetProviders), | ||
attribute.StringSlice("algorithm_providers", cmp.AlgorithmProviders), | ||
attribute.StringSlice("result_consumers", cmp.ResultConsumers), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.Run(ctx, cmp) | ||
} | ||
|
||
func (tm *tracingMiddleware) Algo(ctx context.Context, algorithm []byte) (string, error) { | ||
ctx, span := tm.tracer.Start(context.Background(), "algo") | ||
defer span.End() | ||
|
||
return tm.svc.Algo(ctx, algorithm) | ||
} | ||
|
||
func (tm *tracingMiddleware) Data(ctx context.Context, dataset string) (string, error) { | ||
ctx, span := tm.tracer.Start(context.Background(), "data", trace.WithAttributes( | ||
attribute.String("dataset", dataset), | ||
)) | ||
defer span.End() | ||
|
||
return tm.svc.Data(ctx, dataset) | ||
} | ||
|
||
func (tm *tracingMiddleware) Result(ctx context.Context) ([]byte, error) { | ||
ctx, span := tm.tracer.Start(context.Background(), "result") | ||
defer span.End() | ||
|
||
return tm.svc.Result(ctx) | ||
} |
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