From 21237c2453e26c9f1688399dfdd596aaee32f119 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 | 10 ++++++++++ src/ApiService/ApiService/Log.cs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ApiService/ApiService/Functions/ReproVmss.cs b/src/ApiService/ApiService/Functions/ReproVmss.cs index a18e86433f..0af6258c4b 100644 --- a/src/ApiService/ApiService/Functions/ReproVmss.cs +++ b/src/ApiService/ApiService/Functions/ReproVmss.cs @@ -1,4 +1,6 @@ using System.Net; +using System.Security.Cryptography; +using System.Text; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; @@ -81,6 +83,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 76435890e0..1f4bcd6b5e 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) {