Feat: add telemetry

This commit is contained in:
Grail Finder
2025-07-11 16:20:43 +03:00
parent 9a949757f2
commit ea27d35254
6 changed files with 114 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"gralias/crons"
"gralias/handlers"
"gralias/repos"
"gralias/telemetry"
"log/slog"
"net/http"
"os"
@ -56,8 +57,11 @@ func getContentType(path string) string {
func ListenToRequests(port string) *http.Server {
mux := http.NewServeMux()
var handler http.Handler = mux
handler = handlers.LogRequests(handlers.GetSession(handler))
handler = telemetry.OtelMiddleware(handler)
server := &http.Server{
Handler: handlers.LogRequests(handlers.GetSession(mux)),
Handler: handler,
Addr: ":" + port,
// ReadTimeout: time.Second * 5, // does this timeout conflict with sse connection?
WriteTimeout: 0, // sse streaming
@ -96,6 +100,8 @@ func ListenToRequests(port string) *http.Server {
}
func main() {
shutdown := telemetry.InitTracer()
defer shutdown()
// Setup graceful shutdown
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)