Synchronize Sentry debug message handling.
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ type SentryDebugWriter struct {
|
|||||||
Target io.Writer
|
Target io.Writer
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
lastSpan *sentry.Span
|
lastSpan *sentry.Span
|
||||||
lastSpanLock sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSentryDebugWriter(target io.Writer, ctx context.Context) *SentryDebugWriter {
|
func NewSentryDebugWriter(target io.Writer, ctx context.Context) *SentryDebugWriter {
|
||||||
@ -66,7 +64,7 @@ func (s *SentryDebugWriter) Write(p []byte) (n int, err error) {
|
|||||||
n += count
|
n += count
|
||||||
}
|
}
|
||||||
|
|
||||||
go s.handleTimeDebugMessage(match)
|
s.handleTimeDebugMessage(match)
|
||||||
n += len(p) - len(match["before"]) - len(match["after"])
|
n += len(p) - len(match["before"]) - len(match["after"])
|
||||||
|
|
||||||
if len(match["after"]) > 0 {
|
if len(match["after"]) > 0 {
|
||||||
@ -80,8 +78,6 @@ func (s *SentryDebugWriter) Write(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
func (s *SentryDebugWriter) Close(exitCode int) {
|
func (s *SentryDebugWriter) Close(exitCode int) {
|
||||||
if s.lastSpan != nil {
|
if s.lastSpan != nil {
|
||||||
s.lastSpanLock.Lock()
|
|
||||||
defer s.lastSpanLock.Unlock()
|
|
||||||
s.lastSpan.Op = "nomad.execute.disconnect"
|
s.lastSpan.Op = "nomad.execute.disconnect"
|
||||||
s.lastSpan.SetTag("exit_code", strconv.Itoa(exitCode))
|
s.lastSpan.SetTag("exit_code", strconv.Itoa(exitCode))
|
||||||
s.lastSpan.Finish()
|
s.lastSpan.Finish()
|
||||||
@ -97,8 +93,6 @@ func (s *SentryDebugWriter) handleTimeDebugMessage(match map[string][]byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.lastSpanLock.Lock()
|
|
||||||
defer s.lastSpanLock.Unlock()
|
|
||||||
if s.lastSpan != nil {
|
if s.lastSpan != nil {
|
||||||
s.lastSpan.EndTime = time.UnixMilli(timestamp)
|
s.lastSpan.EndTime = time.UnixMilli(timestamp)
|
||||||
s.lastSpan.SetData("latency", time.Since(time.UnixMilli(timestamp)).String())
|
s.lastSpan.SetData("latency", time.Since(time.UnixMilli(timestamp)).String())
|
||||||
|
Reference in New Issue
Block a user