Skip to content

Commit

Permalink
#61 : Add Sentry compatibility with Dapr 1.12+, and SentrySample project
Browse files Browse the repository at this point in the history
  • Loading branch information
badgeratu committed Apr 10, 2024
1 parent f7d0543 commit 6adabee
Show file tree
Hide file tree
Showing 26 changed files with 307 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
dotnet-version: ['net35', 'net48', 'net50']
dotnet-version: ['net35', 'net48', 'net80']
include:
- dotnet-version: 'net35'
display-name: '.NET Framework 3.5'
Expand All @@ -43,8 +43,8 @@ jobs:
framework: 'net48'
logger: '--logger="GitHubActions;report-warnings=false" --logger="trx"'
- dotnet-version: 'net50'
display-name: '.NET 5.0'
framework: 'net5.0'
display-name: '.NET 8.0'
framework: 'net8.0'
logger: '--logger="GitHubActions;report-warnings=false" --logger="trx"'
steps:
- uses: actions/checkout@v2
Expand Down
26 changes: 22 additions & 4 deletions all.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.6.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.10.34707.107
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A985DBAA-87F6-4860-A5D3-96376165BE17}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -80,13 +80,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ControllerSample", "Control
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControllerSample", "samples\AspNetCore\ControllerSample\ControllerSample\ControllerSample.csproj", "{FE082318-2993-42A3-B2DB-28EDA77F7136}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppConfigurationSample", "samples\AspNetCore\AppConfigurationSample\AppConfigurationSample\AppConfigurationSample.csproj", "{C6911A37-51F3-4E29-8E67-39B460EE7ABA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppConfigurationSample", "samples\AspNetCore\AppConfigurationSample\AppConfigurationSample\AppConfigurationSample.csproj", "{C6911A37-51F3-4E29-8E67-39B460EE7ABA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AppConfigurationSample", "AppConfigurationSample", "{3AD6FEBE-37E9-436E-BE86-29668A9DDB3E}"
ProjectSection(SolutionItems) = preProject
samples\AspNetCore\AppConfigurationSample\README.md = samples\AspNetCore\AppConfigurationSample\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SentrySample", "SentrySample", "{7F6A5D8C-9780-4824-8284-CC3149683C70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SentrySample", "samples\AspNetCore\SentrySample\SentrySample\SentrySample.csproj", "{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -277,6 +281,18 @@ Global
{C6911A37-51F3-4E29-8E67-39B460EE7ABA}.Release|x64.Build.0 = Release|Any CPU
{C6911A37-51F3-4E29-8E67-39B460EE7ABA}.Release|x86.ActiveCfg = Release|Any CPU
{C6911A37-51F3-4E29-8E67-39B460EE7ABA}.Release|x86.Build.0 = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|x64.ActiveCfg = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|x64.Build.0 = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|x86.ActiveCfg = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Debug|x86.Build.0 = Debug|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|Any CPU.Build.0 = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|x64.ActiveCfg = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|x64.Build.0 = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|x86.ActiveCfg = Release|Any CPU
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -304,8 +320,10 @@ Global
{A3C52771-3B41-43F6-A4DD-7B3F7BAA598D} = {D625B898-1677-4DCA-B067-C7BFB07F1314}
{C5B72F44-C52D-471D-BE29-DB1C34699220} = {DA3D8137-F2DD-465D-81AA-3CA5C75087D2}
{FE082318-2993-42A3-B2DB-28EDA77F7136} = {C5B72F44-C52D-471D-BE29-DB1C34699220}
{3AD6FEBE-37E9-436E-BE86-29668A9DDB3E} = {DA3D8137-F2DD-465D-81AA-3CA5C75087D2}
{C6911A37-51F3-4E29-8E67-39B460EE7ABA} = {3AD6FEBE-37E9-436E-BE86-29668A9DDB3E}
{3AD6FEBE-37E9-436E-BE86-29668A9DDB3E} = {DA3D8137-F2DD-465D-81AA-3CA5C75087D2}
{7F6A5D8C-9780-4824-8284-CC3149683C70} = {DA3D8137-F2DD-465D-81AA-3CA5C75087D2}
{9F4DA8E9-F253-4312-A0BB-E2873A21C41A} = {7F6A5D8C-9780-4824-8284-CC3149683C70}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E906E97D-7D56-4E02-A13F-1C48AEB47A88}
Expand Down
8 changes: 4 additions & 4 deletions properties/dapr_sidekick_csharp.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="dapr_sidekick_common.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
Expand Down Expand Up @@ -50,15 +50,15 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="3.0.0">
<PackageReference Include="Roslynator.Analyzers" Version="4.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>

<!-- Configure properties for MinVer -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
Expand All @@ -20,4 +20,4 @@ public class Account
/// </summary>
public decimal Balance { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
Expand All @@ -24,4 +24,4 @@ public class Transaction
[Range(0, double.MaxValue)]
public decimal Amount { get; set; }
}
}
}
24 changes: 24 additions & 0 deletions samples/AspNetCore/SentrySample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ASP.NET Core Controller example

This sample shows using Dapr with ASP.NET Core controllers. This application is a simple and not-so-secure banking application. The application uses the Dapr state-store for its data storage. The sample is a copy of the [Dapr .NET SDK Controller example](https://github.com/dapr/dotnet-sdk/tree/master/examples/AspNetCore/ControllerSample), but modified to include Dapr Sidekick integration for launching a Dapr sidecar.

> See the [original source](https://github.com/dapr/dotnet-sdk/tree/master/examples/AspNetCore/ControllerSample) for more information on how to use the sample.
## How Dapr Sidekick was added

The main change to the template code to add Dapr support can be found in the `ConfigureServices` method in `Startup.cs`:

```csharp
public void ConfigureServices(IServiceCollection services)
{
...
// Add Dapr Sidekick
services.AddDaprSidekick(Configuration);
}
```

## Running the sample

To run the sample simply set `ControllerSample` as the startup project and run it in Visual Studio, it will launch the Dapr sidecar and connect to it.

For all further instructions, including prerequisites and testing, please refer to the [original source](https://github.com/dapr/dotnet-sdk/tree/master/examples/AspNetCore/ControllerSample).
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;

namespace SentrySample.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
67 changes: 67 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Man.Dapr.Sidekick;
using Serilog;

// Add Serilog for enhanced console logging.
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Add Dapr Sidekick with Sentry
builder.Services.AddDaprSidekick(builder.Configuration)
.AddSentry();

// Inject Sentry certificates into the Dapr sidecar to verify mTLS operation
builder.Services.PostConfigure<DaprOptions>(options =>
{
var certsFolder = "sentry/certs/";
// Assign security defaults (trust chain, certificates and keys) from embedded resources.
// This needs to be replaced with proper certificate distribution in the future.
options.TrustAnchorsCertificate ??= File.ReadAllText(certsFolder + DaprConstants.TrustAnchorsCertificateFilename);
options.IssuerCertificate ??= File.ReadAllText(certsFolder + DaprConstants.IssuerCertificateFilename);
options.IssuerKey ??= File.ReadAllText(certsFolder + DaprConstants.IssuerKeyFilename);
});

builder.Host.UseSerilog();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.MapGet("/status", (IDaprSidecarHost sidecarHost, IDaprSentryHost sentryHost) => Results.Ok(new
{
sidecar = new
{
process = sidecarHost.GetProcessInfo(), // Information about the sidecar process such as if it is running
options = sidecarHost.GetProcessOptions() // The sidecar options if running, including ports and locations
},
sentry = new
{
process = sentryHost.GetProcessInfo(), // Information about the sentry process such as if it is running
options = sentryHost.GetProcessOptions() // The sentry options if running, including ports and locations
},
}));

// For Dapr
app.MapHealthChecks("/health");

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"SentrySample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "status",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000"
}
}
}
27 changes: 27 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/SentrySample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Man.Dapr.Sidekick.AspNetCore\Man.Dapr.Sidekick.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="dapr\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="sentry\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SentrySample
{
public class WeatherForecast
{
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
20 changes: 20 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"DaprSidekick": {
"Sidecar": {
"mTLS": true,
"RuntimeDirectory": "dapr",
"SentryAddress": "localhost:50001"
},
"Sentry": {
"RuntimeDirectory": "sentry",
"TrustDomain": "cluster.local" // Certificates in /certs folder generated for this domain
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
8 changes: 8 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/dapr/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprsystem
namespace: default
spec:
mtls:
enabled: true
10 changes: 10 additions & 0 deletions samples/AspNetCore/SentrySample/SentrySample/sentry/certs/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----BEGIN CERTIFICATE-----
MIIBcjCCARegAwIBAgIRAPNjhmnvu5t1cT4RleqbpIgwCgYIKoZIzj0EAwIwGDEW
MBQGA1UEChMNY2x1c3Rlci5sb2NhbDAeFw0yNDA0MDkxNjMxNDVaFw0yNTA0MDkx
NjQ2NDVaMBgxFjAUBgNVBAoTDWNsdXN0ZXIubG9jYWwwWTATBgcqhkjOPQIBBggq
hkjOPQMBBwNCAAQnuU4Xu2OicVtxHSvpByI4Q3v3Ld4UKpMKvR3+iPs0goJRmkOd
+rgKfUJRu99Al89iF1Jc0xp2G3hqsTJzRNGmo0IwQDAOBgNVHQ8BAf8EBAMCAqQw
DwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUClFVts/NEUrgwtxGRVHYdsr5MkAw
CgYIKoZIzj0EAwIDSQAwRgIhAL1kZ/CgvaVstjh6Wl7Xpq9S5cqL/uDBP8qA535J
gEEhAiEAiPkgINWSCjvunsyCS2MzGRqzXS5F9hSMsl8JJvAAk3A=
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBqzCCAVGgAwIBAgIRAIwB5uvnwvPxdYpnXs68vxAwCgYIKoZIzj0EAwIwGDEW
MBQGA1UEChMNY2x1c3Rlci5sb2NhbDAeFw0yNDA0MDkxNjMxNDVaFw0yNTA0MDkx
NjQ2NDVaMDgxNjA0BgNVBAoTLXNwaWZmZTovL2NsdXN0ZXIubG9jYWwvbnMvZGVm
YXVsdC9kYXByLXNlbnRyeTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABIlCFe0s
g2hyCoT+jtFfIUKPLcJmT6kI1cOWhd9lEdKxRQQK0WAIpgLoBU1dV/bQEh2vTI7h
+UP8JYTib6RLy5mjXDBaMA4GA1UdDwEB/wQEAwIBpjAPBgNVHRMBAf8EBTADAQH/
MB0GA1UdDgQWBBRDRvGl7xL2km4sd7pln3ayKZEv3DAYBgNVHREEETAPgg1jbHVz
dGVyLmxvY2FsMAoGCCqGSM49BAMCA0gAMEUCIGMbBjjNPM2lgSojy4Zdr3EZO4qZ
7QUC39qit7zrHEaUAiEA2GHEgHHu7gJdDoTz9Up+jSjIfDIRNgOqUpHsldEwN0c=
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgwVI9SsqI5owZm19/
NI2uN4yp9WkqE8W8/zhM4AZOvwahRANCAASJQhXtLINocgqE/o7RXyFCjy3CZk+p
CNXDloXfZRHSsUUECtFgCKYC6AVNXVf20BIdr0yO4flD/CWE4m+kS8uZ
-----END PRIVATE KEY-----
Loading

0 comments on commit 6adabee

Please sign in to comment.