Skip to content

Commit 70525fc

Browse files
ejsmithniemyjski
andauthored
Adding better support for serverless functions and sample projects to show how to use them (#243)
* Adding better support for serverless functions and sample projects to show how to use them * Some pr feedback. * Change name to ProcessQueueDeferred. Couple more lambda sample updates. * Minor * Change local server port from 50000 to 5000 Co-authored-by: Blake Niemyjski <[email protected]>
1 parent cfc0dee commit 70525fc

File tree

36 files changed

+612
-14
lines changed

36 files changed

+612
-14
lines changed

Exceptionless.Net.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exceptionless.SampleWpf", "
7676
EndProject
7777
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exceptionless.Extensions.Hosting", "src\Platforms\Exceptionless.Extensions.Hosting\Exceptionless.Extensions.Hosting.csproj", "{A5589072-EC59-4A6A-B78D-5D2ABB36DB1B}"
7878
EndProject
79+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exceptionless.SampleHosting", "samples\Exceptionless.SampleHosting\Exceptionless.SampleHosting.csproj", "{693ED127-0124-4697-8369-700717615E85}"
80+
EndProject
81+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exceptionless.SampleLambda", "samples\Exceptionless.SampleLambda\Exceptionless.SampleLambda.csproj", "{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7}"
82+
EndProject
83+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exceptionless.SampleLambdaAspNetCore", "samples\Exceptionless.SampleLambdaAspNetCore\Exceptionless.SampleLambdaAspNetCore.csproj", "{D9987952-B891-48B4-AA93-59AA39F33FC4}"
84+
EndProject
7985
Global
8086
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8187
Debug|Any CPU = Debug|Any CPU
@@ -174,6 +180,18 @@ Global
174180
{A5589072-EC59-4A6A-B78D-5D2ABB36DB1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
175181
{A5589072-EC59-4A6A-B78D-5D2ABB36DB1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
176182
{A5589072-EC59-4A6A-B78D-5D2ABB36DB1B}.Release|Any CPU.Build.0 = Release|Any CPU
183+
{693ED127-0124-4697-8369-700717615E85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
184+
{693ED127-0124-4697-8369-700717615E85}.Debug|Any CPU.Build.0 = Debug|Any CPU
185+
{693ED127-0124-4697-8369-700717615E85}.Release|Any CPU.ActiveCfg = Release|Any CPU
186+
{693ED127-0124-4697-8369-700717615E85}.Release|Any CPU.Build.0 = Release|Any CPU
187+
{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
188+
{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
189+
{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
190+
{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7}.Release|Any CPU.Build.0 = Release|Any CPU
191+
{D9987952-B891-48B4-AA93-59AA39F33FC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
192+
{D9987952-B891-48B4-AA93-59AA39F33FC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
193+
{D9987952-B891-48B4-AA93-59AA39F33FC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
194+
{D9987952-B891-48B4-AA93-59AA39F33FC4}.Release|Any CPU.Build.0 = Release|Any CPU
177195
EndGlobalSection
178196
GlobalSection(SolutionProperties) = preSolution
179197
HideSolutionNode = FALSE
@@ -201,6 +219,9 @@ Global
201219
{E1D077DE-C62E-4137-B609-3E9845C8A027} = {2CEE12C6-3840-4C01-A952-D3026B0A662A}
202220
{AD95A70D-18DB-414E-9F6C-1B13B4FBA56E} = {2CEE12C6-3840-4C01-A952-D3026B0A662A}
203221
{A5589072-EC59-4A6A-B78D-5D2ABB36DB1B} = {D363E15F-621D-40E4-8C96-DEE41A7070FF}
222+
{693ED127-0124-4697-8369-700717615E85} = {2CEE12C6-3840-4C01-A952-D3026B0A662A}
223+
{4B26BF7F-85FB-4B41-BF93-661E83A4EDD7} = {2CEE12C6-3840-4C01-A952-D3026B0A662A}
224+
{D9987952-B891-48B4-AA93-59AA39F33FC4} = {2CEE12C6-3840-4C01-A952-D3026B0A662A}
204225
EndGlobalSection
205226
GlobalSection(ExtensibilityGlobals) = postSolution
206227
SolutionGuid = {EBB2CC85-FF87-431B-865F-2F110B2A10E6}

samples/Exceptionless.SampleAspNetCore/Exceptionless.SampleAspNetCore.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\..\src\Exceptionless\Exceptionless.csproj" />
98
<ProjectReference Include="..\..\src\Platforms\Exceptionless.AspNetCore\Exceptionless.AspNetCore.csproj" />
10-
<ProjectReference Include="..\..\src\Platforms\Exceptionless.Extensions.Hosting\Exceptionless.Extensions.Hosting.csproj" />
119
<ProjectReference Include="..\..\src\Platforms\Exceptionless.Extensions.Logging\Exceptionless.Extensions.Logging.csproj" />
1210
</ItemGroup>
1311
</Project>

samples/Exceptionless.SampleAspNetCore/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Exceptionless": {
33
"ApiKey": "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
4-
"ServerUrl": "http://localhost:50000",
4+
"ServerUrl": "http://localhost:5000",
55
"DefaultData": {
66
"JSON_OBJECT": "{ \"Name\": \"Blake\" }",
77
"Boolean": true,

samples/Exceptionless.SampleConsole/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using LogLevel = Exceptionless.Logging.LogLevel;
2323

2424
// example of setting an attribute value in config.
25-
[assembly: Exceptionless("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw", ServerUrl = "http://localhost:50000")]
25+
[assembly: Exceptionless("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw", ServerUrl = "http://localhost:5000")]
2626
[assembly: ExceptionlessSetting("EnableWelcomeMessage", "True")]
2727

2828
namespace Exceptionless.SampleConsole {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\src\Platforms\Exceptionless.Extensions.Hosting\Exceptionless.Extensions.Hosting.csproj" />
9+
<ProjectReference Include="..\..\src\Platforms\Exceptionless.Extensions.Logging\Exceptionless.Extensions.Logging.csproj" />
10+
</ItemGroup>
11+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace Exceptionless.SampleHosting {
9+
public class Program {
10+
public static void Main(string[] args) {
11+
CreateHostBuilder(args).Build().Run();
12+
}
13+
14+
public static IHostBuilder CreateHostBuilder(string[] args) =>
15+
Host.CreateDefaultBuilder(args)
16+
.ConfigureLogging(builder => {
17+
// By default sends warning and error log messages to Exceptionless.
18+
// Log levels can be controlled remotely per log source from the Exceptionless app in near real-time.
19+
builder.AddExceptionless();
20+
})
21+
.UseExceptionless() // listens for host shutdown and
22+
.ConfigureServices(services => {
23+
// Reads settings from IConfiguration then adds additional configuration from this lambda.
24+
// This also configures ExceptionlessClient.Default
25+
services.AddExceptionless(c => c.DefaultData["Startup"] = "heyyy");
26+
// OR
27+
// services.AddExceptionless();
28+
// OR
29+
// services.AddExceptionless("API_KEY_HERE");
30+
31+
// adds a hosted service that will send sample events to Exceptionless.
32+
services.AddHostedService<SampleService>();
33+
})
34+
.UseConsoleLifetime()
35+
.ConfigureWebHostDefaults(builder => {
36+
builder.Configure(app => {
37+
app.UseRouting();
38+
app.UseEndpoints(endpoints => {
39+
endpoints.MapGet("/ping", context => {
40+
var client = context.RequestServices.GetRequiredService<ExceptionlessClient>();
41+
var logger = context.RequestServices.GetRequiredService<ILogger<Program>>();
42+
43+
// Submit a feature usage event directly using the client instance.
44+
client.SubmitFeatureUsage("MapGet_Ping");
45+
46+
// This log message will get sent to Exceptionless since Exceptionless has be added to the logging system in Program.cs.
47+
logger.LogWarning("Test warning message from ping");
48+
49+
try {
50+
throw new Exception($"Handled Exception: {Guid.NewGuid()}");
51+
}
52+
catch (Exception handledException) {
53+
// Use the ToExceptionless extension method to submit this handled exception to Exceptionless using the client instance from DI.
54+
handledException.ToExceptionless(client).Submit();
55+
}
56+
57+
try {
58+
throw new Exception($"Handled Exception (Default Client): {Guid.NewGuid()}");
59+
}
60+
catch (Exception handledException) {
61+
// Use the ToExceptionless extension method to submit this handled exception to Exceptionless using the default client instance (ExceptionlessClient.Default).
62+
// This works and is convenient, but its generally not recommended to use static singleton instances because it makes testing and
63+
// other things harder.
64+
handledException.ToExceptionless().Submit();
65+
}
66+
67+
// Unhandled exceptions will get reported since called UseExceptionless in the Startup.cs which registers a listener for unhandled exceptions.
68+
throw new Exception($"Unhandled Exception: {Guid.NewGuid()}");
69+
});
70+
});
71+
});
72+
});
73+
}
74+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"Exceptionless.SampleAspNetCore": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"launchUrl": "http://localhost:5000/ping",
7+
"environmentVariables": {
8+
"ASPNETCORE_ENVIRONMENT": "Development"
9+
}
10+
}
11+
}
12+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Microsoft.Extensions.Hosting;
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace Exceptionless.SampleHosting {
8+
internal class SampleService : IHostedService {
9+
private readonly ExceptionlessClient _exceptionlessClient;
10+
private readonly ILogger _logger;
11+
12+
public SampleService(ExceptionlessClient exceptionlessClient, ILogger<SampleService> logger) {
13+
_exceptionlessClient = exceptionlessClient;
14+
_logger = logger;
15+
}
16+
17+
public Task StartAsync(CancellationToken cancellationToken) {
18+
_logger.LogInformation("Starting sample service.");
19+
20+
// Submit a feature usage event directly using the client instance that is injected from the DI container.
21+
_exceptionlessClient.SubmitFeatureUsage("SampleService");
22+
23+
// This log message will get sent to Exceptionless since Exceptionless has be added to the logging system in Program.cs.
24+
_logger.LogWarning("Test warning message");
25+
26+
return Task.Run(() => {
27+
try {
28+
throw new Exception($"Handled Exception: {Guid.NewGuid()}");
29+
}
30+
catch (Exception handledException) {
31+
// Use the ToExceptionless extension method to submit this handled exception to Exceptionless using the client instance from DI.
32+
handledException.ToExceptionless(_exceptionlessClient).Submit();
33+
}
34+
35+
try {
36+
throw new Exception($"Handled Exception (Default Client): {Guid.NewGuid()}");
37+
}
38+
catch (Exception handledException) {
39+
// Use the ToExceptionless extension method to submit this handled exception to Exceptionless using the default client instance (ExceptionlessClient.Default).
40+
// This works and is convenient, but its generally not recommended to use static singleton instances because it makes testing and
41+
// other things harder.
42+
handledException.ToExceptionless().Submit();
43+
}
44+
}, cancellationToken);
45+
}
46+
47+
public Task StopAsync(CancellationToken cancellationToken) {
48+
_logger.LogInformation("Stopping sample service.");
49+
return Task.CompletedTask;
50+
}
51+
}
52+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"Exceptionless": {
3+
"ApiKey": "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
4+
"ServerUrl": "http://localhost:5000",
5+
"DefaultData": {
6+
"JSON_OBJECT": "{ \"Name\": \"Blake\" }",
7+
"Boolean": true,
8+
"Number": 1,
9+
"Array": "1,2,3"
10+
},
11+
"DefaultTags": [ "xplat" ],
12+
"Settings": {
13+
"FeatureXYZEnabled": false
14+
}
15+
},
16+
"Logging": {
17+
"LogLevel": {
18+
"Default": "Information",
19+
"Microsoft": "Warning",
20+
"Microsoft.Hosting.Lifetime": "Information"
21+
}
22+
},
23+
"AllowedHosts": "*"
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
5+
<LangVersion>latest</LangVersion>
6+
<AWSProjectType>Lambda</AWSProjectType>
7+
8+
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
9+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Amazon.Lambda.Core" Version="1.2.0" />
13+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\src\Exceptionless\Exceptionless.csproj" />
18+
</ItemGroup>
19+
</Project>

0 commit comments

Comments
 (0)