Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apps: log simplified user agent and downgrade user errors to warn #5113

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/app-agent-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: log simplified user agent in apps

https://github.com/cs3org/reva/pull/5113
20 changes: 19 additions & 1 deletion internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"path"
"path/filepath"
"strings"

apppb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
Expand Down Expand Up @@ -436,8 +437,25 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
return
}

var agent string
switch {
case strings.Contains(r.UserAgent(), "Firefox"):
agent = "Firefox"
case strings.Contains(r.UserAgent(), "Chrome"):
agent = "Chrome"
case strings.Contains(r.UserAgent(), "Safari"):
agent = "Safari"
default:
agent = "Other"
}
log := appctx.GetLogger(ctx)
log.Info().Interface("resource", fileRef).Str("url", openRes.AppUrl.AppUrl).Str("method", openRes.AppUrl.Method).Interface("viewMode", viewMode).Str("fileExt", filepath.Ext(statRes.Info.Path)).Msg("returning app URL for file")
log.Info().Interface("resource", fileRef).
Str("url", openRes.AppUrl.AppUrl).
Str("method", openRes.AppUrl.Method).
Interface("viewMode", viewMode).
Str("fileExt", filepath.Ext(statRes.Info.Path)).
Str("agent", agent).
Msg("returning app URL for file")

w.Header().Set("Content-Type", "application/json")
if _, err = w.Write(js); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/appprovider/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type appError struct {
// writeError handles writing error responses.
func writeError(w http.ResponseWriter, r *http.Request, code appErrorCode, message string, err error) {
if err != nil {
appctx.GetLogger(r.Context()).Error().Err(err).Msg(message)
appctx.GetLogger(r.Context()).Warn().Err(err).Msg(message)
}

var encoded []byte
Expand Down