Skip to content

Commit 5f5dda8

Browse files
authored
feat: Improve serverless mode detection (#2661)
1 parent 7608af3 commit 5f5dda8

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/Agent/NewRelic/Home/Home.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</Target>
1414

1515
<ItemGroup>
16-
<PackageReference Include="NewRelic.Agent.Internal.Profiler" Version="10.25.1.10"/>
16+
<PackageReference Include="NewRelic.Agent.Internal.Profiler" Version="10.27.0.15"/>
1717
</ItemGroup>
1818

1919
</Project>

src/Agent/NewRelic/Profiler/Configuration/InstrumentationConfiguration.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,36 @@ namespace NewRelic { namespace Profiler { namespace Configuration
126126
return;
127127
}
128128

129-
auto lambdaInstPoint = _systemCalls->TryGetEnvironmentVariable(_X("_HANDLER"));
129+
// give precedence to the NEW_RELIC_LAMBDA_HANDLER environment variable
130+
auto lambdaInstPoint = _systemCalls->TryGetEnvironmentVariable(_X("NEW_RELIC_LAMBDA_HANDLER"));
130131
if (lambdaInstPoint != nullptr)
131132
{
132-
AddInstrumentationPointToCollectionFromEnvironment(*lambdaInstPoint);
133-
_foundServerlessInstrumentationPoint = true;
134-
return;
133+
LogDebug("Found NEW_RELIC_LAMBDA_HANDLER environment variable: ", *lambdaInstPoint);
134+
if (TryAddInstrumentationPointToCollectionFromEnvironment(*lambdaInstPoint))
135+
{
136+
_foundServerlessInstrumentationPoint = true;
137+
return;
138+
}
135139
}
136140

137-
lambdaInstPoint = _systemCalls->TryGetEnvironmentVariable(_X("NEW_RELIC_LAMBDA_HANDLER"));
141+
lambdaInstPoint = _systemCalls->TryGetEnvironmentVariable(_X("_HANDLER"));
138142
if (lambdaInstPoint != nullptr)
139143
{
140-
AddInstrumentationPointToCollectionFromEnvironment(*lambdaInstPoint);
141-
_foundServerlessInstrumentationPoint = true;
144+
LogDebug("Found _HANDLER environment variable: ", *lambdaInstPoint);
145+
if (TryAddInstrumentationPointToCollectionFromEnvironment(*lambdaInstPoint))
146+
_foundServerlessInstrumentationPoint = true;
142147
}
143148
}
144149

145-
void AddInstrumentationPointToCollectionFromEnvironment(xstring_t text)
150+
bool TryAddInstrumentationPointToCollectionFromEnvironment(xstring_t text)
146151
{
147152
auto segments = Strings::Split(text, _X("::"));
148153
if (segments.size() != 3)
149154
{
150155
LogWarn(text, L" is not a valid method descriptor. It must be in the format 'assembly::class::method'");
151-
return;
156+
return false;
152157
}
158+
153159
LogInfo(L"Serverless mode detected. Assembly: ", segments[0], L" Class: ", segments[1], L" Method: ", segments[2]);
154160

155161
InstrumentationPointPtr instrumentationPoint(new InstrumentationPoint());
@@ -167,6 +173,8 @@ namespace NewRelic { namespace Profiler { namespace Configuration
167173

168174
(*_instrumentationPointsMap)[instrumentationPoint->GetMatchKey()].insert(instrumentationPoint);
169175
_instrumentationPointsSet->insert(instrumentationPoint);
176+
177+
return true;
170178
}
171179

172180
private:

src/Agent/NewRelic/Profiler/ConfigurationTest/InstrumentationConfigurationTest.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration { namespace Te
956956
xmlSet->emplace(L"filename", L"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
957957

958958
InstrumentationConfiguration instrumentation(xmlSet, nullptr);
959-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::MyMethod"));
959+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::MyMethod"));
960960

961961
auto instrumentationPoint = instrumentation.TryGetInstrumentationPoint(std::make_shared<MethodRewriter::Test::MockFunction>());
962962
Assert::IsFalse(instrumentationPoint == nullptr);
@@ -968,21 +968,21 @@ namespace NewRelic { namespace Profiler { namespace Configuration { namespace Te
968968
xmlSet->emplace(L"filename", L"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
969969

970970
InstrumentationConfiguration instrumentation(xmlSet, nullptr);
971-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::"));
972-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::WrongMethod"));
973-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyMethod"));
974-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyNamespace.MyClass:MyMethod"));
975-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyMethod"));
976-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X(":::MyMethod"));
977-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("::::::MyMethod"));
978-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X(":::MyMethod::"));
979-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly:MyNamespace.MyClass:MyMethod"));
980-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly/MyNamespace.MyClass/MyMethod"));
981-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly_MyNamespace.MyClass_MyMethod"));
982-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly MyNamespace.MyClass MyMethod"));
983-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X(" MyAssembly::MyNamespace.MyClass:MyMethod"));
984-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::MyMethod"));
985-
instrumentation.AddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace .MyClass:: MyMethod"));
971+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::"));
972+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::WrongMethod"));
973+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyMethod"));
974+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyNamespace.MyClass:MyMethod"));
975+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyMethod"));
976+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X(":::MyMethod"));
977+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("::::::MyMethod"));
978+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X(":::MyMethod::"));
979+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly:MyNamespace.MyClass:MyMethod"));
980+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly/MyNamespace.MyClass/MyMethod"));
981+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly_MyNamespace.MyClass_MyMethod"));
982+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly MyNamespace.MyClass MyMethod"));
983+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X(" MyAssembly::MyNamespace.MyClass:MyMethod"));
984+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace.MyClass::MyMethod"));
985+
instrumentation.TryAddInstrumentationPointToCollectionFromEnvironment(_X("MyAssembly::MyNamespace .MyClass:: MyMethod"));
986986

987987
auto instrumentationPoint = instrumentation.TryGetInstrumentationPoint(std::make_shared<MethodRewriter::Test::MockFunction>());
988988
Assert::IsFalse(instrumentationPoint == nullptr);

0 commit comments

Comments
 (0)