Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dotnet): Open Telemetry support #7430

Merged
merged 14 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the `OpenTelemetry` package `1.5.0` or higher.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

</Note>

Add the `Sentry` and `Sentry.OpenTelemetry` **NuGet** packages to your project:
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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 you'll want to add their respective packages as well, i.e. `Sentry.AspNet` or `Sentry.AspNetCore`.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved
87 changes: 87 additions & 0 deletions src/platform-includes/performance/opentelemetry-setup/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
### Console applications
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

To start tracing in a console application, you need to create a tracer provider. Add Sentry to the tracer provider to allow OpenTelemetry spans to be captured by Sentry.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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 sent OpenTelemetry spans to be sent to Sentry.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

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 sent OpenTelemetry spans to be sent to Sentry.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

To start tracing in an ASP.NET application, you need to create a tracer provider.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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. You'll need to provide the SDK with the builder for OpenTelemetry's tracer provider to allow sending spans to Sentry.
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

```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
Loading