diff --git a/Myriad/Rest/BaseRestClient.cs b/Myriad/Rest/BaseRestClient.cs index 4013cc22..68ecc9d6 100644 --- a/Myriad/Rest/BaseRestClient.cs +++ b/Myriad/Rest/BaseRestClient.cs @@ -179,7 +179,7 @@ namespace Myriad.Rest var request = createRequest(); _logger.Debug("Request: {RequestMethod} {RequestPath}", - request.Method, request.RequestUri?.ToString().Substring(_baseUrl.Length)); + request.Method, CleanForLogging(request.RequestUri!)); request.Version = _httpVersion; request.VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher; @@ -204,7 +204,7 @@ namespace Myriad.Rest _logger.Debug( "Response: {RequestMethod} {RequestPath} -> {StatusCode} {ReasonPhrase} (in {ResponseDurationMs} ms)", - request.Method, request.RequestUri?.ToString().Substring(_baseUrl.Length), (int)response.StatusCode, + request.Method, CleanForLogging(request.RequestUri!), (int)response.StatusCode, response.ReasonPhrase, stopwatch.ElapsedMilliseconds); await HandleApiError(response, ignoreNotFound); @@ -305,5 +305,20 @@ namespace Myriad.Rest var routePath = NormalizeRoutePath(localPath); return $"{req.Method} {routePath}"; } + + private string CleanForLogging(Uri uri) + { + var path = uri.ToString(); + + // don't show tokens in logs + // todo: anything missing here? + path = Regex.Replace(path, @"/webhooks/(\d+)/[^/]+", "/webhooks/$1/:token"); + path = Regex.Replace(path, @"/interactions/(\d+)/[^{/]+", "/interactions/$1/:token"); + + // remove base URL + path = path.Substring(_baseUrl.Length); + + return path; + } } } \ No newline at end of file