diff --git a/x-pack/heartbeat/monitors/browser/synthexec/enrich.go b/x-pack/heartbeat/monitors/browser/synthexec/enrich.go index 0df01cf278aa..69d8913128dc 100644 --- a/x-pack/heartbeat/monitors/browser/synthexec/enrich.go +++ b/x-pack/heartbeat/monitors/browser/synthexec/enrich.go @@ -36,7 +36,7 @@ type journeyEnricher struct { journey *Journey checkGroup string errorCount int - lastError error + firstError error stepCount int // The first URL we visit is the URL for this journey, which is set on the summary event. // We store the URL fields here for use on the summary event. @@ -69,7 +69,7 @@ func (je *journeyEnricher) enrich(event *beat.Event, se *SynthEvent) error { // Record start and end so we can calculate journey duration accurately later switch se.Type { case "journey/start": - je.lastError = nil + je.firstError = nil je.checkGroup = makeUuid() je.journey = se.Journey je.start = event.Timestamp @@ -121,7 +121,9 @@ func (je *journeyEnricher) enrichSynthEvent(event *beat.Event, se *SynthEvent) e if se.Error != nil { jobErr = stepError(se.Error) je.errorCount++ - je.lastError = jobErr + if je.firstError == nil { + je.firstError = jobErr + } } return jobErr @@ -154,7 +156,7 @@ func (je *journeyEnricher) createSummary(event *beat.Event) error { "down": down, }, }) - return je.lastError + return je.firstError } return fmt.Errorf("journey did not finish executing, %d steps ran", je.stepCount) diff --git a/x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go b/x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go index cf1cc0dd6cf0..c80d050ea0b4 100644 --- a/x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go +++ b/x-pack/heartbeat/monitors/browser/synthexec/enrich_test.go @@ -30,6 +30,11 @@ func TestJourneyEnricher(t *testing.T) { Name: "my-errname", Stack: "my\nerr\nstack", } + otherErr := &SynthError{ + Message: "last-errmsg", + Name: "last-errname", + Stack: "last\nerr\nstack", + } journeyStart := &SynthEvent{ Type: "journey/start", TimestampEpochMicros: 1000, @@ -66,7 +71,7 @@ func TestJourneyEnricher(t *testing.T) { makeStepEvent("step/start", 21, "Step2", 1, "", nil), makeStepEvent("step/end", 30, "Step2", 1, url2, syntherr), makeStepEvent("step/start", 31, "Step3", 1, "", nil), - makeStepEvent("step/end", 40, "Step3", 1, url3, nil), + makeStepEvent("step/end", 40, "Step3", 1, url3, otherErr), journeyEnd, }