14
14
#include " ../RapidXML/rapidxml.hpp"
15
15
#include " ../Common/AssemblyVersion.h"
16
16
#include " IgnoreInstrumentation.h"
17
+ #include " ../Configuration/Strings.h"
18
+ #include " ../Logging/DefaultFileLogLocation.h"
17
19
18
20
namespace NewRelic { namespace Profiler { namespace Configuration
19
21
{
@@ -24,9 +26,11 @@ namespace NewRelic { namespace Profiler { namespace Configuration
24
26
class InstrumentationConfiguration
25
27
{
26
28
public:
27
- InstrumentationConfiguration (InstrumentationXmlSetPtr instrumentationXmls, IgnoreInstrumentationListPtr ignoreList) :
29
+ InstrumentationConfiguration (InstrumentationXmlSetPtr instrumentationXmls, IgnoreInstrumentationListPtr ignoreList, std::shared_ptr<NewRelic::Profiler::Logger::IFileDestinationSystemCalls> systemCalls = nullptr ) :
28
30
_instrumentationPointsSet (new InstrumentationPointSet())
29
31
, _ignoreList(ignoreList)
32
+ , _systemCalls(systemCalls)
33
+ , _foundServerlessInstrumentationPoint(false )
30
34
{
31
35
// pull instrumentation points from every xml string
32
36
for (auto instrumentationXml : *instrumentationXmls)
@@ -57,6 +61,8 @@ namespace NewRelic { namespace Profiler { namespace Configuration
57
61
InstrumentationConfiguration (InstrumentationPointSetPtr instrumentationPoints, IgnoreInstrumentationListPtr ignoreList) :
58
62
_instrumentationPointsSet (new InstrumentationPointSet())
59
63
, _ignoreList(ignoreList)
64
+ , _systemCalls(nullptr )
65
+ , _foundServerlessInstrumentationPoint(false )
60
66
{
61
67
for (auto instrumentationPoint : *instrumentationPoints)
62
68
{
@@ -113,8 +119,47 @@ namespace NewRelic { namespace Profiler { namespace Configuration
113
119
return nullptr ;
114
120
}
115
121
116
- private:
122
+ void CheckForEnvironmentInstrumentationPoint (void )
123
+ {
124
+ if (_foundServerlessInstrumentationPoint || (_systemCalls == nullptr ))
125
+ {
126
+ return ;
127
+ }
128
+ auto lambdaInstPoint = _systemCalls->TryGetEnvironmentVariable (_X (" AWS_LAMBDA_FUNCTION_NAME" ));
129
+ if (lambdaInstPoint != nullptr )
130
+ {
131
+ AddInstrumentationPointToCollectionFromEnvironment (*lambdaInstPoint);
132
+ _foundServerlessInstrumentationPoint = true ;
133
+ }
134
+ }
135
+
136
+ void AddInstrumentationPointToCollectionFromEnvironment (xstring_t text)
137
+ {
138
+ auto segments = Strings::Split (text, _X (" ::" ));
139
+ if (segments.size () != 3 )
140
+ {
141
+ LogWarn (text, L" is not a valid method descriptor. It must be in the format 'assembly::class::method'" );
142
+ return ;
143
+ }
144
+ LogInfo (L" Serverless mode detected. Assembly: " , segments[0 ], L" Class: " , segments[1 ], L" Method: " , segments[2 ]);
117
145
146
+ InstrumentationPointPtr instrumentationPoint (new InstrumentationPoint ());
147
+ // Note that this must exactly match the wrapper name in the managed Agent
148
+ instrumentationPoint->TracerFactoryName = _X (" NewRelic.Providers.Wrapper.AwsLambda.HandlerMethod" );
149
+ instrumentationPoint->MetricName = _X (" " );
150
+ instrumentationPoint->MetricType = _X (" " );
151
+ instrumentationPoint->AssemblyName = segments[0 ];
152
+ instrumentationPoint->MinVersion = nullptr ;
153
+ instrumentationPoint->MaxVersion = nullptr ;
154
+ instrumentationPoint->ClassName = segments[1 ];
155
+ instrumentationPoint->MethodName = segments[2 ];
156
+ instrumentationPoint->Parameters = nullptr ;
157
+
158
+ (*_instrumentationPointsMap)[instrumentationPoint->GetMatchKey ()].insert (instrumentationPoint);
159
+ _instrumentationPointsSet->insert (instrumentationPoint);
160
+ }
161
+
162
+ private:
118
163
static bool InstrumentationXmlIsDeprecated (xstring_t instrumentationXmlFilePath)
119
164
{
120
165
bool returnValue = false ;
@@ -140,6 +185,7 @@ namespace NewRelic { namespace Profiler { namespace Configuration
140
185
const xstring_t & methodName,
141
186
const xstring_t & parameters) const
142
187
{
188
+
143
189
auto matchKey = InstrumentationPoint::GetMatchKey (assemblyName, className, methodName, parameters);
144
190
auto matchInstrumentation = TryGetInstrumentationPoints (matchKey);
145
191
@@ -457,6 +503,8 @@ namespace NewRelic { namespace Profiler { namespace Configuration
457
503
InstrumentationPointSetPtr _instrumentationPointsSet;
458
504
uint16_t _invalidFileCount = 0 ;
459
505
IgnoreInstrumentationListPtr _ignoreList;
506
+ std::shared_ptr<NewRelic::Profiler::Logger::IFileDestinationSystemCalls> _systemCalls;
507
+ bool _foundServerlessInstrumentationPoint;
460
508
};
461
509
typedef std::shared_ptr<InstrumentationConfiguration> InstrumentationConfigurationPtr;
462
510
}}}
0 commit comments