this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

identity: add logging with slog

+30 -8
+8 -6
atproto/identity/cmd/atp-id/main.go
··· 4 4 "context" 5 5 "encoding/json" 6 6 "fmt" 7 + "log/slog" 7 8 "os" 8 9 9 10 "github.com/bluesky-social/indigo/atproto/identity" ··· 34 35 Action: runResolveDID, 35 36 }, 36 37 } 38 + h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 39 + slog.SetDefault(slog.New(h)) 37 40 app.RunAndExitOnError() 38 41 } 39 42 ··· 48 51 if err != nil { 49 52 return err 50 53 } 51 - fmt.Printf("valid at-identifier syntax: %s\n", id) 52 - 53 - ndir := identity.BaseDirectory{} 54 + slog.Info("valid syntax", "at-identifier", id) 54 55 55 - acc, err := ndir.Lookup(ctx, *id) 56 + dir := identity.DefaultDirectory() 57 + acc, err := dir.Lookup(ctx, *id) 56 58 if err != nil { 57 59 return err 58 60 } ··· 71 73 if err != nil { 72 74 return err 73 75 } 74 - fmt.Printf("valid handle syntax: %s\n", handle) 76 + slog.Info("valid syntax", "handle", handle) 75 77 76 78 d := identity.BaseDirectory{} 77 79 did, err := d.ResolveHandle(ctx, handle) ··· 95 97 fmt.Println(err) 96 98 os.Exit(-1) 97 99 } 98 - fmt.Printf("valid DID syntax: %s\n", did) 100 + slog.Info("valid syntax", "did", did) 99 101 100 102 d := identity.BaseDirectory{} 101 103 doc, err := d.ResolveDID(ctx, did)
+11 -2
atproto/identity/did.go
··· 5 5 "encoding/json" 6 6 "errors" 7 7 "fmt" 8 + "log/slog" 8 9 "net" 9 10 "net/http" 11 + "time" 10 12 11 13 "github.com/bluesky-social/indigo/atproto/syntax" 12 14 ) ··· 33 35 34 36 // WARNING: this does *not* bi-directionally verify account metadata; it only implements direct DID-to-DID-document lookup for the supported DID methods, and parses the resulting DID Doc into an Identity struct 35 37 func (d *BaseDirectory) ResolveDID(ctx context.Context, did syntax.DID) (*DIDDocument, error) { 38 + start := time.Now() 36 39 switch did.Method() { 37 40 case "web": 38 - return d.ResolveDIDWeb(ctx, did) 41 + doc, err := d.ResolveDIDWeb(ctx, did) 42 + elapsed := time.Since(start) 43 + slog.Debug("resolve DID", "did", did, "err", err, "duration_ms", elapsed.Milliseconds()) 44 + return doc, err 39 45 case "plc": 40 - return d.ResolveDIDPLC(ctx, did) 46 + doc, err := d.ResolveDIDPLC(ctx, did) 47 + elapsed := time.Since(start) 48 + slog.Debug("resolve DID", "did", did, "err", err, "duration_ms", elapsed.Milliseconds()) 49 + return doc, err 41 50 default: 42 51 return nil, fmt.Errorf("DID method not supported: %s", did.Method()) 43 52 }
+11
atproto/identity/handle.go
··· 5 5 "errors" 6 6 "fmt" 7 7 "io" 8 + "log/slog" 8 9 "net" 9 10 "net/http" 10 11 "strings" ··· 123 124 124 125 func (d *BaseDirectory) ResolveHandle(ctx context.Context, handle syntax.Handle) (syntax.DID, error) { 125 126 // TODO: *could* do resolution in parallel, but expecting that sequential is sufficient to start 127 + start := time.Now() 128 + triedAuthoritative := false 126 129 did, dnsErr := d.ResolveHandleDNS(ctx, handle) 127 130 if dnsErr == ErrHandleNotFound && d.TryAuthoritativeDNS { 131 + slog.Info("attempting authoritative handle DNS resolution", "handle", handle) 132 + triedAuthoritative = true 128 133 // try harder with authoritative lookup 129 134 did, dnsErr = d.ResolveHandleDNSAuthoritative(ctx, handle) 130 135 } 136 + elapsed := time.Since(start) 137 + slog.Debug("resolve handle DNS", "handle", handle, "err", dnsErr, "did", did, "authoritative", triedAuthoritative, "duration_ms", elapsed.Milliseconds()) 131 138 if nil == dnsErr { // if *not* an error 132 139 return did, nil 133 140 } 141 + 142 + start = time.Now() 134 143 did, httpErr := d.ResolveHandleWellKnown(ctx, handle) 144 + elapsed = time.Since(start) 145 + slog.Debug("resolve handle HTTP well-known", "handle", handle, "err", httpErr, "did", did, "duration_ms", elapsed.Milliseconds()) 135 146 if nil == httpErr { // if *not* an error 136 147 return did, nil 137 148 }