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

feat: created util to print out trace from endpoint call #2217

Merged
merged 3 commits into from
Dec 30, 2024
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
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ WORKDIR /app
COPY go.mod .
COPY go.sum .

# Installing xgo
RUN go install github.com/xhd2015/xgo/cmd/xgo@latest
ENV PATH="/usr/local/xgo/bin:${PATH}"

RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build
RUN CGO_ENABLED=0 xgo build

# final stage
FROM alpine:latest
Expand All @@ -24,4 +28,4 @@ COPY --from=builder /app/sphinx-tribes /app/
RUN ls app

EXPOSE 5002
ENTRYPOINT ["/app/sphinx-tribes"]
ENTRYPOINT ["/app/sphinx-tribes"]
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/onsi/gomega v1.26.0 // indirect
github.com/robfig/cron v1.2.0
github.com/urfave/negroni v1.0.0 // indirect
github.com/xhd2015/xgo/runtime v1.0.52 // indirect
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,8 @@ github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/xhd2015/xgo/runtime v1.0.52 h1:njcRzY3Xo2AFu/qQSC4ak9+JN7xFmaI3iEUyJxoErWM=
github.com/xhd2015/xgo/runtime v1.0.52/go.mod h1:9GBQ2SzJCzpD3T+HRN+2C0TUOGv7qIz4s0mad1xJ8Jo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
Expand Down
16 changes: 16 additions & 0 deletions routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"os"
"runtime"
"time"
"strings"
"context"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors"
"github.com/urfave/negroni"
"github.com/xhd2015/xgo/runtime/core"
"github.com/xhd2015/xgo/runtime/trap"

"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/config"
Expand Down Expand Up @@ -195,6 +199,18 @@ func internalServerErrorHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rr := negroni.NewResponseWriter(w)

trap.AddInterceptor(&trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) {
index := strings.Index(f.File, "sphinx-tribes")
trimmed := f.File
if index != -1 {
trimmed = f.File[index:]
}
logger.Log.Machine("%s:%d %s\n", trimmed, f.Line, f.Name)

return nil, nil
},
})
defer func() {
if err := recover(); err != nil {
// Get stack trace
Expand Down
Loading