From 392e4cb34e0bbabdd7410b108216d3953a1a164b Mon Sep 17 00:00:00 2001 From: George Pollard Date: Tue, 9 May 2023 03:09:53 +0000 Subject: [PATCH] Add an event for Repro VM creation --- src/ApiService/ApiService/Functions/ReproVmss.cs | 13 ++++++++++++- src/ApiService/ApiService/Log.cs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ApiService/ApiService/Functions/ReproVmss.cs b/src/ApiService/ApiService/Functions/ReproVmss.cs index a18e86433f4..cdea19da69a 100644 --- a/src/ApiService/ApiService/Functions/ReproVmss.cs +++ b/src/ApiService/ApiService/Functions/ReproVmss.cs @@ -1,4 +1,7 @@ -using System.Net; +using System.IO; +using System.Net; +using System.Security.Cryptography; +using System.Text; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; @@ -81,6 +84,14 @@ private async Async.Task Post(HttpRequestData req) { "repro_vm create"); } + // we’d like to track the usage of this feature; + // anonymize the user ID so we can distinguish multiple requests + { + var data = userInfo.OkV.UserInfo.ToString(); // rely on record ToString + var hash = Convert.ToBase64String(SHA256.HashData(Encoding.UTF8.GetBytes(data))); + _log.Event($"created repro VM, user distinguisher: {hash:Tag:UserHash}"); + } + var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(vm.OkV); return response; diff --git a/src/ApiService/ApiService/Log.cs b/src/ApiService/ApiService/Log.cs index 76435890e0f..1f4bcd6b5ed 100644 --- a/src/ApiService/ApiService/Log.cs +++ b/src/ApiService/ApiService/Log.cs @@ -12,7 +12,7 @@ namespace Microsoft.OneFuzz.Service; [InterpolatedStringHandler] public struct LogStringHandler { - private StringBuilder _builder; + private readonly StringBuilder _builder; private Dictionary? _tags; public LogStringHandler(int literalLength, int formattedCount) {