refactor discord command span in its own middleware

main
William Perron 10 months ago
parent 6b99919dd7
commit a46de17b7c
Signed by: wperron
GPG Key ID: BFDB4EF72D73C5F2

@ -785,7 +785,7 @@ func registerHandlers(sess *discordgo.Session, handlers map[string]Handler) {
defer cancel()
if h, ok := handlers[i.ApplicationCommandData().Name]; ok {
withLogging(i.ApplicationCommandData().Name, h)(ctx, s, i)
inSpan(i.ApplicationCommandData().Name, withLogging(i.ApplicationCommandData().Name, h))(ctx, s, i)
}
case discordgo.InteractionModalSubmit:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@ -952,11 +952,17 @@ func serve(address string) error {
return http.ListenAndServe(address, nil)
}
func withLogging(name string, h Handler) Handler {
func inSpan(name string, h Handler) Handler {
return func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
ctx, span := tracer.Start(ctx, fmt.Sprintf("discord_command %s", name))
defer span.End()
return h(ctx, s, i)
}
}
func withLogging(name string, h Handler) Handler {
return func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
start := time.Now()
logCommandInvocation(ctx, name, s, i)
err := h(ctx, s, i)

Loading…
Cancel
Save