Filter out telemetry from when not needed

This commit is contained in:
Brahim Hadriche committed 2025-09-03 15:40:09 -04:00
1 parent 207f96c882
commit 0c79787161
16 files changed
+63 -56

No files matched your search

@@ -43,7 +43,7 @@ function OnRequest(event as object) as void
m.pendingRequestEvents = [] m.pendingRequestEvents = []
end if end if
m.pendingRequestEvents.push(event) m.pendingRequestEvents.push(event)
LogWarn("JobQueue: Job queue task is not ready, request will be queued") LogWarnNoTelemetry("JobQueue: Job queue task is not ready, request will be queued")
return return
end if end if
@@ -62,9 +62,7 @@ function RunTests(instance as string, content as object, cancellation as object)
testNode.title = `${testNode.title} (${testNode.duration}ms)` testNode.title = `${testNode.title} (${testNode.duration}ms)`
if testNode.state = "failed" if testNode.state = "failed"
m.noTelemetry = true LogErrorNoTelemetry(testNode.details)
LogError(testNode.details)
m.noTelemetry = false
end if end if
if CancellationUtils.IsCancelled(cancellation) if CancellationUtils.IsCancelled(cancellation)
@@ -48,9 +48,7 @@ class DashManifest
audioStreams = m.getAudioStreams(adaptiveFormats) audioStreams = m.getAudioStreams(adaptiveFormats)
videoStreams = m.getVideoStreams(adaptiveFormats, qualityFilter) videoStreams = m.getVideoStreams(adaptiveFormats, qualityFilter)
if videoStreams.Count() = 0 if videoStreams.Count() = 0
m.noTelemetry = true LogWarnNoTelemetry("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams")
LogWarn("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams")
m.noTelemetry = false
videoStreams = m.getVideoStreams(adaptiveFormats, {}) videoStreams = m.getVideoStreams(adaptiveFormats, {})
end if end if
@@ -204,9 +202,7 @@ class DashManifest
templateUrl = storyboard.templateUrl templateUrl = storyboard.templateUrl
if templateUrl.Instr("$M") = -1 if templateUrl.Instr("$M") = -1
m.noTelemetry = true LogWarnNoTelemetry("Invalid storyboard url: url does not contain $M:", templateUrl)
LogInfo("Invalid storyboard url: url does not contain $M:", templateUrl)
m.noTelemetry = false
continue for continue for
end if end if
@@ -610,13 +610,11 @@ namespace Innertube
videoId = ObjectUtils.Dig(nodeData, ["updatedMetadataEndpoint", "updatedMetadataEndpoint", "videoId"]) videoId = ObjectUtils.Dig(nodeData, ["updatedMetadataEndpoint", "updatedMetadataEndpoint", "videoId"])
if not IsString(videoId) if not IsString(videoId)
' TODO:P1 confirm that videoPrimaryInfoRenderer has the requested video ' TODO:P1 confirm that videoPrimaryInfoRenderer has the requested video
m.noTelemetry = true
#if DEBUG #if DEBUG
LogWarn("Invalid video ID in videoPrimaryInfoRenderer", `\n`, FormatJson(nodeData)) LogWarnNoTelemetry("Invalid video ID in videoPrimaryInfoRenderer", `\n`, FormatJson(nodeData))
#else #else
LogWarn("Invalid video ID in videoPrimaryInfoRenderer") LogWarnNoTelemetry("Invalid video ID in videoPrimaryInfoRenderer")
#end if #end if
m.noTelemetry = false
return invalid return invalid
end if end if
end if end if
@@ -1735,9 +1733,7 @@ namespace Innertube
function Warning(message as string, nodeData as object) as void function Warning(message as string, nodeData as object) as void
nodeDataString = FormatJson(nodeData) nodeDataString = FormatJson(nodeData)
m.noTelemetry = true LogWarnNoTelemetry(message + `\n` + nodeDataString)
LogWarn(message + `\n` + nodeDataString)
m.noTelemetry = false
m.global.telemetry.LogEvent = { m.global.telemetry.LogEvent = {
level: "error" level: "error"
@@ -374,7 +374,11 @@ namespace Innertube
request.NoCache() request.NoCache()
response = request.Await() response = request.Await()
if not response.IsSuccess() if not response.IsSuccess()
LogError(response.ErrorMessage()) if response.IsCancelled()
LogErrorNoTelemetry(response.ErrorMessage())
else
LogError(response.ErrorMessage())
end if
return invalid return invalid
end if end if
@@ -409,7 +413,11 @@ namespace Innertube
response = request.Await() response = request.Await()
if not response.IsSuccess() if not response.IsSuccess()
LogError(response.ErrorMessage()) if response.IsCancelled()
LogErrorNoTelemetry(response.ErrorMessage())
else
LogError(response.ErrorMessage())
end if
code = "" code = ""
if response.StatusCode() = 400 if response.StatusCode() = 400
json = response.Json() json = response.Json()
@@ -83,9 +83,7 @@ class LongPoller
' Not receiving data for LONG_POLL_TIMEOUT_MS seconds might be a sign of a dead connection ' Not receiving data for LONG_POLL_TIMEOUT_MS seconds might be a sign of a dead connection
if m.socket_timer.TotalMilliseconds() > LONG_POLL_TIMEOUT_MS if m.socket_timer.TotalMilliseconds() > LONG_POLL_TIMEOUT_MS
m.noTelemetry = true LogWarnNoTelemetry("Timeout after", LONG_POLL_TIMEOUT_MS, "ms")
LogWarn("Timeout after", LONG_POLL_TIMEOUT_MS, "ms")
m.noTelemetry = false
m.CloseSocket() m.CloseSocket()
return false return false
end if end if
@@ -555,7 +555,11 @@ class LoungeApi
}) })
if not response.IsSuccess() if not response.IsSuccess()
LogError(response.ErrorMessage()) if response.StatusCode() = 400 and response.ErrorMessage().InStr("Unknown SID") <> -1
LogErrorNoTelemetry(response.ErrorMessage())
else
LogError(response.ErrorMessage())
end if
end if end if
m.outgoingMessagesRequests.Delete(key) m.outgoingMessagesRequests.Delete(key)
@@ -87,7 +87,11 @@ namespace SponsorBlock
url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}` url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}`
response = HttpClient.Get(url).Cancellation(cancellation).Await() response = HttpClient.Get(url).Cancellation(cancellation).Await()
if not response.IsSuccess() if not response.IsSuccess()
LogError("GetSkipSegmentsForVideo failed:", response.ErrorMessage()) if response.IsCancelled()
LogErrorNoTelemetry(response.ErrorMessage())
else
LogError(response.ErrorMessage())
end if
return invalid return invalid
end if end if
@@ -78,9 +78,7 @@ namespace Sentry
response = request.Await() response = request.Await()
if not response.IsSuccess() if not response.IsSuccess()
#if DEBUG #if DEBUG
m.noTelemetry = true LogErrorNoTelemetry("Failed to send event to Sentry:", response.ErrorMessage())
LogError("Failed to send event to Sentry:", response.ErrorMessage())
m.noTelemetry = false
#end if #end if
statusCode = response.StatusCode() statusCode = response.StatusCode()
@@ -241,15 +241,11 @@ end function
function HandleFeedLoadErrorDialog(error as object, isCancelled as boolean, rowList as object) as void function HandleFeedLoadErrorDialog(error as object, isCancelled as boolean, rowList as object) as void
error = ErrorUtils.Format(error) error = ErrorUtils.Format(error)
if isCancelled if isCancelled
m.noTelemetry = true LogErrorNoTelemetry(error)
else
LogError(error)
end if end if
LogError(error)
if isCancelled
m.noTelemetry = false
end if
rowList.onError = error rowList.onError = error
if rowList.hasField("dispose") and rowList.dispose if rowList.hasField("dispose") and rowList.dispose
return return
@@ -445,9 +445,7 @@ function OnVideoPlayerStateChange() as void
errorInfo = m.top.errorInfo errorInfo = m.top.errorInfo
errorData = GetPlayerErrorData(content.videoId, errorInfo) errorData = GetPlayerErrorData(content.videoId, errorInfo)
m.noTelemetry = true LogErrorNoTelemetry(errorData.title, errorData.body)
LogError(errorData.title, errorData.body)
m.noTelemetry = false
m.global.telemetry.LogEvent = { m.global.telemetry.LogEvent = {
level: "error" level: "error"
message: errorData.title + `\n` + errorData.body message: errorData.title + `\n` + errorData.body
@@ -501,9 +499,7 @@ function OnVideoPlayerStateChange() as void
errorInfo = m.top.errorInfo errorInfo = m.top.errorInfo
errorData = GetPlayerErrorData(content.videoId, errorInfo) errorData = GetPlayerErrorData(content.videoId, errorInfo)
m.noTelemetry = true LogErrorNoTelemetry(errorData.title, errorData.body)
LogError(errorData.title, errorData.body)
m.noTelemetry = false
m.global.telemetry.LogEvent = { m.global.telemetry.LogEvent = {
level: "error" level: "error"
message: errorData.title + `\n` + errorData.body message: errorData.title + `\n` + errorData.body
@@ -171,9 +171,7 @@ namespace Http
end for end for
if includedQualitiesCount = 0 if includedQualitiesCount = 0
m.noTelemetry = true LogWarnNoTelemetry("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams")
LogWarn("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams")
m.noTelemetry = false
return hlsManifest return hlsManifest
end if end if
return newLines.join(`\n`) return newLines.join(`\n`)
@@ -214,9 +214,7 @@ namespace Http
if not hasContinuation if not hasContinuation
page = ValidString(request.query.page).ToInt() page = ValidString(request.query.page).ToInt()
if page > 1 if page > 1
m.noTelemetry = true LogErrorNoTelemetry("Playlet backend does not use history pagination (use continuation instead)")
LogError("Playlet backend does not use history pagination (use continuation instead)")
m.noTelemetry = false
response.Json({ response.Json({
"items": [] "items": []
}) })
@@ -165,9 +165,7 @@ namespace Http
if m.socket.eSuccess() if m.socket.eSuccess()
LogDebug(op + " peer closed @" + m.client) LogDebug(op + " peer closed @" + m.client)
else else
m.noTelemetry = true LogErrorNoTelemetry(op + " transfer error @" + m.client, m.socket.status())
LogError(op + " transfer error @" + m.client, m.socket.status())
m.noTelemetry = false
end if end if
m.close = true m.close = true
m.SetState(Http.HttpConnectionState.DONE) m.SetState(Http.HttpConnectionState.DONE)
+8
View File
@@ -9,10 +9,18 @@ function LogError(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3
throw "FATAL: Calling LogError() which is a stub function" throw "FATAL: Calling LogError() which is a stub function"
end function end function
function LogErrorNoTelemetry(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void
throw "FATAL: Calling LogErrorNoTelemetry() which is a stub function"
end function
function LogWarn(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void function LogWarn(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void
throw "FATAL: Calling LogWarn() which is a stub function" throw "FATAL: Calling LogWarn() which is a stub function"
end function end function
function LogWarnNoTelemetry(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void
throw "FATAL: Calling LogWarnNoTelemetry() which is a stub function"
end function
function LogInfo(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void function LogInfo(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void
throw "FATAL: Calling LogInfo() which is a stub function" throw "FATAL: Calling LogInfo() which is a stub function"
end function end function
+18 -7
View File
@@ -22,18 +22,32 @@ const logFunctions = {
LogError: { LogError: {
stringLevel: 'ERROR', stringLevel: 'ERROR',
level: 0, level: 0,
telemetry: true
},
LogErrorNoTelemetry: {
stringLevel: 'ERROR',
level: 0,
telemetry: false
}, },
LogWarn: { LogWarn: {
stringLevel: 'WARN', stringLevel: 'WARN',
level: 1, level: 1,
telemetry: true
},
LogWarnNoTelemetry: {
stringLevel: 'WARN',
level: 1,
telemetry: false
}, },
LogInfo: { LogInfo: {
stringLevel: 'INFO', stringLevel: 'INFO',
level: 2, level: 2,
telemetry: false
}, },
LogDebug: { LogDebug: {
stringLevel: 'DEBUG', stringLevel: 'DEBUG',
level: 3, level: 3,
telemetry: false
} }
} }
@@ -164,7 +178,7 @@ export class LoggerPlugin implements CompilerPlugin {
program.setFile(loggingFilePath, content) program.setFile(loggingFilePath, content)
} }
generateLoggingFunction(newFunctionName: string, level: string, argCount: number, isDebug: boolean) { generateLoggingFunction(newFunctionName: string, originalFunctionName: string, argCount: number, isDebug: boolean) {
const args: string[] = []; const args: string[] = [];
const argsParams: string[] = []; const argsParams: string[] = [];
for (let i = 0; i < argCount; i++) { for (let i = 0; i < argCount; i++) {
@@ -176,11 +190,11 @@ export class LoggerPlugin implements CompilerPlugin {
return `ToString(${arg})`; return `ToString(${arg})`;
}).join(` + " " + `); }).join(` + " " + `);
const func = logFunctions[level as 'LogError' | 'LogWarn' | 'LogInfo' | 'LogDebug']; const func = logFunctions[originalFunctionName as keyof typeof logFunctions];
let logLine = ''; let logLine = '';
const telemetryEnabled = level === 'LogError' || level === 'LogWarn'; const telemetryEnabled = func.telemetry;
if (isDebug) { if (isDebug) {
const RED = '[31m'; const RED = '[31m';
@@ -223,10 +237,7 @@ function ${newFunctionName}(${args.join(', ')}) as void
logger.logLine = line logger.logLine = line
`; `;
if (telemetryEnabled) { if (telemetryEnabled) {
result += ` if not (m.noTelemetry = true) result += ` m.global.telemetry.${originalFunctionName} = line\n`;
m.global.telemetry.${level} = line
end if
`;
} }
result += `end function result += `end function
`; `;