Skip to content

Commit fdc3981

Browse files
committed
Add basic tracing to randomizer.App
We can see what the operation was, at least, which is interesting.
1 parent 7a76ad6 commit fdc3981

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/randomizer/app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ package randomizer
33
import (
44
"context"
55
"math/rand/v2"
6+
7+
"go.opentelemetry.io/otel"
8+
"go.opentelemetry.io/otel/attribute"
69
)
710

11+
var tracer = otel.Tracer("github.com/featherbread/randomizer/internal/randomizer")
12+
813
// Store enables persistence for named groups of options.
914
type Store interface {
1015
// List returns the names of all available groups. If no groups have been
@@ -50,10 +55,16 @@ func shuffle(options []string) {
5055
// All errors returned from Main are of type [Error], and support
5156
// [Error.HelpText] for user-friendly formatting.
5257
func (a App) Main(ctx context.Context, args []string) (Result, error) {
58+
ctx, span := tracer.Start(ctx, "Main")
59+
defer span.End()
60+
5361
request, err := a.newRequest(ctx, args)
5462
if err != nil {
63+
span.RecordError(err)
5564
return Result{}, err
5665
}
66+
67+
span.SetAttributes(attribute.String("operation", request.Operation.String()))
5768
handler := appHandlers[request.Operation]
5869
return handler(a, request)
5970
}

internal/randomizer/request.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ const (
1616
deleteGroup
1717
)
1818

19+
func (op operation) String() string {
20+
switch op {
21+
case makeSelection:
22+
return "select"
23+
case showHelp:
24+
return "help"
25+
case listGroups:
26+
return "list"
27+
case showGroup:
28+
return "show"
29+
case saveGroup:
30+
return "save"
31+
case deleteGroup:
32+
return "delete"
33+
}
34+
return ""
35+
}
36+
1937
// request represents a single user request to a randomizer instance, created
2038
// from raw user input.
2139
type request struct {

0 commit comments

Comments
 (0)