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

Make ITransport and SentryOptions.Transport public #1602

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 1 addition & 6 deletions src/Sentry/Extensibility/ITransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sentry.Extensibility
/// <summary>
/// An abstraction to the transport of the event.
/// </summary>
internal interface ITransport
public interface ITransport
{
/// <summary>
/// Sends the <see cref="Envelope" /> to Sentry asynchronously.
Expand All @@ -16,9 +16,4 @@ internal interface ITransport
/// <param name="cancellationToken">The cancellation token.</param>
Task SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken = default);
}

internal interface IFlushableTransport : ITransport
{
Task FlushAsync(CancellationToken cancellationToken = default);
}
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/Http/CachingTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Internal/SdkComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,9 +50,13 @@ public bool IsGlobalModeEnabled

/// <summary>
/// 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.
/// </summary>
internal ITransport? Transport { get; set; }
/// <remarks>
/// If <seealso cref="CacheDirectoryPath"/> is set, any transport set here will be wrapped in a
/// <seealso cref="CachingTransport"/> and used as its inner transport.
/// </remarks>
public ITransport? Transport { get; set; }

internal ISentryStackTraceFactory? SentryStackTraceFactory { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
5 changes: 5 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core2_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
5 changes: 5 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
5 changes: 5 additions & 0 deletions test/Sentry.Tests/ApiApprovalTests.Run.Core3_1.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace Sentry
public Sentry.StackTraceMode StackTraceMode { get; set; }
public double TracesSampleRate { get; set; }
public System.Func<Sentry.TransactionSamplingContext, double?>? TracesSampler { get; set; }
public Sentry.Extensibility.ITransport? Transport { get; set; }
public bool UseAsyncFileIO { get; set; }
}
public static class SentryOptionsExtensions
Expand Down Expand Up @@ -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<Sentry.Extensibility.IRequestPayloadExtractor> extractors, Sentry.SentryOptions options, System.Func<Sentry.Extensibility.RequestSize> sizeSwitch) { }
Expand Down