-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSdkComposer.cs
More file actions
96 lines (81 loc) · 3.68 KB
/
SdkComposer.cs
File metadata and controls
96 lines (81 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Sentry.Extensibility;
using Sentry.Http;
using Sentry.Infrastructure;
using Sentry.Internal.Http;
namespace Sentry.Internal;
internal class SdkComposer
{
private readonly SentryOptions _options;
private readonly BackpressureMonitor? _backpressureMonitor;
public SdkComposer(SentryOptions options, BackpressureMonitor? backpressureMonitor)
{
ArgumentNullException.ThrowIfNull(options);
_options = options;
if (options.Dsn is null)
{
throw new ArgumentException("No DSN defined in the SentryOptions");
}
_backpressureMonitor = backpressureMonitor;
}
private ITransport CreateTransport()
{
_options.LogDebug("Creating transport.");
// Start from either the transport given on options, or create a new HTTP transport.
var transport = _options.Transport ?? new LazyHttpTransport(_options, _backpressureMonitor);
// When a cache directory path is given, wrap the transport in a caching transport.
if (!string.IsNullOrWhiteSpace(_options.CacheDirectoryPath))
{
_options.LogDebug("Cache directory path is specified.");
if (_options.DisableFileWrite)
{
_options.LogInfo("File write has been disabled via the options. Skipping caching transport creation.");
}
else
{
_options.LogDebug("File writing is enabled, wrapping transport in caching transport.");
transport = CachingTransport.Create(transport, _options);
}
}
else
{
_options.LogDebug("No cache directory path specified. Skipping caching transport creation.");
}
// Wrap the transport with the Spotlight one that double sends the envelope: Sentry + Spotlight
if (_options.EnableSpotlight)
{
var environment = _options.SettingLocator.GetEnvironment(true);
if (string.Equals(environment, Constants.ProductionEnvironmentSetting, StringComparison.OrdinalIgnoreCase))
{
_options.LogWarning("""
[Spotlight] It seems you're not in dev mode because environment is set to 'production'.
Do you really want to have Spotlight enabled?
You can set a different environment via SENTRY_ENVIRONMENT env var or programatically during Init.
Docs on Environment: https://docs.sentry.io/platforms/dotnet/configuration/environments/
""");
}
else
{
_options.LogInfo("Connecting to Spotlight at {0}", _options.SpotlightUrl);
}
if (!Uri.TryCreate(_options.SpotlightUrl, UriKind.Absolute, out var spotlightUrl))
{
throw new InvalidOperationException("Invalid option for SpotlightUrl: " + _options.SpotlightUrl);
}
transport = new SpotlightHttpTransport(transport, _options, _options.GetHttpClient(), spotlightUrl, SystemClock.Clock);
}
// Always persist the transport on the options, so other places can pick it up where necessary.
_options.Transport = transport;
return transport;
}
public IBackgroundWorker CreateBackgroundWorker()
{
if (_options.BackgroundWorker is { } worker)
{
_options.LogDebug("Using IBackgroundWorker set through options: {0}.",
worker.GetType().Name);
return worker;
}
var transport = CreateTransport();
return new BackgroundWorker(transport, _options, _backpressureMonitor);
}
}