Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a17795a4 authored by Nicolas Melin's avatar Nicolas Melin Committed by Fahim Salam Chowdhury
Browse files

Send proxy STT crash logs to Sentry

parent 76b8b2a4
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
| PROXY_HOSTNAME                       | murena-streamer          | No                                                   | Hostname for stream logs                                                        |
| STREAM_SDID                          | stream@12345             | No                                                   | Stream SD ID for stream logs                                                    |
| PORT                                 | 888                      | No                                                   | The port used by quic protocol                                                  |
| SENTRY_DSN                           | -                        | Yes                                                  | DSN for Sentry                                                                  |
| SENTRY_ENVIRONMENT                   | -                        | Yes                                                  | Environment for Sentry                                                          |

# Stream logs

+17 −1
Original line number Diff line number Diff line
@@ -6,18 +6,34 @@ import (
	"proxy-stt/app/murena-api"
	"proxy-stt/app/streamlog"
	"proxy-stt/app/quic-router"
	"proxy-stt/app/sentry-wrapper"
	"proxy-stt/app/utils"
	"proxy-stt/app/websocket"
)

var log = logger.GetLogger()

func main() {
	// Streamlog
	if err := streamlog.Init(); err != nil {
		log.Fatal().Err(err).Msg("Failed to init stream logger")
	}

	defer streamlog.CloseLogger()

	// Sentry
	flush, err := sentryWrapper.Init()
    if err != nil {
        log.Fatal().Msg(err.Error())
    }
    defer flush()

	defer func() {
        if r := recover(); r != nil {
			utils.HandleRecoveredPanic(r)
            log.Fatal().Msgf("Recovered from panic: %v", r)
        }
    }()

	murenaUserCanDoSTT := murenaApi.UserCanDoSTTProd{}
	websocketGetConnectionProd := websocket.GetConnectionProd{}
	websocketStartConnectionProd := websocket.StartConnectionProd{}
+3 −3
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ func initHttpRequestGeneric(method string, path string, authHeaderFunc func() (s
	host = strings.TrimSuffix(host, "/") // remove last caracter if it's a /
	if(host == "") {
		errorMessage := "Env MURENA_API_HOST is not set !"
		log.Fatal().Msg(errorMessage)
		panic(errorMessage)
		return nil, errors.New(errorMessage)
	}

@@ -136,14 +136,14 @@ func initHttpRequestV1(method string, path string) (*http.Request, error) {
		adminUsername := os.Getenv("MURENA_API_ADMIN_USERNAME")
		if(adminUsername == "") {
			errorMessage := "Env MURENA_API_ADMIN_USERNAME is not set !"
			log.Fatal().Msg(errorMessage)
			panic(errorMessage)
			return "", errors.New(errorMessage)
		}
		
		adminPassword := os.Getenv("MURENA_API_ADMIN_PASSWORD")
		if(adminPassword == "") {
			errorMessage := "Env MURENA_API_ADMIN_PASSWORD is not set !"
			log.Fatal().Msg(errorMessage)
			panic(errorMessage)
			return "", errors.New(errorMessage)
		}

+15 −2
Original line number Diff line number Diff line
@@ -65,12 +65,12 @@ func initQuicServer(router *gin.Engine) {

	crtPath := os.Getenv("CRT_PATH")
	if(crtPath == "") {
		log.Fatal().Msg("Env CRT_PATH is not set !")
		panic("Env CRT_PATH is not set !")
		return
	}
	keyPath := os.Getenv("KEY_PATH")
	if(keyPath == "") {
		log.Fatal().Msg("Env KEY_PATH is not set !")
		panic("Env KEY_PATH is not set !")
		return
	}

@@ -92,6 +92,7 @@ func initRouter(
	websocketCloseConnection websocket.CloseConnectionInterface,
) *gin.Engine {
	router := gin.New()
	router.Use(RecoveryWithSentry())
	handler := &UploadHandler{
		MurenaUserCanDoSTT: murenaUserCanDoSTT,
		WebsocketGetConnection: websocketGetConnection,
@@ -105,6 +106,18 @@ func initRouter(
	return router
}

func RecoveryWithSentry() gin.HandlerFunc {
    return func(c *gin.Context) {
        defer func() {
            if r := recover(); r != nil {
                utils.HandleRecoveredPanic(r)
                c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "Internal server error"})
            }
        }()
        c.Next()
    }
}

// ----------------------
// --- Middleware Auth --
// ----------------------
+41 −0
Original line number Diff line number Diff line
package sentryWrapper

import (
	"errors"
	"fmt"
	"os"
	"time"
	

	// External dependencies
	"github.com/getsentry/sentry-go"
)

func Init() (func(), error) {
	dsn := os.Getenv("SENTRY_DSN")
	if(dsn == "") {
		errorMessage := "Env SENTRY_DSN is not set !"
		return nil, errors.New(errorMessage)
	}
	
	environment := os.Getenv("SENTRY_ENVIRONMENT")
	if(environment == "") {
		errorMessage := "Env SENTRY_ENVIRONMENT is not set !"
		return nil, errors.New(errorMessage)
	}

    err := sentry.Init(sentry.ClientOptions{
        Dsn: dsn,
        Environment: environment,
    })
    if err != nil {
		errorMessage := fmt.Sprintf("sentry.Init: %s", err)
		return nil, errors.New(errorMessage)
    }

	flush := func() {
        sentry.Flush(2 * time.Second)
    }

	return flush, nil
}
 No newline at end of file
Loading