Skip to content

Commit 5573aa1

Browse files
committed
Add newrelic transaction attributes
1 parent 4a1624d commit 5573aa1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/server/end.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77

88
"github.com/bethanyj28/battlesnek/internal"
9+
"github.com/newrelic/go-agent/v3/newrelic"
910
"github.com/sirupsen/logrus"
1011
)
1112

@@ -21,10 +22,25 @@ func (s *server) handleEnd() http.HandlerFunc {
2122
return
2223
}
2324

25+
if txn := newrelic.FromContext(r.Context()); nil != txn {
26+
txn.AddAttribute("won", didSnakeWin(state.Board.Snakes, state.You))
27+
txn.AddAttribute("turns", state.Turn)
28+
txn.AddAttribute("game_id", state.Game.ID)
29+
}
30+
2431
s.logger.WithFields(logrus.Fields{
2532
"game_state": fmt.Sprintf("%+v", state),
2633
}).Info("END")
2734

2835
w.WriteHeader(http.StatusOK)
2936
}
3037
}
38+
39+
func didSnakeWin(remainingSnakes []internal.Battlesnake, you internal.Battlesnake) bool {
40+
for _, snake := range remainingSnakes {
41+
if snake.ID == you.ID {
42+
return true
43+
}
44+
}
45+
return false
46+
}

0 commit comments

Comments
 (0)