diff --git a/CHANGELOG.md b/CHANGELOG.md index d3c27171f6..1bceb59b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Expose `ITransport` and `SentryOptions.Transport` public, to support using custom transports ([#1602](https://github.com/getsentry/sentry-dotnet/pull/1602)) + ### Fixes - Workaround `System.Text.Json` issue with Unity IL2CPP. ([#1583](https://github.com/getsentry/sentry-dotnet/pull/1583)) diff --git a/src/Sentry/Extensibility/ITransport.cs b/src/Sentry/Extensibility/ITransport.cs index 8725b9d437..7a2e6d6450 100644 --- a/src/Sentry/Extensibility/ITransport.cs +++ b/src/Sentry/Extensibility/ITransport.cs @@ -7,7 +7,7 @@ namespace Sentry.Extensibility /// /// An abstraction to the transport of the event. /// - internal interface ITransport + public interface ITransport { /// /// Sends the to Sentry asynchronously. @@ -16,9 +16,4 @@ internal interface ITransport /// The cancellation token. Task SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken = default); } - - internal interface IFlushableTransport : ITransport - { - Task FlushAsync(CancellationToken cancellationToken = default); - } } diff --git a/src/Sentry/Internal/Http/CachingTransport.cs b/src/Sentry/Internal/Http/CachingTransport.cs index d651389291..bf9d4a6b9e 100644 --- a/src/Sentry/Internal/Http/CachingTransport.cs +++ b/src/Sentry/Internal/Http/CachingTransport.cs @@ -11,7 +11,7 @@ namespace Sentry.Internal.Http { - internal class CachingTransport : IFlushableTransport, IAsyncDisposable, IDisposable + internal class CachingTransport : ITransport, IAsyncDisposable, IDisposable { private const string EnvelopeFileExt = "envelope"; diff --git a/src/Sentry/Internal/SdkComposer.cs b/src/Sentry/Internal/SdkComposer.cs index 2d21e42a14..1925f3db13 100644 --- a/src/Sentry/Internal/SdkComposer.cs +++ b/src/Sentry/Internal/SdkComposer.cs @@ -52,7 +52,7 @@ private HttpTransport CreateHttpTransport() return new HttpTransport(_options, httpClient); } - internal void BlockCacheFlush(IFlushableTransport transport) + internal void BlockCacheFlush(CachingTransport transport) { // If configured, flush existing cache if (_options.InitCacheFlushTimeout > TimeSpan.Zero) diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs index 8ffd8b2049..fce4c9b005 100644 --- a/src/Sentry/SentryOptions.cs +++ b/src/Sentry/SentryOptions.cs @@ -8,6 +8,7 @@ using Sentry.Http; using Sentry.Integrations; using Sentry.Internal; +using Sentry.Internal.Http; using Sentry.Internal.ScopeStack; using static Sentry.Constants; using static Sentry.Internal.Constants; @@ -49,9 +50,13 @@ public bool IsGlobalModeEnabled /// /// This holds a reference to the current transport, when one is active. - /// If set manually (for tests), it will be used instead of the default transport. + /// If set manually before initialization, the provided transport will be used instead of the default transport. /// - internal ITransport? Transport { get; set; } + /// + /// If is set, any transport set here will be wrapped in a + /// and used as its inner transport. + /// + public ITransport? Transport { get; set; } internal ISentryStackTraceFactory? SentryStackTraceFactory { get; set; } diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 93b767227c..c693bdc58d 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index 76bfd2921e..76f8a81848 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 1bb34f5450..d314d070a8 100644 --- a/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt index abe61dffc8..011d1d62f5 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1037,6 +1038,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt index 5136f07aa9..356fe74e29 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1037,6 +1038,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt index 93b767227c..c693bdc58d 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt index 5bb1bc77f1..b2119e26b2 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet4_6.verified.txt @@ -497,6 +497,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1037,6 +1038,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt index 76bfd2921e..76f8a81848 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet5_0.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { } diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt index 1bb34f5450..d314d070a8 100644 --- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt +++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt @@ -498,6 +498,7 @@ namespace Sentry public Sentry.StackTraceMode StackTraceMode { get; set; } public double TracesSampleRate { get; set; } public System.Func? TracesSampler { get; set; } + public Sentry.Extensibility.ITransport? Transport { get; set; } public bool UseAsyncFileIO { get; set; } } public static class SentryOptionsExtensions @@ -1038,6 +1039,10 @@ namespace Sentry.Extensibility { Sentry.SentryStackTrace? Create(System.Exception? exception = null); } + public interface ITransport + { + System.Threading.Tasks.Task SendEnvelopeAsync(Sentry.Protocol.Envelopes.Envelope envelope, System.Threading.CancellationToken cancellationToken = default); + } public class RequestBodyExtractionDispatcher : Sentry.Extensibility.IRequestPayloadExtractor { public RequestBodyExtractionDispatcher(System.Collections.Generic.IEnumerable extractors, Sentry.SentryOptions options, System.Func sizeSwitch) { }