Always log Runner and Environment ID.

Systematically log the runner id and the environment id by adding the information at the findRunnerMiddleware.
This commit is contained in:
Maximilian Paß
2023-07-14 18:17:42 +02:00
parent 0bfef5e105
commit e7df777db4
11 changed files with 39 additions and 25 deletions

View File

@ -184,6 +184,12 @@ func (f File) ByteContent() []byte {
// ContextKey is the type for keys in a request context that is used for passing data to the next handler.
type ContextKey string
// Keys to reference information (for logging or monitoring).
const (
KeyRunnerID = "runner_id"
KeyEnvironmentID = "environment_id"
)
// WebSocketMessageType is the type for the messages from Poseidon to the client.
type WebSocketMessageType string

View File

@ -3,6 +3,7 @@ package logging
import (
"context"
"github.com/getsentry/sentry-go"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/sirupsen/logrus"
)
@ -28,6 +29,9 @@ func (hook *SentryHook) Fire(entry *logrus.Entry) error {
var hub *sentry.Hub
if entry.Context != nil {
hub = sentry.GetHubFromContext(entry.Context)
// This might overwrite valid data when not the request context is passed.
entry.Data[dto.KeyRunnerID] = entry.Context.Value(dto.ContextKey(dto.KeyRunnerID))
entry.Data[dto.KeyEnvironmentID] = entry.Context.Value(dto.ContextKey(dto.KeyEnvironmentID))
}
if hub == nil {
hub = sentry.CurrentHub()

View File

@ -34,8 +34,8 @@ const (
// The keys for the monitored tags and fields.
InfluxKeyRunnerID = "runner_id"
InfluxKeyEnvironmentID = "environment_id"
InfluxKeyRunnerID = dto.KeyRunnerID
InfluxKeyEnvironmentID = dto.KeyEnvironmentID
InfluxKeyJobID = "job_id"
InfluxKeyClientStatus = "client_status"
InfluxKeyNomadNode = "nomad_agent"