-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#61 : Add Sentry compatibility with Dapr 1.12+, and SentrySample project
- Loading branch information
Showing
26 changed files
with
307 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
33 changes: 33 additions & 0 deletions
33
samples/AspNetCore/SentrySample/SentrySample/Controllers/WeatherForecastController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
13 changes: 13 additions & 0 deletions
13
samples/AspNetCore/SentrySample/SentrySample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
samples/AspNetCore/SentrySample/SentrySample/SentrySample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
samples/AspNetCore/SentrySample/SentrySample/WeatherForecast.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/AspNetCore/SentrySample/SentrySample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
samples/AspNetCore/SentrySample/SentrySample/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
samples/AspNetCore/SentrySample/SentrySample/dapr/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
samples/AspNetCore/SentrySample/SentrySample/sentry/certs/ca.crt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
11 changes: 11 additions & 0 deletions
11
samples/AspNetCore/SentrySample/SentrySample/sentry/certs/issuer.crt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
5 changes: 5 additions & 0 deletions
5
samples/AspNetCore/SentrySample/SentrySample/sentry/certs/issuer.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
Oops, something went wrong.