Skip to content

Commit f461a43

Browse files
committed
Updated the default submission client to use compression
1 parent 3fa990d commit f461a43

File tree

14 files changed

+57
-203
lines changed

14 files changed

+57
-203
lines changed

src/Exceptionless.Portable/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@ public static class ExceptionlessClientExtensions {
1414
/// </summary>
1515
/// <param name="client">The ExceptionlessClient.</param>
1616
public static void Startup(this ExceptionlessClient client) {
17-
if (client.Configuration.Resolver.HasDefaultRegistration<ISubmissionClient, DefaultSubmissionClient>())
18-
client.Configuration.Resolver.Register<ISubmissionClient, SubmissionClient>();
19-
20-
if (client.Configuration.Resolver.HasDefaultRegistration<IEnvironmentInfoCollector, DefaultEnvironmentInfoCollector>())
21-
client.Configuration.Resolver.Register<IEnvironmentInfoCollector, EnvironmentInfoCollector>();
22-
2317
client.Configuration.ReadAllConfig();
2418
#if !PORTABLE && !NETSTANDARD1_2
25-
client.Configuration.UseErrorPlugin();
2619
client.Configuration.UseTraceLogEntriesPlugin();
27-
client.Configuration.AddPlugin<VersionPlugin>();
2820
#endif
2921

3022
if (client.Configuration.UpdateSettingsWhenIdleInterval == null)

src/Exceptionless.Portable/Extensions/ExceptionlessExtraConfigurationExtensions.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
namespace Exceptionless {
2323
public static class ExceptionlessExtraConfigurationExtensions {
2424
#if !PORTABLE && !NETSTANDARD1_2
25-
/// <summary>
26-
/// Reads the Exceptionless configuration from the app.config or web.config file.
27-
/// </summary>
28-
/// <param name="config">The configuration object you want to apply the attribute settings to.</param>
29-
public static void UseErrorPlugin(this ExceptionlessConfiguration config) {
30-
config.RemovePlugin<SimpleErrorPlugin>();
31-
config.AddPlugin<Plugins.ErrorPlugin>();
32-
}
33-
3425
public static void UseTraceLogger(this ExceptionlessConfiguration config, LogLevel minLogLevel = null) {
3526
config.Resolver.Register<IExceptionlessLog>(new TraceExceptionlessLog { MinimumLogLevel = minLogLevel ?? LogLevel.Info });
3627
}

src/Exceptionless.Portable/Services/DefaultEnvironmentInfoCollector.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void PopulateApplicationInfo(EnvironmentInfo info) {
4343
try {
4444
info.Data.Add("AppDomainName", AppDomain.CurrentDomain.FriendlyName);
4545
} catch (Exception ex) {
46-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get AppDomain friendly name. Error message: {0}", ex.Message);
46+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get AppDomain friendly name. Error message: {0}", ex.Message);
4747
}
4848
#endif
4949

@@ -53,7 +53,7 @@ private void PopulateApplicationInfo(EnvironmentInfo info) {
5353
if (hostEntry != null && hostEntry.AddressList.Any())
5454
info.IpAddress = String.Join(", ", hostEntry.AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork).Select(a => a.ToString()).ToArray());
5555
} catch (Exception ex) {
56-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get ip address. Error message: {0}", ex.Message);
56+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get ip address. Error message: {0}", ex.Message);
5757
}
5858
#endif
5959
}
@@ -62,7 +62,7 @@ private void PopulateProcessInfo(EnvironmentInfo info) {
6262
try {
6363
info.ProcessorCount = Environment.ProcessorCount;
6464
} catch (Exception ex) {
65-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get processor count. Error message: {0}", ex.Message);
65+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get processor count. Error message: {0}", ex.Message);
6666
}
6767

6868
#if !PORTABLE && !NETSTANDARD1_2
@@ -71,7 +71,7 @@ private void PopulateProcessInfo(EnvironmentInfo info) {
7171
info.ProcessName = process.ProcessName;
7272
info.ProcessId = process.Id.ToString(NumberFormatInfo.InvariantInfo);
7373
} catch (Exception ex) {
74-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process name or id. Error message: {0}", ex.Message);
74+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get process name or id. Error message: {0}", ex.Message);
7575
}
7676

7777
try {
@@ -81,7 +81,7 @@ private void PopulateProcessInfo(EnvironmentInfo info) {
8181
info.CommandLine = Environment.CommandLine;
8282
#endif
8383
} catch (Exception ex) {
84-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get command line. Error message: {0}", ex.Message);
84+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get command line. Error message: {0}", ex.Message);
8585
}
8686
#endif
8787
}
@@ -91,13 +91,13 @@ private void PopulateThreadInfo(EnvironmentInfo info) {
9191
try {
9292
info.ThreadId = Thread.CurrentThread.ManagedThreadId.ToString(NumberFormatInfo.InvariantInfo);
9393
} catch (Exception ex) {
94-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get thread id. Error message: {0}", ex.Message);
94+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get thread id. Error message: {0}", ex.Message);
9595
}
9696

9797
try {
9898
info.ThreadName = Thread.CurrentThread.Name;
9999
} catch (Exception ex) {
100-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get current thread name. Error message: {0}", ex.Message);
100+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get current thread name. Error message: {0}", ex.Message);
101101
}
102102
#endif
103103
}
@@ -108,7 +108,7 @@ private void PopulateMemoryInfo(EnvironmentInfo info) {
108108
Process process = Process.GetCurrentProcess();
109109
info.ProcessMemorySize = process.PrivateMemorySize64;
110110
} catch (Exception ex) {
111-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process memory size. Error message: {0}", ex.Message);
111+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get process memory size. Error message: {0}", ex.Message);
112112
}
113113
#endif
114114

@@ -128,7 +128,7 @@ private void PopulateMemoryInfo(EnvironmentInfo info) {
128128
info.AvailablePhysicalMemory = Convert.ToInt64(computerInfo.AvailablePhysicalMemory);
129129
}
130130
} catch (Exception ex) {
131-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get physical memory. Error message: {0}", ex.Message);
131+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get physical memory. Error message: {0}", ex.Message);
132132
}
133133
#endif
134134
}
@@ -156,7 +156,7 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
156156
info.MachineName = Guid.NewGuid().ToString("N");
157157
#endif
158158
} catch (Exception ex) {
159-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get machine name. Error message: {0}", ex.Message);
159+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get machine name. Error message: {0}", ex.Message);
160160
}
161161

162162
#if !PORTABLE && !NETSTANDARD1_2
@@ -173,7 +173,7 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
173173
computerInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
174174
#endif
175175
} catch (Exception ex) {
176-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get computer info. Error message: {0}", ex.Message);
176+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get computer info. Error message: {0}", ex.Message);
177177
}
178178

179179
#if NETSTANDARD || NET45
@@ -199,7 +199,7 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
199199
info.RuntimeVersion = Environment.Version.ToString();
200200
#endif
201201
} catch (Exception ex) {
202-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get populate runtime info. Error message: {0}", ex.Message);
202+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get populate runtime info. Error message: {0}", ex.Message);
203203
}
204204
#endif
205205
}
@@ -216,7 +216,7 @@ private bool Is64BitOperatingSystem() {
216216

217217
return ((methodExist && KernelNativeMethods.IsWow64Process(KernelNativeMethods.GetCurrentProcess(), out is64)) && is64);
218218
} catch (Exception ex) {
219-
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get CPU architecture. Error message: {0}", ex.Message);
219+
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get CPU architecture. Error message: {0}", ex.Message);
220220
}
221221

222222
return false;

src/Exceptionless.Portable/Submission/DefaultSubmissionClient.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Net;
4+
using System.Runtime.CompilerServices;
45
using Exceptionless.Configuration;
56
using Exceptionless.Dependency;
67
using Exceptionless.Extensions;
@@ -11,13 +12,17 @@
1112

1213
namespace Exceptionless.Submission {
1314
public class DefaultSubmissionClient : ISubmissionClient {
15+
static DefaultSubmissionClient() {
16+
ConfigureServicePointManagerSettings();
17+
}
18+
1419
public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessConfiguration config, IJsonSerializer serializer) {
1520
var data = serializer.Serialize(events);
1621

1722
HttpWebResponse response;
1823
try {
1924
var request = CreateHttpWebRequest(config, String.Format("{0}/events", config.GetServiceEndPoint()));
20-
response = request.PostJsonAsync(data).ConfigureAwait(false).GetAwaiter().GetResult() as HttpWebResponse;
25+
response = request.PostJsonAsyncWithCompression(data).ConfigureAwait(false).GetAwaiter().GetResult() as HttpWebResponse;
2126
} catch (WebException ex) {
2227
response = (HttpWebResponse)ex.Response;
2328
if (response == null)
@@ -39,7 +44,7 @@ public SubmissionResponse PostUserDescription(string referenceId, UserDescriptio
3944
HttpWebResponse response;
4045
try {
4146
var request = CreateHttpWebRequest(config, String.Format("{0}/events/by-ref/{1}/user-description", config.GetServiceEndPoint(), referenceId));
42-
response = request.PostJsonAsync(data).ConfigureAwait(false).GetAwaiter().GetResult() as HttpWebResponse;
47+
response = request.PostJsonAsyncWithCompression(data).ConfigureAwait(false).GetAwaiter().GetResult() as HttpWebResponse;
4348
} catch (WebException ex) {
4449
response = (HttpWebResponse)ex.Response;
4550
if (response == null)
@@ -55,7 +60,7 @@ public SubmissionResponse PostUserDescription(string referenceId, UserDescriptio
5560
return new SubmissionResponse((int)response.StatusCode, GetResponseMessage(response));
5661
}
5762

58-
public SettingsResponse GetSettings(ExceptionlessConfiguration config, int version, IJsonSerializer serializer) {
63+
public SettingsResponse GetSettings(ExceptionlessConfiguration config, int version, IJsonSerializer serializer) {
5964
HttpWebResponse response;
6065
try {
6166
var request = CreateHttpWebRequest(config, String.Format("{0}/projects/config?v={1}", config.GetServiceEndPoint(), version));
@@ -78,7 +83,7 @@ public SettingsResponse GetSettings(ExceptionlessConfiguration config, int versi
7883
var settings = serializer.Deserialize<ClientConfiguration>(json);
7984
return new SettingsResponse(true, settings.Settings, settings.Version);
8085
}
81-
86+
8287
public void SendHeartbeat(string sessionIdOrUserId, bool closeSession, ExceptionlessConfiguration config) {
8388
try {
8489
var request = CreateHttpWebRequest(config, String.Format("{0}/events/session/heartbeat?id={1}&close={2}", config.GetHeartbeatServiceEndPoint(), sessionIdOrUserId, closeSession));
@@ -108,14 +113,33 @@ private static string GetResponseMessage(HttpWebResponse response) {
108113
}
109114

110115
protected virtual HttpWebRequest CreateHttpWebRequest(ExceptionlessConfiguration config, string url) {
111-
#if PORTABLE40
112-
var request = WebRequest.CreateHttp(url);
113-
#else
114-
var request = (HttpWebRequest)WebRequest.Create(url);
115-
#endif
116+
var request = (HttpWebRequest)WebRequest.Create(url);
116117
request.AddAuthorizationHeader(config);
117118
request.SetUserAgent(config);
119+
#if !PORTABLE && !NETSTANDARD
120+
request.AllowAutoRedirect = true;
121+
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.None;
122+
#endif
123+
124+
try {
125+
request.UseDefaultCredentials = true;
126+
// if (Credentials != null)
127+
// request.Credentials = Credentials;
128+
} catch (Exception) {}
129+
118130
return request;
119131
}
132+
133+
[MethodImpl(MethodImplOptions.NoInlining)]
134+
private static void ConfigureServicePointManagerSettings() {
135+
#if NET45
136+
try {
137+
ServicePointManager.Expect100Continue = false;
138+
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
139+
} catch (Exception ex) {
140+
System.Diagnostics.Trace.WriteLine(String.Concat("An error occurred while configuring SSL certificate validation. Exception: ", ex));
141+
}
142+
#endif
143+
}
120144
}
121-
}
145+
}

0 commit comments

Comments
 (0)