diff --git a/LambdaExtension/LambdaExtension.csproj b/LambdaExtension/LambdaExtension.csproj
new file mode 100644
index 0000000..b9de063
--- /dev/null
+++ b/LambdaExtension/LambdaExtension.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/MoesifMiddlewareExample.sln b/MoesifMiddlewareExample.sln
index 9eebb22..d75673b 100644
--- a/MoesifMiddlewareExample.sln
+++ b/MoesifMiddlewareExample.sln
@@ -12,9 +12,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoesifNet8Example", "Moesif
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MoesifNet6Example", "MoesifNet6Example\MoesifNet6Example.csproj", "{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Middleware", "..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj", "{2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Api", "..\moesifapi-csharp\Moesif.Api\Moesif.Api.csproj", "{B4A40605-57BA-4C5D-B68F-348717EF61B1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Api", "..\moesifapi-csharp\Moesif.Api\Moesif.Api.csproj", "{1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moesif.Middleware", "..\moesif-dotnet\Moesif.Middleware\Moesif.Middleware.csproj", "{E49606CF-77F8-48BA-B265-AA85BC980193}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -42,14 +42,14 @@ Global
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F248B0AC-68C5-46F8-BA5D-9E275ADC4F08}.Release|Any CPU.Build.0 = Release|Any CPU
- {2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {2D2E12C2-4C03-4939-A0B7-4FDD367D29D3}.Release|Any CPU.Build.0 = Release|Any CPU
- {1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {1A2A5E0A-E7F2-4780-B253-6DE1ABBAB4FC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B4A40605-57BA-4C5D-B68F-348717EF61B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B4A40605-57BA-4C5D-B68F-348717EF61B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B4A40605-57BA-4C5D-B68F-348717EF61B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B4A40605-57BA-4C5D-B68F-348717EF61B1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E49606CF-77F8-48BA-B265-AA85BC980193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E49606CF-77F8-48BA-B265-AA85BC980193}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E49606CF-77F8-48BA-B265-AA85BC980193}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E49606CF-77F8-48BA-B265-AA85BC980193}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/MoesifNet6Example/Controllers/EmployeeController.cs b/MoesifNet6Example/Controllers/EmployeeController.cs
index 96ac093..1a20fe0 100644
--- a/MoesifNet6Example/Controllers/EmployeeController.cs
+++ b/MoesifNet6Example/Controllers/EmployeeController.cs
@@ -5,24 +5,105 @@
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using MoesifNet6Example.Models;
+using System.Threading;
namespace MoesifNet6Example.Controllers
{
[Route("api/[controller]")]
public class EmployeeController : ControllerBase
{
+ private const int MAX_SIZE_75_KB = 75;
+ private const int MAX_SIZE_150_KB = 150;
+
+ public EmployeeController()
+ {
+ Console.WriteLine("EmployeeController constructor called");
+ }
+
+ private static string GenerateLargeResponseBody(int sizeInKB)
+ {
+ const string baseString = "This is a test string. ";
+ int repetitions = (sizeInKB * 1024); // / baseString.Length;
+ return new string('A', repetitions); // Create a large string filled with 'A's
+ }
[HttpGet("{id}")]
public IActionResult GetByID(int id)
{
+ Console.WriteLine($"BEGIN: EmployeeController GetByID method called with id: {id}");
var employee = new Employee()
{
ID = id,
- FirstName = "firstName",
+ FirstName = "No Delay",
LastName = "Very Long LastName From Moesif for API Awesomeness of Moesif",
DateOfBirth = DateTime.Now.AddYears(-30)
};
+
+ Console.WriteLine($"END : Employee object created: {employee.ID}, {employee.FirstName}, {employee.LastName}");
+
+ return Ok(employee);
+ }
+
+ [HttpGet("delay_random/{id}")]
+ public IActionResult GetEventId(int id)
+ {
+ var employee = new Employee()
+ {
+ ID = id,
+ FirstName = $"Get-Event-{id}",
+ LastName = $"Delayed-By-{id}-MS",
+ DateOfBirth = DateTime.Now.AddYears(-30)
+ };
+
+ Thread.Sleep(id); // Sleeps for id milliseconds
+
+ return Ok(employee);
+ }
+
+ [HttpGet("payload75/{id}")]
+ public IActionResult GetNotificationId(int id)
+ {
+ int sleepTime = 100;
+ string firstName = $"Get-{id}-{MAX_SIZE_75_KB}-KB-{sleepTime}-MS";
+ string lastName = $"Delayed-By-{sleepTime}-MS";
+ if (id > 10)
+ {
+ lastName = GenerateLargeResponseBody(MAX_SIZE_75_KB);
+ }
+ var employee = new Employee()
+ {
+ ID = id,
+ FirstName = firstName,
+ LastName = lastName,
+ DateOfBirth = DateTime.Now.AddYears(-30)
+ };
+
+ Thread.Sleep(sleepTime); // Sleeps for id milliseconds
+
+ return Ok(employee);
+ }
+ [HttpGet("payload150/{id}")]
+ public IActionResult GetSubsId(int id)
+ {
+ int sleepTime = 100; // in ms
+ string firstName = $"Get-{id}-{MAX_SIZE_150_KB}-KB-{sleepTime}-MS";
+ string lastName = $"Delayed-By-{sleepTime}-MS";
+ if (id > 10)
+ {
+ lastName = GenerateLargeResponseBody(MAX_SIZE_150_KB);
+ }
+
+ var employee = new Employee()
+ {
+ ID = id,
+ FirstName = firstName,
+ LastName = lastName,
+ DateOfBirth = DateTime.Now.AddYears(-30)
+ };
+
+ Thread.Sleep(sleepTime); // Sleeps for id milliseconds
+
return Ok(employee);
}
@@ -30,7 +111,8 @@ public IActionResult GetByID(int id)
[HttpPost]
public IActionResult Post([FromBody] Employee employee)
{
-
+ Console.WriteLine("Post method called");
+
return Ok(employee);
}
}
diff --git a/MoesifNet6Example/MoesifNet6Example.csproj b/MoesifNet6Example/MoesifNet6Example.csproj
index ec8af9a..46914ce 100644
--- a/MoesifNet6Example/MoesifNet6Example.csproj
+++ b/MoesifNet6Example/MoesifNet6Example.csproj
@@ -3,6 +3,14 @@
net6.0
+
+
+ NET6_0_OR_GREATER
+ NETCORE
+
+
+
+
@@ -15,16 +23,16 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/MoesifNet6Example/Settings/MoesifOptions.cs b/MoesifNet6Example/Settings/MoesifOptions.cs
index c43119e..e69ece7 100644
--- a/MoesifNet6Example/Settings/MoesifOptions.cs
+++ b/MoesifNet6Example/Settings/MoesifOptions.cs
@@ -103,6 +103,18 @@ public bool isConfiguredMoesifApplicationId()
}
return !string.IsNullOrWhiteSpace(appId) && !appId.StartsWith("<");
}
+
+ public bool IsLambda()
+ {
+ var isLambda = false;
+ try {
+ isLambda = (bool) getMoesifOptions().GetValueOrDefault(MoesifOptionsParamNames.IsLambda);
+ }
+ catch (Exception ex){
+ Console.WriteLine("Error Reading Moesif Application Id in appsettings(.env).json: " + ex.Message );
+ }
+ return isLambda;
+ }
}
public class MoesifOptionsParamNames
diff --git a/MoesifNet6Example/Startup.cs b/MoesifNet6Example/Startup.cs
index 82b648d..1bfe027 100644
--- a/MoesifNet6Example/Startup.cs
+++ b/MoesifNet6Example/Startup.cs
@@ -1,5 +1,10 @@
+#define MOESIF_INSTRUMENT
+
using System;
using System.Collections.Generic;
+using System.Net;
+using System.Text.Json.Nodes;
+using Amazon.Lambda.APIGatewayEvents;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@@ -29,28 +34,68 @@ public void ConfigureServices(IServiceCollection services)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
+#if MOESIF_INSTRUMENT
+ Console.WriteLine($"Begin: Configure");
+#endif
+ var isLambda = false;
MoesifOptions mo = new MoesifOptions(Configuration);
ensureValidConfig(mo);
app.UseMiddleware(mo.getMoesifOptions());
+ isLambda = mo.IsLambda();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
-
+#if MOESIF_INSTRUMENT
+ Console.WriteLine($"Before: Configure / UseRouting");
+#endif
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
- await context.Response.WriteAsync("Hello World!");
+ var msg = $"Hello World! isLambd = {isLambda}";
+ Console.WriteLine($"Hit the home page: {msg}");
+ // if (isLambda)
+ // {
+ // var response = new APIGatewayProxyResponse
+ // {
+ // StatusCode = (int)HttpStatusCode.OK,
+ // Body = $"Welcome to Home! Request path: /",
+ // Headers = new Dictionary { { "Content-Type", "text/json" } }
+ // };
+ // }
+ // else
+ // {
+ await context.Response.WriteAsync(new JsonObject
+ {
+ ["msg"] = msg,
+ ["zipcode"] = 94709
+ }.ToString());
+ // }
+ });
+
+ endpoints.MapGet("/foo", async context =>
+ {
+ // var hdrs = new Dictionary { { "Content-Type", "text/json" } };
+ var response = new JsonObject
+ {
+ ["StatusCode"] = (int)HttpStatusCode.OK,
+ ["Body"] = $"Hello from Lambda! Request path: /foo"
+ };
+ await context.Response.WriteAsJsonAsync(response);
});
endpoints.MapControllerRoute(
name: "api",
pattern: "{controller}/{id}");
});
+
+#if MOESIF_INSTRUMENT
+ Console.WriteLine($"End: Configure");
+#endif
}
private static void ensureValidConfig(MoesifOptions mo)
diff --git a/MoesifNet6Example/appsettings.json b/MoesifNet6Example/appsettings.json
index 26f03b9..193e7e4 100644
--- a/MoesifNet6Example/appsettings.json
+++ b/MoesifNet6Example/appsettings.json
@@ -1,12 +1,13 @@
{
"MoesifOptions": {
+ "MyTag": "ILT_Org_PK_App",
"ApplicationId": "",
"LocalDebug": false,
"LogBody": true,
- "RequestMaxBodySize": 100,
- "ResponseMaxBodySize": 100,
+ "RequestMaxBodySize": 100000,
+ "ResponseMaxBodySize": 100000,
"LogBodyOutgoing": true,
- "ApiVersion": "3.1.0",
+ "ApiVersion": "3.1.2",
"EnableBatching": true,
"BatchSize": 1,
"IsLambda": true