Skip to content

Commit

Permalink
feat(dotnet): Open Telemetry support (#7430)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Jul 14, 2023
1 parent c7f0a09 commit 9ae8bb3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/docs/product/performance/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ If you don't already have performance monitoring enabled, use the links for supp
- <PlatformLinkWithLogo platform="dotnet" url="/platforms/dotnet/performance" />

- [ASP.NET Core](/platforms/dotnet/guides/aspnetcore/performance)
- [OpenTelemetry](/platforms/dotnet/performance/instrumentation/opentelemetry/)

- <PlatformLinkWithLogo platform="go" url="/platforms/go/performance" />

Expand Down
1 change: 1 addition & 0 deletions src/includes/feature-stage-beta-opentelemetry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Currently, OpenTelemetry is supported on the following SDKs:
- [Python](/platforms/python/performance/instrumentation/opentelemetry/)
- [Ruby](/platforms/ruby/performance/instrumentation/opentelemetry/)
- [Java](/platforms/java/performance/instrumentation/opentelemetry/)
- [.NET](/platforms/dotnet/performance/instrumentation/opentelemetry/)
- [Go](/platforms/go/performance/instrumentation/opentelemetry/)

</Note>
24 changes: 24 additions & 0 deletions src/platform-includes/performance/opentelemetry-install/dotnet.mdx
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 src/platform-includes/performance/opentelemetry-setup/dotnet.mdx
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();
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ supported:
- ruby
- go
- java
- dotnet
notSupported:
- javascript
- dart
- flutter
- react-native
- android
- apple
- dotnet
- javascript.cordova
- javascript.electron
- unity
Expand Down

1 comment on commit 9ae8bb3

@vercel
Copy link

@vercel vercel bot commented on 9ae8bb3 Jul 14, 2023

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

Please sign in to comment.