Skip to content

Commit c548726

Browse files
Merge pull request #113 from stackify/feature/WIN-291
Support manual injection of RUM settings via method on page
2 parents 2665bb8 + 7b25381 commit c548726

File tree

6 files changed

+493
-46
lines changed

6 files changed

+493
-46
lines changed

Src/StackifyLib/Config.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Text.RegularExpressions;
45
using StackifyLib.Utils;
56

67
namespace StackifyLib
@@ -108,6 +109,26 @@ public static void LoadSettings()
108109
LoggingJsonMaxFields = maxFields;
109110
}
110111
}
112+
113+
var rumScriptUrl = Get("Stackify.Rum_Script_Url", "https://stckjs.stackify.com/stckjs.js");
114+
115+
if (Uri.IsWellFormedUriString(rumScriptUrl, UriKind.Absolute))
116+
{
117+
var uri = new Uri(rumScriptUrl);
118+
119+
var scheme = uri.Scheme;
120+
121+
if (string.Equals(scheme, "https", StringComparison.OrdinalIgnoreCase))
122+
{
123+
RumScriptUrl = rumScriptUrl;
124+
}
125+
}
126+
127+
var rumKey = Get("Stackify.Rum_Key");
128+
if (Regex.IsMatch(rumKey, "^[A-Za-z0-9_-]+$"))
129+
{
130+
RumKey = rumKey;
131+
}
111132
}
112133
catch (Exception ex)
113134
{
@@ -150,6 +171,10 @@ public static void LoadSettings()
150171

151172
public static int LoggingJsonMaxFields { get; set; } = 50;
152173

174+
public static string RumScriptUrl { get; set; }
175+
176+
public static string RumKey { get; set; }
177+
153178

154179
/// <summary>
155180
/// Attempts to fetch a setting value given the key.
@@ -171,6 +196,13 @@ internal static string Get(string key, string defaultValue = null)
171196
{
172197
var appSettings = _configuration.GetSection("Stackify");
173198
v = appSettings[key.Replace("Stackify.", string.Empty)];
199+
200+
if (string.IsNullOrEmpty(v))
201+
{
202+
// Search in Retrace, but key will likely still be Stackify.name, not Retrace.name in the code
203+
var retraceAppSettings = _configuration.GetSection("Retrace");
204+
v = retraceAppSettings[key.Replace("Stackify.", string.Empty)];
205+
}
174206
}
175207
#endif
176208

@@ -185,6 +217,22 @@ internal static string Get(string key, string defaultValue = null)
185217
{
186218
v = System.Environment.GetEnvironmentVariable(key);
187219
}
220+
221+
if (string.IsNullOrEmpty(v))
222+
{
223+
v = System.Environment.GetEnvironmentVariable(key.ToUpperInvariant());
224+
}
225+
226+
if (string.IsNullOrEmpty(v))
227+
{
228+
// Linux systems do not allow period in an environment variable name
229+
v = System.Environment.GetEnvironmentVariable(key.Replace('.', '_').ToUpperInvariant());
230+
}
231+
232+
if (string.IsNullOrEmpty(v) && key.StartsWith("Stackify."))
233+
{
234+
v = System.Environment.GetEnvironmentVariable("RETRACE_" + key.Substring(9).Replace('.', '_').ToUpperInvariant());
235+
}
188236
}
189237
}
190238
finally

Src/StackifyLib/Extensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public static void ConfigureStackifyLogging(this Microsoft.Extensions.Configurat
3838
//tell it to load all the settings since we now have the config
3939
Config.LoadSettings();
4040
}
41+
42+
public static void ConfigureStackifyLib(this Microsoft.Extensions.Configuration.IConfiguration configuration)
43+
{
44+
Config.SetConfiguration(configuration);
45+
//tell it to load all the settings since we now have the config
46+
Config.LoadSettings();
47+
}
4148
#endif
4249
}
4350
}

Src/StackifyLib/Internal/Logs/LogQueue.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Threading.Tasks;
1111

1212
#if NETFULL
13-
using System.Runtime.Remoting.Messaging;
1413
using StackifyLib.Web;
1514
using System.Web;
1615
#endif
@@ -106,27 +105,7 @@ public void QueueLogMessage(Models.LogMsg msg)
106105
#if NETFULL
107106
try
108107
{
109-
if (string.IsNullOrEmpty(msg.TransID))
110-
{
111-
var stackifyRequestID = CallContext.LogicalGetData("Stackify-RequestID");
112-
113-
if (stackifyRequestID != null)
114-
{
115-
msg.TransID = stackifyRequestID.ToString();
116-
}
117-
}
118-
119-
if (string.IsNullOrEmpty(msg.TransID))
120-
{
121-
//gets from Trace.CorrelationManager.ActivityId but doesnt assume it is guid since it technically doesn't have to be
122-
//not calling the CorrelationManager method because it blows up if it isn't a guid
123-
var correltionManagerId = CallContext.LogicalGetData("E2ETrace.ActivityID");
124-
125-
if (correltionManagerId != null && correltionManagerId is Guid && ((Guid)correltionManagerId) != Guid.Empty)
126-
{
127-
msg.TransID = correltionManagerId.ToString();
128-
}
129-
}
108+
msg.TransID = StackifyLib.Utils.HelperFunctions.GetRequestId();
130109

131110
if (string.IsNullOrEmpty(msg.TransID))
132111
{
@@ -186,27 +165,11 @@ public void QueueLogMessage(Models.LogMsg msg)
186165
// get RequestID
187166
if (string.IsNullOrEmpty(msg.TransID))
188167
{
189-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
168+
string reqId = StackifyLib.Utils.HelperFunctions.GetRequestId();
190169

191-
var agentAssemblyQry = assemblies.Where(assembly => assembly.FullName.Contains("Stackify.Agent"));
192-
if(agentAssemblyQry.Count() > 0)
170+
if (reqId != null)
193171
{
194-
var middleware = agentAssemblyQry.First();
195-
var callContextType = middleware.GetType("Stackify.Agent.Threading.StackifyCallContext");
196-
if (callContextType != null)
197-
{
198-
var traceCtxType = middleware.GetType("Stackify.Agent.Tracing.ITraceContext");
199-
if(traceCtxType != null)
200-
{
201-
var traceContextProp = callContextType.GetProperty("TraceContext")?.GetValue(null);
202-
if (traceContextProp != null)
203-
{
204-
var reqIdProp = traceCtxType.GetProperty("RequestId")?.GetValue(traceContextProp)?.ToString();
205-
if(!string.IsNullOrEmpty(reqIdProp))
206-
msg.TransID = reqIdProp;
207-
}
208-
}
209-
}
172+
msg.TransID = reqId;
210173
}
211174
}
212175
#endif

Src/StackifyLib/StackifyLib.csproj

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

33
<PropertyGroup>
44
<AssemblyTitle>Stackify API</AssemblyTitle>
5-
<VersionPrefix>2.1.0</VersionPrefix>
5+
<VersionPrefix>2.2.2</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.1.10</Version>
16+
<Version>2.2.2</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.1.10.0</AssemblyVersion>
24-
<FileVersion>2.1.10.0</FileVersion>
23+
<AssemblyVersion>2.2.2.0</AssemblyVersion>
24+
<FileVersion>2.2.2.0</FileVersion>
2525
<PackageReleaseNotes>Remove default internal file logger</PackageReleaseNotes>
2626
</PropertyGroup>
2727

@@ -56,4 +56,4 @@
5656
<DefineConstants>NETFULL</DefineConstants>
5757
</PropertyGroup>
5858

59-
</Project>
59+
</Project>

0 commit comments

Comments
 (0)