telemetry fix
This commit is contained in:
1 parent
55bdf2855b
commit
6e964fa2e5
4 files changed
+78
-40
No files matched your search
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Nothing worth mentioning yet.
|
||||||
|
|
||||||
## [0.48.6] - 2026-10-03
|
## [0.48.6] - 2026-10-03
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -5,11 +5,57 @@ const SUPPORT_SERVER_ENVELOPE_URL = "https://playlet-v8556.ondigitalocean.app/en
|
|||||||
const SENTRY_FALLBACK_ENVELOPE_URL = "https://o4509923566288896.ingest.us.sentry.io/api/4512194184544256/envelope/"
|
const SENTRY_FALLBACK_ENVELOPE_URL = "https://o4509923566288896.ingest.us.sentry.io/api/4512194184544256/envelope/"
|
||||||
const SENTRY_FALLBACK_KEY = "a16c510299b23ccc63bdc84f751c9950"
|
const SENTRY_FALLBACK_KEY = "a16c510299b23ccc63bdc84f751c9950"
|
||||||
|
|
||||||
const SUPPORTS_ATTACHMENTS = false
|
|
||||||
|
|
||||||
namespace Sentry
|
namespace Sentry
|
||||||
|
|
||||||
function SendEvents(events as object) as integer
|
function SendEvents(events as object) as integer
|
||||||
|
payload = BuildEnvelope(events, false)
|
||||||
|
request = HttpClient.Post(SUPPORT_SERVER_ENVELOPE_URL, payload)
|
||||||
|
request.Header("Content-Type", "application/x-sentry-envelope")
|
||||||
|
response = request.Await()
|
||||||
|
' Only when the server never answered: its own failures hit every device at once and would exhaust the fallback's quota
|
||||||
|
if response.StatusCode() <= 0
|
||||||
|
LogWarnNoTelemetry("Support server unreachable, sending events to the Sentry fallback:", response.ErrorMessage())
|
||||||
|
request = HttpClient.Post(SENTRY_FALLBACK_ENVELOPE_URL, BuildEnvelope([CreateSupportServerUnreachableEvent(events[0], payload, response.ErrorMessage())], true))
|
||||||
|
request.Header("Content-Type", "application/x-sentry-envelope")
|
||||||
|
request.QueryParam("sentry_key", SENTRY_FALLBACK_KEY)
|
||||||
|
response = request.Await()
|
||||||
|
end if
|
||||||
|
|
||||||
|
if response.IsSuccess()
|
||||||
|
LogDebug("Sent events to", request.BuildUrl(), "Response:", response.Text())
|
||||||
|
return 0
|
||||||
|
end if
|
||||||
|
|
||||||
|
retryAfter = ValidString(response.Headers()["Retry-After"]).ToInt()
|
||||||
|
if retryAfter = 0
|
||||||
|
retryAfter = 60
|
||||||
|
end if
|
||||||
|
|
||||||
|
if response.StatusCode() = 429
|
||||||
|
LogErrorNoTelemetry("Rate limited by", request.BuildUrl(), "Retry after", retryAfter, "seconds")
|
||||||
|
else
|
||||||
|
LogErrorNoTelemetry("Failed to send events to", request.BuildUrl(), response.ErrorMessage(), `\nRetry after`, retryAfter, "seconds")
|
||||||
|
end if
|
||||||
|
return retryAfter
|
||||||
|
end function
|
||||||
|
|
||||||
|
function CreateSupportServerUnreachableEvent(originalEvent as object, payload as string, errorMessage as string) as object
|
||||||
|
return {
|
||||||
|
level: "warning"
|
||||||
|
message: `Support server unreachable: ${errorMessage}`
|
||||||
|
fingerprint: ["support server unreachable"]
|
||||||
|
release: originalEvent.release
|
||||||
|
tags: originalEvent.tags
|
||||||
|
userId: originalEvent.userId
|
||||||
|
attachments: [{
|
||||||
|
filename: "envelope.txt"
|
||||||
|
content_type: "text/plain"
|
||||||
|
data: payload
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
end function
|
||||||
|
|
||||||
|
function BuildEnvelope(events as object, supportsAttachments as boolean) as string
|
||||||
timestamp = CreateObject("roDateTime").ToISOString()
|
timestamp = CreateObject("roDateTime").ToISOString()
|
||||||
|
|
||||||
payload = FormatJson({
|
payload = FormatJson({
|
||||||
@@ -69,7 +115,7 @@ namespace Sentry
|
|||||||
|
|
||||||
hasAttachments = IsArray(event.attachments) and event.attachments.Count() > 0
|
hasAttachments = IsArray(event.attachments) and event.attachments.Count() > 0
|
||||||
|
|
||||||
if (not SUPPORTS_ATTACHMENTS) and hasAttachments
|
if (not supportsAttachments) and hasAttachments
|
||||||
extra = {}
|
extra = {}
|
||||||
for each attachment in event.attachments
|
for each attachment in event.attachments
|
||||||
extra[attachment.filename] = `content_type:${attachment.content_type}\n${Redact(attachment.data)}`
|
extra[attachment.filename] = `content_type:${attachment.content_type}\n${Redact(attachment.data)}`
|
||||||
@@ -83,7 +129,7 @@ namespace Sentry
|
|||||||
|
|
||||||
payload += FormatJson(eventPayload) + `\n`
|
payload += FormatJson(eventPayload) + `\n`
|
||||||
|
|
||||||
if SUPPORTS_ATTACHMENTS and hasAttachments
|
if supportsAttachments and hasAttachments
|
||||||
tmpBuffer = CreateObject("roByteArray")
|
tmpBuffer = CreateObject("roByteArray")
|
||||||
for each attachment in event.attachments
|
for each attachment in event.attachments
|
||||||
data = Redact(attachment.data)
|
data = Redact(attachment.data)
|
||||||
@@ -98,34 +144,7 @@ namespace Sentry
|
|||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
|
|
||||||
request = HttpClient.Post(SUPPORT_SERVER_ENVELOPE_URL, payload)
|
return payload
|
||||||
request.Header("Content-Type", "application/x-sentry-envelope")
|
|
||||||
response = request.Await()
|
|
||||||
' Only when the server never answered: its own failures hit every device at once and would exhaust the fallback's quota
|
|
||||||
if response.StatusCode() <= 0
|
|
||||||
LogWarnNoTelemetry("Support server unreachable, sending events to the Sentry fallback:", response.ErrorMessage())
|
|
||||||
request = HttpClient.Post(SENTRY_FALLBACK_ENVELOPE_URL, payload)
|
|
||||||
request.Header("Content-Type", "application/x-sentry-envelope")
|
|
||||||
request.QueryParam("sentry_key", SENTRY_FALLBACK_KEY)
|
|
||||||
response = request.Await()
|
|
||||||
end if
|
|
||||||
|
|
||||||
if response.IsSuccess()
|
|
||||||
LogDebug("Sent events to", request.BuildUrl(), "Response:", response.Text())
|
|
||||||
return 0
|
|
||||||
end if
|
|
||||||
|
|
||||||
retryAfter = ValidString(response.Headers()["Retry-After"]).ToInt()
|
|
||||||
if retryAfter = 0
|
|
||||||
retryAfter = 60
|
|
||||||
end if
|
|
||||||
|
|
||||||
if response.StatusCode() = 429
|
|
||||||
LogErrorNoTelemetry("Rate limited by", request.BuildUrl(), "Retry after", retryAfter, "seconds")
|
|
||||||
else
|
|
||||||
LogErrorNoTelemetry("Failed to send events to", request.BuildUrl(), response.ErrorMessage(), `\nRetry after`, retryAfter, "seconds")
|
|
||||||
end if
|
|
||||||
return retryAfter
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetFingerprint(message as dynamic) as dynamic
|
function GetFingerprint(message as dynamic) as dynamic
|
||||||
@@ -165,7 +184,7 @@ namespace Sentry
|
|||||||
return text
|
return text
|
||||||
end if
|
end if
|
||||||
|
|
||||||
authHeader = /Authorization: [^\r\n]*/i
|
authHeader = /Authorization: (?!<REDACTED>)[^\r\n]*/i
|
||||||
for each match in authHeader.MatchAll(text)
|
for each match in authHeader.MatchAll(text)
|
||||||
text = text.Replace(match[0], "Authorization: <REDACTED>")
|
text = text.Replace(match[0], "Authorization: <REDACTED>")
|
||||||
end for
|
end for
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#const SUPPORTS_BATCHING = false
|
#const SUPPORTS_BATCHING = true
|
||||||
|
|
||||||
import "pkg:/components/Telemetry/LastExitCrash.bs"
|
import "pkg:/components/Telemetry/LastExitCrash.bs"
|
||||||
import "pkg:/components/Telemetry/Sentry.bs"
|
import "pkg:/components/Telemetry/Sentry.bs"
|
||||||
@@ -72,7 +72,8 @@ function TelemetryLoop() as void
|
|||||||
"LogError": "error"
|
"LogError": "error"
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = []
|
receivedAt = CreateObject("roDateTime")
|
||||||
|
inbox = []
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
while true
|
while true
|
||||||
@@ -86,7 +87,8 @@ function TelemetryLoop() as void
|
|||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
messages.Push(msg)
|
receivedAt.Mark()
|
||||||
|
inbox.Push({ msg: msg, timestamp: receivedAt.ToISOString() })
|
||||||
|
|
||||||
#if SUPPORTS_BATCHING
|
#if SUPPORTS_BATCHING
|
||||||
debounceTimer.Mark()
|
debounceTimer.Mark()
|
||||||
@@ -97,8 +99,9 @@ function TelemetryLoop() as void
|
|||||||
LogDebug("No more messages")
|
LogDebug("No more messages")
|
||||||
exit while
|
exit while
|
||||||
end if
|
end if
|
||||||
messages.Push(msg)
|
receivedAt.Mark()
|
||||||
if messages.Count() >= debounceCountLimit
|
inbox.Push({ msg: msg, timestamp: receivedAt.ToISOString() })
|
||||||
|
if inbox.Count() >= debounceCountLimit
|
||||||
LogDebug("Reached debounce count limit")
|
LogDebug("Reached debounce count limit")
|
||||||
exit while
|
exit while
|
||||||
end if
|
end if
|
||||||
@@ -110,7 +113,8 @@ function TelemetryLoop() as void
|
|||||||
#end if
|
#end if
|
||||||
|
|
||||||
events.Clear()
|
events.Clear()
|
||||||
for each msg in messages
|
for each item in inbox
|
||||||
|
msg = item.msg
|
||||||
msgType = type(msg)
|
msgType = type(msg)
|
||||||
if msgType <> "roSGNodeEvent"
|
if msgType <> "roSGNodeEvent"
|
||||||
continue for
|
continue for
|
||||||
@@ -122,6 +126,7 @@ function TelemetryLoop() as void
|
|||||||
events.Push({
|
events.Push({
|
||||||
level: levelMap[field]
|
level: levelMap[field]
|
||||||
message: msg.getData()
|
message: msg.getData()
|
||||||
|
timestamp: item.timestamp
|
||||||
release: m.release
|
release: m.release
|
||||||
dist: m.dist
|
dist: m.dist
|
||||||
tags: m.tags
|
tags: m.tags
|
||||||
@@ -132,6 +137,7 @@ function TelemetryLoop() as void
|
|||||||
events.Push({
|
events.Push({
|
||||||
level: data.level
|
level: data.level
|
||||||
message: data.message
|
message: data.message
|
||||||
|
timestamp: item.timestamp
|
||||||
release: m.release
|
release: m.release
|
||||||
dist: m.dist
|
dist: m.dist
|
||||||
tags: m.tags
|
tags: m.tags
|
||||||
@@ -141,7 +147,7 @@ function TelemetryLoop() as void
|
|||||||
})
|
})
|
||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
messages.Clear()
|
inbox.Clear()
|
||||||
|
|
||||||
if events.Count() = 0
|
if events.Count() = 0
|
||||||
continue while
|
continue while
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ namespace Tests
|
|||||||
m.assertEqual(Sentry.Redact(42), 42)
|
m.assertEqual(Sentry.Redact(42), 42)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
@it("leaves an already-masked Authorization header alone inside a serialized envelope line")
|
||||||
|
function alreadyRedactedInEnvelopeLine()
|
||||||
|
line = FormatJson({
|
||||||
|
extra: { "request.txt": "curl -H 'Authorization: <REDACTED>'" + Chr(10) + " -H 'X-Other: 1'" }
|
||||||
|
level: "error"
|
||||||
|
})
|
||||||
|
m.assertEqual(Sentry.Redact(line), line)
|
||||||
|
end function
|
||||||
|
|
||||||
end class
|
end class
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
Reference in new issue
Block a user