-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Open Telemetry Support (#2453)
OpenTelemetry Integration and ASP.NET Core sample Co-authored-by: Matt Johnson-Pint <matt.johnson-pint@sentry.io>
- Loading branch information
1 parent
af5aac5
commit 46490d7
Showing
55 changed files
with
1,878 additions
and
106 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
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
9 changes: 9 additions & 0 deletions
9
samples/Sentry.Samples.OpenTelemetry.AspNetCore/DiagnosticsConfig.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,9 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Sentry.Samples.OpenTelemetry.AspNetCore; | ||
|
||
public static class DiagnosticsConfig | ||
{ | ||
public const string ServiceName = "Sentry.Samples.OpenTelemetry.AspNetCore"; | ||
public static ActivitySource ActivitySource { get; } = new(ServiceName); | ||
} |
56 changes: 56 additions & 0 deletions
56
samples/Sentry.Samples.OpenTelemetry.AspNetCore/Program.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,56 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Diagnostics; | ||
using OpenTelemetry.Resources; | ||
using OpenTelemetry.Trace; | ||
using Sentry; | ||
using Sentry.OpenTelemetry; | ||
using Sentry.Samples.OpenTelemetry.AspNetCore; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// OpenTelemetry Configuration | ||
// See https://opentelemetry.io/docs/instrumentation/net/getting-started/ | ||
builder.Services.AddOpenTelemetry() | ||
.WithTracing(tracerProviderBuilder => | ||
tracerProviderBuilder | ||
.AddSource(DiagnosticsConfig.ActivitySource.Name) | ||
.ConfigureResource(resource => resource.AddService(DiagnosticsConfig.ServiceName)) | ||
.AddAspNetCoreInstrumentation() | ||
.AddHttpClientInstrumentation() | ||
.AddSentry() | ||
); | ||
|
||
builder.WebHost.UseSentry(options => | ||
{ | ||
options.TracesSampleRate = 1.0; | ||
options.UseOpenTelemetry(); | ||
options.Debug = builder.Environment.IsDevelopment(); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
var httpClient = new HttpClient(); | ||
app.MapGet("/hello", async context => | ||
{ | ||
// Make an HTTP request to the /echo endpoint, to demonstrate that Baggage and TraceHeaders get propagated | ||
// correctly... in a real world situation, we might have received a request to this endpoint from an upstream | ||
// service that is instrumented with Sentry (passing in a SentryTraceHeader), and we might make an downstream | ||
// request to another service that's also instrumented with Sentry. Having a single TraceId that gets propagated | ||
// across all services by Sentry and OpenTelemetry ensures all of these events show as part of the same trace in | ||
// the performance dashboard in Sentry. | ||
var request = context.Request; | ||
if (request.Query.TryGetValue("topping", out var topping)) | ||
{ | ||
Activity.Current?.AddTag("topping", topping); | ||
} | ||
|
||
var url = $"{request.Scheme}://{request.Host}{request.PathBase}/echo"; | ||
var result = await httpClient.GetStringAsync(url); | ||
await context.Response.WriteAsync(result); | ||
}); | ||
|
||
app.MapGet("/echo", () => "Hi!"); | ||
|
||
app.MapGet("/throw", _ => throw new Exception("test")); | ||
|
||
app.Run(); |
14 changes: 14 additions & 0 deletions
14
samples/Sentry.Samples.OpenTelemetry.AspNetCore/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,14 @@ | ||
{ | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "hello", | ||
"applicationUrl": "http://localhost:5092", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...es/Sentry.Samples.OpenTelemetry.AspNetCore/Sentry.Samples.OpenTelemetry.AspNetCore.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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.0" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.0-beta.1" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.0-beta.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sentry.AspNetCore\Sentry.AspNetCore.csproj" /> | ||
<ProjectReference Include="..\..\src\Sentry.OpenTelemetry\Sentry.OpenTelemetry.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
samples/Sentry.Samples.OpenTelemetry.AspNetCore/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" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/Sentry.Samples.OpenTelemetry.AspNetCore/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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
Oops, something went wrong.