feat: add otel
This commit is contained in:
10 files changed
+612
-111
No files matched your search
@@ -1,23 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.sour.is/xt/internal/otel"
|
||||
)
|
||||
|
||||
func httpServer(c console, app *appState) {
|
||||
c.Log("start http server")
|
||||
func httpServer(c *console, app *appState) error {
|
||||
otel.Info("start http server")
|
||||
|
||||
db, err := app.DB()
|
||||
if err != nil {
|
||||
c.Log("missing db", err)
|
||||
c.abort()
|
||||
return
|
||||
otel.Info("missing db", err)
|
||||
return err
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -37,7 +38,7 @@ func httpServer(c console, app *appState) {
|
||||
|
||||
rows, err := db.QueryContext(r.Context(), "SELECT feed_id, hash, conv, dt, text FROM twt WHERE hash = $1 or conv = $1", hash)
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
otel.Info("error", err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
@@ -52,7 +53,7 @@ func httpServer(c console, app *appState) {
|
||||
}
|
||||
err = rows.Scan(&twt.FeedID, &twt.Hash, &twt.Conv, &twt.Dt, &twt.Text)
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
otel.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -73,18 +74,14 @@ func httpServer(c console, app *appState) {
|
||||
Handler: http.DefaultServeMux,
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-c.Done()
|
||||
c.Log("stop http server")
|
||||
srv.Shutdown(context.Background())
|
||||
}()
|
||||
|
||||
c.AddCancel(srv.Shutdown)
|
||||
err = srv.ListenAndServe()
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
c.abort()
|
||||
return
|
||||
if !errors.Is(err, http.ErrServerClosed) {
|
||||
otel.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func notAny(s string, chars string) bool {
|
||||
|
||||
Reference in new issue
Block a user