File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,13 @@ package randomizer
33import (
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.
914type 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.
5257func (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}
Original file line number Diff line number Diff 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.
2139type request struct {
You can’t perform that action at this time.
0 commit comments