Skip to content

Commit d141b67

Browse files
author
Todd Lair
committed
Merge branch 'develop'
2 parents 3082a94 + 18b8876 commit d141b67

File tree

8 files changed

+142
-46
lines changed

8 files changed

+142
-46
lines changed

Src/StackifyLib.AspNetCore/Extensions.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ public static void ConfigureStackifyLogging(this Microsoft.AspNetCore.Builder.IA
1111
try
1212
{
1313
Configure.SubscribeToWebRequestDetails(app.ApplicationServices);
14+
}
15+
catch (Exception ex)
16+
{
17+
Debug.WriteLine($"#Extensions - #AspNetCore - Error Subscribing to WebRequestDetails {ex}");
18+
StackifyLib.Utils.StackifyAPILogger.Log("#Extensions - #AspNetCore - Error Subscribing to WebRequestDetails", ex);
19+
}
1420

15-
if (configuration != null)
21+
try
22+
{
23+
if (configuration == null)
1624
{
17-
StackifyLib.Config.SetConfiguration(configuration);
18-
19-
//tell it to load all the settings since we now have the config
20-
Config.LoadSettings();
25+
StackifyLib.Utils.StackifyAPILogger.Log("#Extensions - #AspNetCore - Empty configuration, ignoring");
26+
return;
2127
}
28+
29+
StackifyLib.Utils.StackifyAPILogger.Log("#Extensions - #AspNetCore - ConfigureStackifyLogging - Initialize");
30+
StackifyLib.Config.SetConfiguration(configuration);
31+
StackifyLib.Utils.StackifyAPILogger.Log("#Extensions - #AspNetCore - ConfigureStackifyLogging - Settings Loaded");
32+
Config.LoadSettings();
2233
}
2334
catch (Exception ex)
2435
{
25-
Debug.WriteLine($"Error in ConfigureStackifyLogging {ex}");
36+
Debug.WriteLine($"#Extensions - #AspNetCore - Error in ConfigureStackifyLogging {ex}");
37+
StackifyLib.Utils.StackifyAPILogger.Log("#Extensions - #AspNetCore - Error in ConfigureStackifyLogging", ex);
2638
}
2739
}
2840
}

Src/StackifyLib.AspNetCore/StackifyLib.AspNetCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>StackifyLib for AspNetCore</AssemblyTitle>
5-
<VersionPrefix>2.1.0</VersionPrefix>
5+
<VersionPrefix>2.1.6</VersionPrefix>
66
<TargetFrameworks>netstandard2.0;net461;net462</TargetFrameworks>
77
<AssemblyName>StackifyLib.AspNetCore</AssemblyName>
88
<PackageId>StackifyLib.AspNetCore</PackageId>
99
<PackageTags>stackify;metrics;errors;logs</PackageTags>
1010
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1111
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1212
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
13-
<Version>2.1.6</Version>
13+
<Version>2.1.6-beta</Version>
1414
<Description>StackifyLib.AspNetCore</Description>
1515
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
1616
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>

Src/StackifyLib/Config.cs

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@ public static void LoadSettings()
3838
try
3939
{
4040
if (IsStackifyJsonLoaded == false) {
41+
StackifyAPILogger.Log($"#Config - LoadSettings - Stackify JSON - Read");
4142
ReadStackifyJSONConfig(); // TODO: Better way?
4243
}
4344

45+
if (IsStackifyJsonLoaded == true)
46+
{
47+
StackifyAPILogger.Log($"#Config - LoadSettings - Stackify JSON Loaded");
48+
}
49+
50+
#if NETCORE || NETCOREX
51+
if (_configuration != null)
52+
{
53+
StackifyAPILogger.Log($"#Config - LoadSettings - Configuration Set");
54+
}
55+
#endif
56+
4457
CaptureServerVariables = Get("Stackify.CaptureServerVariables", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
4558

4659
CaptureSessionVariables = Get("Stackify.CaptureSessionVariables", bool.FalseString).Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
@@ -134,7 +147,7 @@ public static void LoadSettings()
134147
}
135148

136149
var rumKey = Get("Stackify.Rum_Key");
137-
if (Regex.IsMatch(rumKey, "^[A-Za-z0-9_-]+$"))
150+
if (string.IsNullOrWhiteSpace(rumKey) == false && Regex.IsMatch(rumKey, "^[A-Za-z0-9_-]+$"))
138151
{
139152
RumKey = rumKey;
140153
}
@@ -143,6 +156,15 @@ public static void LoadSettings()
143156
{
144157
StackifyAPILogger.Log("#Config #LoadSettings failed", ex);
145158
}
159+
160+
try
161+
{
162+
StackifyAPILogger.EvaluateLogEnabled();
163+
}
164+
catch (Exception ex)
165+
{
166+
StackifyAPILogger.Log("#Config #LoadSettings StackifyAPILogger.EvaluateLogEnabled failed", ex);
167+
}
146168
}
147169

148170
public static string ApiKey { get; set; }
@@ -197,6 +219,7 @@ public static void LoadSettings()
197219
internal static string Get(string key, string defaultValue = null)
198220
{
199221
string v = null;
222+
string section = null;
200223

201224
try
202225
{
@@ -207,55 +230,69 @@ internal static string Get(string key, string defaultValue = null)
207230
{
208231
var appSettings = _configuration.GetSection("Stackify");
209232
v = appSettings[key.Replace("Stackify.", string.Empty)];
233+
section = "ConfigStackify";
210234

211235
//Get settings from Stackify.json
212-
if (string.IsNullOrEmpty(v))
236+
if (string.IsNullOrWhiteSpace(v))
213237
{
214238
var key2 = key.Replace("Stackify.", string.Empty);
215239
var stackifyJson = _configuration.GetSection(key2);
216240
v = stackifyJson.Value;
217-
if (string.IsNullOrEmpty(v))
241+
section = "ConfigDirect";
242+
243+
if (string.IsNullOrWhiteSpace(v))
218244
{
219245
// Search in Retrace, but key will likely still be Stackify.name, not Retrace.name in the code
220246
var retraceAppSettings = _configuration.GetSection("Retrace");
221247
v = retraceAppSettings[key.Replace("Stackify.", string.Empty)];
248+
section = "ConfigRetrace";
222249
}
223250
}
224251
}
225252
#endif
226253

227254
#if NETFULL
228-
if (string.IsNullOrEmpty(v))
229-
{
230-
v = System.Configuration.ConfigurationManager.AppSettings[key];
231-
}
255+
if (string.IsNullOrWhiteSpace(v))
256+
{
257+
v = System.Configuration.ConfigurationManager.AppSettings[key];
258+
section = "AppSettings";
259+
}
232260
#endif
233261

234-
if (string.IsNullOrEmpty(v))
235-
{
236-
v = System.Environment.GetEnvironmentVariable(key);
237-
}
262+
if (string.IsNullOrWhiteSpace(v))
263+
{
264+
v = System.Environment.GetEnvironmentVariable(key);
265+
section = "Env";
266+
}
238267

239-
if (string.IsNullOrEmpty(v))
240-
{
241-
v = System.Environment.GetEnvironmentVariable(key.ToUpperInvariant());
242-
}
268+
if (string.IsNullOrWhiteSpace(v))
269+
{
270+
v = System.Environment.GetEnvironmentVariable(key.ToUpperInvariant());
271+
section = "EnvUpper";
272+
}
243273

244-
if (string.IsNullOrEmpty(v))
245-
{
246-
// Linux systems do not allow period in an environment variable name
247-
v = System.Environment.GetEnvironmentVariable(key.Replace('.', '_').ToUpperInvariant());
248-
}
274+
if (string.IsNullOrWhiteSpace(v))
275+
{
276+
// Linux systems do not allow period in an environment variable name
277+
v = System.Environment.GetEnvironmentVariable(key.Replace('.', '_').ToUpperInvariant());
278+
section = "EnvUpperLinux";
279+
}
249280

250-
if (string.IsNullOrEmpty(v) && key.StartsWith("Stackify."))
251-
{
252-
v = System.Environment.GetEnvironmentVariable("RETRACE_" + key.Substring(9).Replace('.', '_').ToUpperInvariant());
253-
}
281+
if (string.IsNullOrWhiteSpace(v) && key.StartsWith("Stackify."))
282+
{
283+
v = System.Environment.GetEnvironmentVariable("RETRACE_" + key.Substring(9).Replace('.', '_').ToUpperInvariant());
284+
section = "EnvUpperLinuxRetrace";
285+
}
286+
287+
if (string.IsNullOrWhiteSpace(v) == false)
288+
{
289+
StackifyAPILogger.Log($"#Config - #Get - Section: {section} - Key: {key} - Value: {v ?? "Empty"}");
290+
}
254291
}
255292
}
256-
catch (Exception ex)
293+
catch (Exception ex)
257294
{
258-
StackifyAPILogger.Log("#Config #Get failed", ex);
295+
StackifyAPILogger.Log("#Config - #Get - #Failed", ex);
259296
}
260297
finally
261298
{
@@ -278,13 +315,11 @@ public static void ReadStackifyJSONConfig()
278315
string jsonPath = string.Empty;
279316
string json = string.Empty;
280317

281-
ASPEnvironment = "Production";
282-
283-
if (!String.IsNullOrEmpty(ASPEnvironment))
318+
if (!String.IsNullOrWhiteSpace(ASPEnvironment))
284319
{
285320
jsonPath = Path.Combine(baseDirectory, $"Stackify.{ASPEnvironment}.json");
286321
}
287-
else if (!String.IsNullOrEmpty(DotnetEnvironment))
322+
else if (!String.IsNullOrWhiteSpace(DotnetEnvironment))
288323
{
289324
jsonPath = Path.Combine(baseDirectory, $"Stackify.{DotnetEnvironment}.json");
290325
}
@@ -293,6 +328,7 @@ public static void ReadStackifyJSONConfig()
293328
jsonPath = Path.Combine(baseDirectory, "Stackify.json");
294329
}
295330

331+
StackifyAPILogger.Log($"#Config #Json Load - Path: {jsonPath}");
296332
if (File.Exists(jsonPath))
297333
{
298334
using (var fs = new FileStream(jsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
@@ -312,11 +348,11 @@ public static void ReadStackifyJSONConfig()
312348
string iisBaseDirectory = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
313349
string iisJsonPath = string.Empty;
314350

315-
if (!String.IsNullOrEmpty(ASPEnvironment))
351+
if (!String.IsNullOrWhiteSpace(ASPEnvironment))
316352
{
317353
iisJsonPath = Path.Combine(iisBaseDirectory, $"Stackify.{ASPEnvironment}.json");
318354
}
319-
else if (!String.IsNullOrEmpty(DotnetEnvironment))
355+
else if (!String.IsNullOrWhiteSpace(DotnetEnvironment))
320356
{
321357
iisJsonPath = Path.Combine(iisBaseDirectory, $"Stackify.{DotnetEnvironment}.json");
322358
}
@@ -325,6 +361,7 @@ public static void ReadStackifyJSONConfig()
325361
iisJsonPath = Path.Combine(iisBaseDirectory, "Stackify.json");
326362
}
327363

364+
StackifyAPILogger.Log($"#Config #Json Load - Path: {iisJsonPath}");
328365
if (File.Exists(iisJsonPath))
329366
{
330367
using (var fs = new FileStream(iisJsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
@@ -402,6 +439,7 @@ public static void SetStackifyObj(JObject obj)
402439
AppName = TryGetValue(obj, "AppName") ?? AppName;
403440
Environment = TryGetValue(obj, "Environment") ?? Environment;
404441
ApiKey = TryGetValue(obj, "ApiKey") ?? ApiKey;
442+
StackifyAPILogger.Log($"#Config #Json #SetStackifyObj Load - AppName: {AppName} - Environment: {Environment} - ApiKey: {ApiKey}");
405443
}
406444

407445
private static string TryGetValue(JToken jToken, string key)
@@ -424,6 +462,7 @@ private static string TryGetValue(JToken jToken, string key)
424462
}
425463

426464
r = val.ToString();
465+
StackifyAPILogger.Log($"#Config #TryGetValue #Json Success - Key: {key} - Value: {r ?? "Empty"}");
427466
}
428467
catch (Exception ex)
429468
{

Src/StackifyLib/Extensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ public static StackifyLib.StackifyError NewStackifyError(this Exception ex)
3434
#if NETCORE || NETCOREX
3535
public static void ConfigureStackifyLogging(this Microsoft.Extensions.Configuration.IConfiguration configuration)
3636
{
37+
StackifyAPILogger.Log("#Extensions - ConfigureStackifyLogging - Initialize");
3738
Config.SetConfiguration(configuration);
3839
//tell it to load all the settings since we now have the config
3940
Config.LoadSettings();
41+
StackifyAPILogger.Log("#Extensions - ConfigureStackifyLogging - Settings Loaded");
4042
}
4143

4244
public static void ConfigureStackifyLib(this Microsoft.Extensions.Configuration.IConfiguration configuration)
4345
{
46+
StackifyAPILogger.Log("#Extensions - ConfigureStackifyLib - Initialize");
4447
Config.SetConfiguration(configuration);
4548
//tell it to load all the settings since we now have the config
4649
Config.LoadSettings();
50+
StackifyAPILogger.Log("#Extensions - ConfigureStackifyLib - Settings Loaded");
4751
}
4852
#endif
4953
}

Src/StackifyLib/Models/EnvironmentDetail.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,5 +490,37 @@ public string AppNameToUse()
490490

491491
return AppName;
492492
}
493+
494+
public void UpdateAppName()
495+
{
496+
if (!string.IsNullOrEmpty(ConfiguredAppName))
497+
{
498+
return;
499+
}
500+
501+
if (!string.IsNullOrEmpty(Config.AppName))
502+
{
503+
ConfiguredAppName = Config.AppName;
504+
return;
505+
}
506+
507+
ConfiguredAppName = Config.Get("Stackify.AppName");
508+
}
509+
510+
public void UpdateEnvironmentName()
511+
{
512+
if (!string.IsNullOrEmpty(ConfiguredEnvironmentName))
513+
{
514+
return;
515+
}
516+
517+
if (!string.IsNullOrEmpty(Config.Environment))
518+
{
519+
ConfiguredEnvironmentName = Config.Environment;
520+
return;
521+
}
522+
523+
ConfiguredEnvironmentName = Config.Get("Stackify.Environment");
524+
}
493525
}
494526
}

Src/StackifyLib/StackifyLib.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>Stackify API</AssemblyTitle>
5-
<VersionPrefix>2.2.3</VersionPrefix>
5+
<VersionPrefix>2.2.5</VersionPrefix>
66
<TargetFrameworks>netstandard2.0;net40;net45;net451;net452;net46;net461;net462</TargetFrameworks>
77
<AssemblyName>StackifyLib</AssemblyName>
88
<PackageId>StackifyLib</PackageId>
@@ -13,15 +13,15 @@
1313
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1414
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1515
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
16-
<Version>2.2.3</Version>
16+
<Version>2.2.5</Version>
1717
<Authors>StackifyLib</Authors>
1818
<PackageProjectUrl>https://github.com/stackify/stackify-api-dotnet</PackageProjectUrl>
1919
<PackageLicenseUrl>https://github.com/stackify/stackify-api-dotnet/blob/master/LICENSE</PackageLicenseUrl>
2020
<RepositoryUrl>https://github.com/stackify/stackify-api-dotnet</RepositoryUrl>
2121
<RepositoryType>git</RepositoryType>
2222
<PackageIconUrl>https://stackify.com/wp-content/uploads/2017/02/stk.png</PackageIconUrl>
23-
<AssemblyVersion>2.2.3.0</AssemblyVersion>
24-
<FileVersion>2.2.3.0</FileVersion>
23+
<AssemblyVersion>2.2.5.0</AssemblyVersion>
24+
<FileVersion>2.2.5.0</FileVersion>
2525
<PackageReleaseNotes>Remove default internal file logger</PackageReleaseNotes>
2626
</PropertyGroup>
2727

Src/StackifyLib/Utils/HttpClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ public bool IdentifyApp()
302302
}
303303
StackifyAPILogger.Log("Calling to Identify App");
304304
EnvironmentDetail env = EnvironmentDetail.Get();
305+
env.UpdateEnvironmentName();
306+
env.UpdateAppName();
307+
if (string.IsNullOrEmpty(env.ConfiguredAppName) && !string.IsNullOrEmpty(Config.AppName)) {
308+
env.ConfiguredAppName = Config.AppName;
309+
}
310+
311+
if (string.IsNullOrEmpty(env.ConfiguredEnvironmentName) && !string.IsNullOrEmpty(Config.Environment)) {
312+
env.ConfiguredEnvironmentName = Config.Environment;
313+
}
314+
305315
string jsonData = JsonConvert.SerializeObject(env, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
306316

307317
var response =

Src/StackifyLib/Utils/StackifyAPILogger.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class StackifyAPILogger
1919

2020
static StackifyAPILogger()
2121
{
22-
EvaluateLogEnabled();
2322
}
2423

2524
public static bool LogEnabled
@@ -85,7 +84,7 @@ public static void Log(string message, Exception ex, bool logAnyways = false)
8584
}
8685
}
8786

88-
private static void EvaluateLogEnabled()
87+
public static void EvaluateLogEnabled()
8988
{
9089
if (_logEnabled == null)
9190
{

0 commit comments

Comments
 (0)