-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dotnet): Open Telemetry support (#7430)
- Loading branch information
1 parent
c7f0a09
commit 9ae8bb3
Showing
5 changed files
with
116 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
src/platform-includes/performance/opentelemetry-install/dotnet.mdx
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 @@ | ||
<Note> | ||
|
||
The `Sentry.OpenTelemetry` package requires `OpenTelemetry` package `1.5.0` or higher. | ||
|
||
</Note> | ||
|
||
To install, add the `Sentry` and `Sentry.OpenTelemetry` **NuGet** packages to your project: | ||
|
||
```shell {tabTitle:.NET Core CLI} | ||
dotnet add package Sentry -v {{@inject packages.version('sentry.dotnet') }} | ||
dotnet add package Sentry.OpenTelemetry -v {{@inject packages.version('sentry.dotnet') }} | ||
``` | ||
|
||
```powershell {tabTitle:Package Manager} | ||
Install-Package Sentry -Version {{@inject packages.version('sentry.dotnet') }} | ||
Install-Package Sentry.OpenTelemetry -Version {{@inject packages.version('sentry.dotnet') }} | ||
``` | ||
|
||
```shell {tabTitle:Paket CLI} | ||
paket add Sentry --version {{@inject packages.version('sentry.dotnet') }} | ||
paket add Sentry.OpenTelemetry --version {{@inject packages.version('sentry.dotnet') }} | ||
``` | ||
|
||
If you're building an ASP.NET or ASP.NET Core application, add their respective packages (`Sentry.AspNet` or `Sentry.AspNetCore`) as well. |
89 changes: 89 additions & 0 deletions
89
src/platform-includes/performance/opentelemetry-setup/dotnet.mdx
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,89 @@ | ||
To learn how to start tracing based on your application kind, read the instructions below. | ||
|
||
### Console Applications | ||
|
||
To start tracing in a console application, you'll need to add Sentry to the tracer provider. This will make it possible for OpenTelemetry spans to be captured by Sentry. | ||
|
||
```csharp | ||
using var tracerProvider = Sdk.CreateTracerProviderBuilder() | ||
.AddSource(serviceName) | ||
.ConfigureResource(resource => | ||
resource.AddService( | ||
serviceName: serviceName, | ||
serviceVersion: serviceVersion)) | ||
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry | ||
.Build(); | ||
``` | ||
|
||
Next, initialize Sentry and opt into the use of OpenTelemetry. This allows the SDK to send OpenTelemetry spans to Sentry. | ||
|
||
```csharp | ||
SentrySdk.Init(options => | ||
{ | ||
// options.Dsn = "... Your DSN ..."; | ||
options.TracesSampleRate = 1.0; | ||
options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information | ||
}); | ||
``` | ||
|
||
### ASP.NET Core Applications | ||
|
||
To start tracing in an ASP.NET Core app, add OpenTelemetry with tracing and add Sentry to the tracer provider. | ||
|
||
```csharp | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddOpenTelemetry() | ||
.WithTracing(tracerProviderBuilder => | ||
tracerProviderBuilder | ||
.AddSource(Telemetry.ActivitySource.Name) | ||
.ConfigureResource(resource => resource.AddService(Telemetry.ServiceName)) | ||
.AddAspNetCoreInstrumentation() | ||
.AddHttpClientInstrumentation() | ||
.AddSentry() // <-- Configure OpenTelemetry to send trace information to Sentry | ||
); | ||
``` | ||
|
||
Next, initialize Sentry and opt into the use of OpenTelemetry. This allows the SDK to send OpenTelemetry spans to Sentry. | ||
|
||
```csharp | ||
builder.WebHost.UseSentry(options => | ||
{ | ||
options.Dsn = "...Your DSN..."; | ||
options.TracesSampleRate = 1.0; | ||
options.UseOpenTelemetry(); // <-- Configure Sentry to use OpenTelemetry trace information | ||
}); | ||
``` | ||
|
||
### ASP.NET Applications | ||
|
||
To start tracing in an ASP.NET application, you'll need to create a tracer provider. | ||
|
||
```csharp | ||
var builder = Sdk.CreateTracerProviderBuilder() | ||
.AddAspNetInstrumentation() | ||
.AddSource(Telemetry.ServiceName) | ||
.SetResourceBuilder( | ||
ResourceBuilder.CreateDefault() | ||
.AddService(serviceName: Telemetry.ServiceName, serviceVersion: "1.0.0") | ||
); | ||
|
||
``` | ||
|
||
Next, initialize Sentry and opt into the use of OpenTelemetry. Provide the SDK with the builder for OpenTelemetry's tracer provider to allow sending spans to Sentry. | ||
|
||
```csharp | ||
_sentry = SentrySdk.Init(o => | ||
{ | ||
//o.Dsn = "...Your DSN..."; | ||
o.TracesSampleRate = 1.0; | ||
o.AddAspNet(RequestSize.Always); | ||
o.UseOpenTelemetry(builder); | ||
}); | ||
``` | ||
|
||
Lastly, build the tracer provider. | ||
|
||
```csharp | ||
_tracerProvider = builder.Build(); | ||
``` |
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
9ae8bb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sentry-docs – ./
sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev
docs.sentry.io