diff --git a/internal/runner/nomad_runner.go b/internal/runner/nomad_runner.go index 15ef885..506b22a 100644 --- a/internal/runner/nomad_runner.go +++ b/internal/runner/nomad_runner.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/getsentry/sentry-go" nomadApi "github.com/hashicorp/nomad/api" influxdb2 "github.com/influxdata/influxdb-client-go/v2" "github.com/openHPI/poseidon/internal/nomad" @@ -137,7 +136,7 @@ func (r *NomadJob) ListFileSystem( command = lsCommandRecursive } - ls2json := &nullio.Ls2JsonWriter{Target: content} + ls2json := &nullio.Ls2JsonWriter{Target: content, Ctx: ctx} defer ls2json.Close() retrieveCommand := (&dto.ExecutionRequest{Command: fmt.Sprintf("%s %q", command, path)}).FullCommand() exitCode, err := r.api.ExecuteCommand(r.id, ctx, retrieveCommand, false, privilegedExecution, @@ -167,11 +166,9 @@ func (r *NomadJob) UpdateFileSystem(copyRequest *dto.UpdateFileSystemRequest, ct updateFileCommand := (&dto.ExecutionRequest{Command: fileDeletionCommand + copyCommand}).FullCommand() stdOut := bytes.Buffer{} stdErr := bytes.Buffer{} - span := sentry.StartSpan(ctx, "Execute Update File System") exitCode, err := r.api.ExecuteCommand(r.id, context.Background(), updateFileCommand, false, nomad.PrivilegedExecution, // All files should be written and owned by a privileged user #211. &tarBuffer, &stdOut, &stdErr) - span.Finish() if err != nil { return fmt.Errorf( "%w: nomad error during file copy: %v", diff --git a/pkg/nullio/ls2json.go b/pkg/nullio/ls2json.go index 92ce0a5..43d80c9 100644 --- a/pkg/nullio/ls2json.go +++ b/pkg/nullio/ls2json.go @@ -2,8 +2,10 @@ package nullio import ( "bytes" + "context" "encoding/json" "fmt" + "github.com/getsentry/sentry-go" "github.com/openHPI/poseidon/pkg/dto" "github.com/openHPI/poseidon/pkg/logging" "io" @@ -34,10 +36,12 @@ const ( // It streams the passed data to the Target and transforms the data into the json format. type Ls2JsonWriter struct { Target io.Writer + Ctx context.Context jsonStartSent bool setCommaPrefix bool remaining []byte latestPath []byte + sentrySpan *sentry.Span } func (w *Ls2JsonWriter) HasStartedWriting() bool { @@ -87,6 +91,7 @@ func (w *Ls2JsonWriter) initializeJSONObject() (count int, err error) { err = fmt.Errorf("could not write to target: %w", err) } else { w.jsonStartSent = true + w.sentrySpan = sentry.StartSpan(w.Ctx, "Forwarding") } } return count, err @@ -98,6 +103,7 @@ func (w *Ls2JsonWriter) Close() { if count == 0 || err != nil { log.WithError(err).Warn("Could not Close ls2json writer") } + w.sentrySpan.Finish() } } diff --git a/pkg/nullio/ls2json_test.go b/pkg/nullio/ls2json_test.go index efd5ce7..fa2579e 100644 --- a/pkg/nullio/ls2json_test.go +++ b/pkg/nullio/ls2json_test.go @@ -2,6 +2,7 @@ package nullio import ( "bytes" + "context" "github.com/stretchr/testify/suite" "testing" ) @@ -18,7 +19,7 @@ type Ls2JsonTestSuite struct { func (s *Ls2JsonTestSuite) SetupTest() { s.buf = &bytes.Buffer{} - s.writer = &Ls2JsonWriter{Target: s.buf} + s.writer = &Ls2JsonWriter{Target: s.buf, Ctx: context.Background()} } func (s *Ls2JsonTestSuite) TestLs2JsonWriter_WriteCreationAndClose() {