-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/ignore-diagnosticsource-with-no-transactions' of ht…
…tps://github.com/getsentry/sentry-dotnet into fix/ignore-diagnosticsource-with-no-transactions
- Loading branch information
Showing
59 changed files
with
10,771 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,22 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Sentry; | ||
|
||
internal static class Program | ||
{ | ||
public static Task Main() | ||
=> new HostBuilder() | ||
.ConfigureHostConfiguration(c => | ||
{ | ||
c.SetBasePath(Directory.GetCurrentDirectory()); | ||
c.AddJsonFile("appsettings.json", optional: false); | ||
}) | ||
.ConfigureServices((_, s) => { s.AddHostedService<SampleHostedService>(); }) | ||
.ConfigureLogging((c, l) => | ||
{ | ||
l.AddConfiguration(c.Configuration); | ||
l.AddConsole(); | ||
l.AddSentry(); | ||
}) | ||
.UseConsoleLifetime() | ||
.Build() | ||
.RunAsync(); | ||
|
||
internal class SampleHostedService : IHostedService | ||
await Host.CreateDefaultBuilder() | ||
.ConfigureHostConfiguration(c => | ||
{ | ||
private readonly IHub _hub; | ||
private readonly ILogger _logger; | ||
|
||
public SampleHostedService(IHub hub, ILogger<SampleHostedService> logger) | ||
{ | ||
_hub = hub; | ||
_logger = logger; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
// Logging integration by default keeps informational logs as Breadcrumb | ||
_logger.LogInformation("Starting sample hosted service. This goes as a breadcrumb"); | ||
// You can also add breadcrumb directly through Sentry.Hub: | ||
_hub.AddBreadcrumb("Breadcrumb added directly to Sentry Hub") | ||
; | ||
// Hub allows total control of the scope | ||
_hub.ConfigureScope(s => s.SetTag("Worker", nameof(SampleHostedService))); | ||
|
||
// By default Error and Critical log messages are sent to sentry as events | ||
_logger.LogError("An event sent to sentry."); | ||
|
||
return Task.Run(() => | ||
{ | ||
try | ||
{ | ||
var zero = 0; | ||
_ = 10 / zero; // Throws DivideByZeroException | ||
} | ||
catch (Exception e) | ||
{ | ||
// Direct control of capturing errors with Sentry | ||
_hub.CaptureException(e); | ||
} | ||
}, cancellationToken); | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("Stopping sample hosted service."); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
c.SetBasePath(Directory.GetCurrentDirectory()); | ||
c.AddJsonFile("appsettings.json", optional: false); | ||
}) | ||
.ConfigureServices((_, s) => s.AddHostedService<SampleHostedService>()) | ||
.ConfigureLogging((c, l) => | ||
{ | ||
l.AddConfiguration(c.Configuration); | ||
l.AddConsole(); | ||
l.AddSentry(); | ||
}) | ||
.UseConsoleLifetime() | ||
.Build() | ||
.RunAsync(); |
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,52 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Sentry; | ||
|
||
internal class SampleHostedService : IHostedService | ||
{ | ||
private readonly IHub _hub; | ||
private readonly ILogger _logger; | ||
|
||
public SampleHostedService(IHub hub, ILogger<SampleHostedService> logger) | ||
{ | ||
_hub = hub; | ||
_logger = logger; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
// Logging integration by default keeps informational logs as Breadcrumb | ||
_logger.LogInformation("Starting sample hosted service. This goes as a breadcrumb"); | ||
// You can also add breadcrumb directly through Sentry.Hub: | ||
_hub.AddBreadcrumb("Breadcrumb added directly to Sentry Hub") | ||
; | ||
// Hub allows total control of the scope | ||
_hub.ConfigureScope(s => s.SetTag("Worker", nameof(SampleHostedService))); | ||
|
||
// By default Error and Critical log messages are sent to sentry as events | ||
_logger.LogError("An event sent to sentry."); | ||
|
||
return Task.Run(() => | ||
{ | ||
try | ||
{ | ||
var zero = 0; | ||
_ = 10 / zero; // Throws DivideByZeroException | ||
} | ||
catch (Exception e) | ||
{ | ||
// Direct control of capturing errors with Sentry | ||
_hub.CaptureException(e); | ||
} | ||
}, cancellationToken); | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("Stopping sample hosted service."); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
test/Sentry.AspNet.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt
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,13 @@ | ||
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName=".NET Framework 4.6.1")] | ||
namespace Sentry.AspNet | ||
{ | ||
public static class HttpContextExtensions | ||
{ | ||
public static void FinishSentryTransaction(this System.Web.HttpContext httpContext) { } | ||
public static Sentry.ITransaction StartSentryTransaction(this System.Web.HttpContext httpContext) { } | ||
} | ||
public static class SentryAspNetOptionsExtensions | ||
{ | ||
public static void AddAspNet(this Sentry.SentryOptions options, Sentry.Extensibility.RequestSize maxRequestBodySize = 0) { } | ||
} | ||
} |
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,17 @@ | ||
using System.Threading.Tasks; | ||
using Sentry.Tests; | ||
using VerifyXunit; | ||
using Xunit; | ||
|
||
namespace Sentry.AspNet.Tests | ||
{ | ||
[UsesVerify] | ||
public class ApiApprovalTests | ||
{ | ||
[Fact] | ||
public Task Run() | ||
{ | ||
return typeof(SentryAspNetOptionsExtensions).Assembly.CheckApproval(); | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
test/Sentry.AspNetCore.Grpc.Tests/ApiApprovalTests.Run.DotNet3_1.verified.txt
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,51 @@ | ||
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v3.0", FrameworkDisplayName="")] | ||
namespace Sentry.AspNetCore.Grpc | ||
{ | ||
public class DefaultProtobufRequestPayloadExtractor : Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor | ||
{ | ||
public DefaultProtobufRequestPayloadExtractor() { } | ||
public Google.Protobuf.IMessage ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage { } | ||
} | ||
public interface IProtobufRequestPayloadExtractor | ||
{ | ||
Google.Protobuf.IMessage? ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage; | ||
} | ||
public interface IProtobufRequest<TRequest> | ||
{ | ||
long? ContentLength { get; } | ||
TRequest Request { get; } | ||
} | ||
public class ProtobufRequestExtractionDispatcher : Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor | ||
{ | ||
public ProtobufRequestExtractionDispatcher(System.Collections.Generic.IEnumerable<Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { } | ||
public Google.Protobuf.IMessage? ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage { } | ||
} | ||
public static class ScopeExtensions | ||
{ | ||
public static void Populate<TRequest>(this Sentry.Scope scope, Grpc.Core.ServerCallContext context, TRequest? request, Sentry.AspNetCore.SentryAspNetCoreOptions options) | ||
where TRequest : class { } | ||
} | ||
public static class SentryBuilderExtensions | ||
{ | ||
public static Sentry.AspNetCore.ISentryBuilder AddGrpc(this Sentry.AspNetCore.ISentryBuilder builder) { } | ||
} | ||
public class SentryGrpcInterceptor : Grpc.Core.Interceptors.Interceptor | ||
{ | ||
public SentryGrpcInterceptor(System.Func<Sentry.IHub> hubAccessor, Microsoft.Extensions.Options.IOptions<Sentry.AspNetCore.SentryAspNetCoreOptions> options) { } | ||
public override System.Threading.Tasks.Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.ServerCallContext context, Grpc.Core.ClientStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task DuplexStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.DuplexStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.ServerStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.ServerCallContext context, Grpc.Core.UnaryServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
test/Sentry.AspNetCore.Grpc.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt
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,51 @@ | ||
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v5.0", FrameworkDisplayName="")] | ||
namespace Sentry.AspNetCore.Grpc | ||
{ | ||
public class DefaultProtobufRequestPayloadExtractor : Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor | ||
{ | ||
public DefaultProtobufRequestPayloadExtractor() { } | ||
public Google.Protobuf.IMessage ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage { } | ||
} | ||
public interface IProtobufRequestPayloadExtractor | ||
{ | ||
Google.Protobuf.IMessage? ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage; | ||
} | ||
public interface IProtobufRequest<TRequest> | ||
{ | ||
long? ContentLength { get; } | ||
TRequest Request { get; } | ||
} | ||
public class ProtobufRequestExtractionDispatcher : Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor | ||
{ | ||
public ProtobufRequestExtractionDispatcher(System.Collections.Generic.IEnumerable<Sentry.AspNetCore.Grpc.IProtobufRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { } | ||
public Google.Protobuf.IMessage? ExtractPayload<TRequest>(Sentry.AspNetCore.Grpc.IProtobufRequest<TRequest> request) | ||
where TRequest : class, Google.Protobuf.IMessage { } | ||
} | ||
public static class ScopeExtensions | ||
{ | ||
public static void Populate<TRequest>(this Sentry.Scope scope, Grpc.Core.ServerCallContext context, TRequest? request, Sentry.AspNetCore.SentryAspNetCoreOptions options) | ||
where TRequest : class { } | ||
} | ||
public static class SentryBuilderExtensions | ||
{ | ||
public static Sentry.AspNetCore.ISentryBuilder AddGrpc(this Sentry.AspNetCore.ISentryBuilder builder) { } | ||
} | ||
public class SentryGrpcInterceptor : Grpc.Core.Interceptors.Interceptor | ||
{ | ||
public SentryGrpcInterceptor(System.Func<Sentry.IHub> hubAccessor, Microsoft.Extensions.Options.IOptions<Sentry.AspNetCore.SentryAspNetCoreOptions> options) { } | ||
public override System.Threading.Tasks.Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.ServerCallContext context, Grpc.Core.ClientStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task DuplexStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.DuplexStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.ServerStreamingServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
public override System.Threading.Tasks.Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.ServerCallContext context, Grpc.Core.UnaryServerMethod<TRequest, TResponse> continuation) | ||
where TRequest : class | ||
where TResponse : class { } | ||
} | ||
} |
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,17 @@ | ||
using System.Threading.Tasks; | ||
using Sentry.Tests; | ||
using VerifyXunit; | ||
using Xunit; | ||
|
||
namespace Sentry.AspNetCore.Grpc.Tests | ||
{ | ||
[UsesVerify] | ||
public class ApiApprovalTests | ||
{ | ||
[Fact] | ||
public Task Run() | ||
{ | ||
return typeof(SentryGrpcInterceptor).Assembly.CheckApproval(); | ||
} | ||
} | ||
} |
Oops, something went wrong.