Skip to content

eduairet/sentry-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentry Example

Simple example project demonstrating Sentry integration for .NET APIs.

Overview

Sentry is an error tracking and performance monitoring tool that helps developers identify and fix issues in their applications. This example project showcases how to integrate Sentry into a .NET API application.

Prerequisites

  • .NET SDK installed (version 6.0 or later)
  • An active Sentry account (you can sign up for free at sentry.io)

Setup

  • Install the Sentry .NET SDK

    • Via .NET CLI:
      dotnet add package Sentry.AspNetCore -v 6.0.0
    • Via Package Manager:
      dotnet add package Sentry.AspNetCore -v 6.0.0
      
  • Configure Sentry in your application

    • In Program.cs add the following configuration:

      builder.WebHost.UseSentry(options =>
      {
          // A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
          // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
          options.Dsn = builder.Configuration["SENTRY_DSN"];
      
          // Enable Sentry performance monitoring
          options.TracesSampleRate = 1.0;
      
      #if DEBUG
          // Log debug information about the Sentry SDK
          options.Debug = true;
      #endif
      
          // Configure the minimum Log Level of Breadcrumbs and Events
          options.MinimumBreadcrumbLevel = LogLevel.Information;
          options.MinimumEventLevel = LogLevel.Error;
      
          // This option enables Logs sent to Sentry
          // Configure the minimum Log Level of Structured-Logs via e.g. "appsettings.json" and "appsettings.{HostEnvironment}.json"
          options.EnableLogs = true;
      });
  • Verify the integration by capturing a test error in your application.

    SentrySdk.CaptureMessage("Sentry is successfully integrated!");
  • The above message should appear in your Sentry dashboard. Sentry Dashboard

Containerization and Deployment

  • In the root of the project (Sentry), run the following commands to build the Docker image for the API and push it to Docker Hub:
    docker build --no-cache -f SentryApi/Dockerfile -t ${DOCKER_USERNAME}/sentry-api:latest .
    docker push ${DOCKER_USERNAME}/sentry-api:latest

References

About

Sentry example.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors