From 16fbd8121e9047e0f2fafaa84b0632ecf20a548e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:03:28 +0200 Subject: [PATCH 1/3] chore(deps): bump django from 4.2.16 to 4.2.17 in /packages/python/examples/metrics_django (#1144) Bumps [django](https://github.com/django/django) from 4.2.16 to 4.2.17.
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=django&package-manager=pip&previous-version=4.2.16&new-version=4.2.17)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/readmeio/metrics-sdks/network/alerts).
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/python/examples/metrics_django/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/examples/metrics_django/requirements.txt b/packages/python/examples/metrics_django/requirements.txt index 3ea3ae4eaf..7192895118 100644 --- a/packages/python/examples/metrics_django/requirements.txt +++ b/packages/python/examples/metrics_django/requirements.txt @@ -2,7 +2,7 @@ asgiref==3.8.1 certifi==2024.7.4 chardet==5.2.0 click==8.1.7 -Django==4.2.16 +Django==4.2.17 Flask==3.0.3 idna==3.7 itsdangerous==2.2.0 From 9514eef3d379d4e257f1ae9a5e5c38c079d98538 Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:05:38 +0200 Subject: [PATCH 2/3] feat(dotnet): add fireAndForget option (#1140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🧰 Changes Add logic for "fire and forget" config option (the same as we have in Node). --- packages/dotnet/ReadMe/ConfigValues.cs | 2 ++ .../HarJsonTranslationLogics/ReadmeApiCaller.cs | 11 +++++++++-- packages/dotnet/ReadMe/Metrics.cs | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/dotnet/ReadMe/ConfigValues.cs b/packages/dotnet/ReadMe/ConfigValues.cs index ccd2b753de..e11cbd1d52 100644 --- a/packages/dotnet/ReadMe/ConfigValues.cs +++ b/packages/dotnet/ReadMe/ConfigValues.cs @@ -27,5 +27,7 @@ public class Options public int bufferLength { get; set; } = 1; public string baseLogUrl { get; set; } = "https://example.readme.com"; + + public bool fireAndForget { get; set; } = true; } } diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs index 001e77ee93..c90b4f8f1f 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs @@ -16,7 +16,7 @@ public ReadMeApiCaller(string harJsonObject, string apiKey) this.apiKey = apiKey; } - public void SendHarObjToReadMeApi() + public void SendHarObjToReadMeApi(bool fireAndForget) { try { @@ -26,7 +26,14 @@ public void SendHarObjToReadMeApi() string apiKey = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.apiKey + ":")); request.AddHeader("Authorization", apiKey); request.AddParameter("application/json", this.harJsonObject, ParameterType.RequestBody); - client.ExecuteAsync(request); + if (fireAndForget) + { + client.ExecuteAsync(request); + } + else + { + client.Execute(request); + } } catch (Exception) { diff --git a/packages/dotnet/ReadMe/Metrics.cs b/packages/dotnet/ReadMe/Metrics.cs index 6bf275b585..417a47776d 100644 --- a/packages/dotnet/ReadMe/Metrics.cs +++ b/packages/dotnet/ReadMe/Metrics.cs @@ -46,7 +46,7 @@ public async Task InvokeAsync(HttpContext context) string harJsonObj = await harJsonBuilder.BuildHar(); ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(harJsonObj, configValues.apiKey); - readmeApiCaller.SendHarObjToReadMeApi(); + readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget); } else { @@ -114,6 +114,11 @@ private ConfigValues GetConfigValues() optionsObj.baseLogUrl = options.GetSection("baseLogUrl").Value; } + if (options.GetSection("fireAndForget").Value != null) + { + optionsObj.fireAndForget = bool.Parse(options.GetSection("fireAndForget").Value); + } + configValues.options = optionsObj; return configValues; } From 59ba597f3868c28b15561399f87ee00f4d612ffd Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:48:50 +0200 Subject: [PATCH 3/3] feat(dotnet): buffer-length check & queue (#1139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🧰 Changes Add logic for buffer length config option (the same as we have in Node). --- .../HarJsonTranslationLogics/HarJsonBuilder.cs | 6 ++---- .../ReadmeApiCaller.cs | 8 ++++---- packages/dotnet/ReadMe/Metrics.cs | 18 +++++++++++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs index 32a0d105aa..56b701e01c 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; using ReadMe.HarJsonObjectModels; namespace ReadMe.HarJsonTranslationLogics @@ -28,7 +27,7 @@ public HarJsonBuilder(RequestDelegate next, HttpContext context, IConfiguration this.configValues = configValues; } - public async Task BuildHar() + internal async Task BuildHar() { Root harObj = new Root(); harObj._id = Guid.NewGuid().ToString(); @@ -37,8 +36,7 @@ public async Task BuildHar() harObj.clientIPAddress = this.context.Connection.RemoteIpAddress.ToString(); harObj.group = this.BuildGroup(); harObj.request = new RequestMain(await this.BuildLog()); - string harJsonObj = JsonConvert.SerializeObject(new List() { harObj }); - return harJsonObj; + return harObj; } private Group BuildGroup() diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs index c90b4f8f1f..fb0aa33fe7 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/ReadmeApiCaller.cs @@ -7,12 +7,12 @@ namespace ReadMe.HarJsonTranslationLogics { class ReadMeApiCaller { - private readonly string harJsonObject; + private readonly string harJsonObjects; private readonly string apiKey; - public ReadMeApiCaller(string harJsonObject, string apiKey) + public ReadMeApiCaller(string harJsonObjects, string apiKey) { - this.harJsonObject = harJsonObject; + this.harJsonObjects = harJsonObjects; this.apiKey = apiKey; } @@ -25,7 +25,7 @@ public void SendHarObjToReadMeApi(bool fireAndForget) request.AddHeader("Content-Type", "application/json"); string apiKey = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.apiKey + ":")); request.AddHeader("Authorization", apiKey); - request.AddParameter("application/json", this.harJsonObject, ParameterType.RequestBody); + request.AddParameter("application/json", this.harJsonObjects, ParameterType.RequestBody); if (fireAndForget) { client.ExecuteAsync(request); diff --git a/packages/dotnet/ReadMe/Metrics.cs b/packages/dotnet/ReadMe/Metrics.cs index 417a47776d..b42849b0e9 100644 --- a/packages/dotnet/ReadMe/Metrics.cs +++ b/packages/dotnet/ReadMe/Metrics.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; using ReadMe.HarJsonObjectModels; using ReadMe.HarJsonTranslationLogics; @@ -11,12 +12,14 @@ public class Metrics { private readonly RequestDelegate next; private readonly IConfiguration configuration; + private readonly List harQueue; private Group group; public Metrics(RequestDelegate next, IConfiguration configuration) { this.next = next; this.configuration = configuration; + this.harQueue = new List(); } public async Task InvokeAsync(HttpContext context) @@ -44,9 +47,18 @@ public async Task InvokeAsync(HttpContext context) context.Request.EnableBuffering(); HarJsonBuilder harJsonBuilder = new HarJsonBuilder(this.next, context, this.configuration, configValues); - string harJsonObj = await harJsonBuilder.BuildHar(); - ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(harJsonObj, configValues.apiKey); - readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget); + var harObj = await harJsonBuilder.BuildHar(); + lock (this.harQueue) + { + this.harQueue.Add(harObj); + if (this.harQueue.Count >= configValues.options.bufferLength) + { + string serializaedHars = JsonConvert.SerializeObject(this.harQueue); + ReadMeApiCaller readmeApiCaller = new ReadMeApiCaller(serializaedHars, configValues.apiKey); + readmeApiCaller.SendHarObjToReadMeApi(configValues.options.fireAndForget); + this.harQueue.Clear(); + } + } } else {