Skip to content

Commit 801edc3

Browse files
authored
fix: Agent license key should be optional in Serverless mode. (#2499) (#2500)
1 parent f1a7bf6 commit 801edc3

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/Agent/NewRelic/Agent/Core/AgentManager.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ private void AssertAgentEnabled()
176176
if (!Configuration.AgentEnabled)
177177
throw new Exception(string.Format("The New Relic agent is disabled. Update {0} to re-enable it.", Configuration.AgentEnabledAt));
178178

179-
if ("REPLACE_WITH_LICENSE_KEY".Equals(Configuration.AgentLicenseKey))
180-
throw new Exception("Please set your license key.");
179+
if (!Configuration.ServerlessModeEnabled) // license key is not required to be set in serverless mode
180+
{
181+
if ("REPLACE_WITH_LICENSE_KEY".Equals(Configuration.AgentLicenseKey))
182+
throw new Exception("Please set your license key.");
183+
}
181184
}
182185

183186
private void Initialize(bool serverlessModeEnabled)

src/Agent/NewRelic/Agent/Core/BrowserMonitoring/BrowserMonitoringScriptMaker.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ public string GetScript(IInternalTransaction transaction, string nonce)
7070
}
7171

7272
var licenseKey = _configurationService.Configuration.AgentLicenseKey;
73-
if (licenseKey == null)
74-
throw new NullReferenceException(nameof(licenseKey));
75-
if (licenseKey.Length <= 0)
76-
throw new Exception("License key is empty");
73+
// serverless mode doesn't require a license key, so this check can fail.
74+
if (string.IsNullOrEmpty(licenseKey) || "REPLACE_WITH_LICENSE_KEY".Equals(licenseKey))
75+
{
76+
Log.Debug("Skipping RUM injection because license key is not set.");
77+
return null;
78+
}
7779

7880
var browserConfigurationData = GetBrowserConfigurationData(transaction, transactionMetricName, licenseKey);
7981

tests/Agent/UnitTests/Core.UnitTest/BrowserMonitoring/BrowserMonitoringScriptMakerTests.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,14 @@ public void GetScript_ReturnsNull_IfBrowserMonitoringJavaScriptAgentIsEmpty()
182182
}
183183

184184
[Test]
185-
public void GetScript_Throws_IfAgentLicenseKeyIsNull()
185+
public void GetScript_ReturnsNull_IfAgentLicenseKeyIsNotSet()
186186
{
187187
Mock.Arrange(() => _configuration.AgentLicenseKey).Returns(null as string);
188188
var transaction = BuildTestTransaction();
189189

190-
Assert.Throws<NullReferenceException>(() => _browserMonitoringScriptMaker.GetScript(transaction, null));
191-
}
192-
193-
[Test]
194-
public void GetScript_Throws_IfAgentLicenseKeyIsEmpty()
195-
{
196-
Mock.Arrange(() => _configuration.AgentLicenseKey).Returns(string.Empty);
197-
var transaction = BuildTestTransaction();
190+
var script = _browserMonitoringScriptMaker.GetScript(transaction, null);
198191

199-
Assert.Throws<Exception>(() => _browserMonitoringScriptMaker.GetScript(transaction, null));
192+
Assert.That(script, Is.Null);
200193
}
201194

202195
[Test]

0 commit comments

Comments
 (0)