@@ -175,6 +175,23 @@ func TestExtensionStartInvokeLambdaRequestId(t *testing.T) {
175175 assert .Equal (t , "test-request-id-12345" , headers .Get ("lambda-runtime-aws-request-id" ))
176176}
177177
178+ func TestExtensionStartInvokeLambdaRequestIdError (t * testing.T ) {
179+ headers := http.Header {}
180+ capturingClient := capturingClient {hdr : headers }
181+
182+ em := & ExtensionManager {
183+ startInvocationUrl : startInvocationUrl ,
184+ httpClient : capturingClient ,
185+ }
186+
187+ logOutput := captureLog (func () { em .SendStartInvocationRequest (context .TODO (), []byte {}) })
188+ err := em .Flush ()
189+ assert .Nil (t , err )
190+ assert .Contains (t , logOutput , "missing lambda Context. Unable to set lambda-runtime-aws-request-id header" )
191+ lines := strings .Split (strings .TrimSpace (logOutput ), "\n " )
192+ assert .Equal (t , 1 , len (lines ))
193+ }
194+
178195func TestExtensionStartInvokeWithTraceContext (t * testing.T ) {
179196 headers := http.Header {}
180197 headers .Set (string (DdTraceId ), mockTraceId )
@@ -227,8 +244,9 @@ func TestExtensionEndInvocation(t *testing.T) {
227244 endInvocationUrl : endInvocationUrl ,
228245 httpClient : & ClientSuccessEndInvoke {},
229246 }
247+ ctx := lambdacontext .NewContext (context .TODO (), & lambdacontext.LambdaContext {})
230248 span := tracer .StartSpan ("aws.lambda" )
231- logOutput := captureLog (func () { em .SendEndInvocationRequest (context . TODO () , span , ddtrace.FinishConfig {}) })
249+ logOutput := captureLog (func () { em .SendEndInvocationRequest (ctx , span , ddtrace.FinishConfig {}) })
232250 span .Finish ()
233251 // Expected because the noopSpanContext doesn't have the SamplingPriority() and we cannot use the mock for the agent
234252 assert .Contains (t , logOutput , "could not get sampling priority from getSamplingPriority()" )
@@ -260,6 +278,27 @@ func TestExtensionEndInvokeLambdaRequestId(t *testing.T) {
260278 assert .Equal (t , "test-request-id-12345" , headers .Get ("lambda-runtime-aws-request-id" ))
261279}
262280
281+ func TestExtensionEndInvokeLambdaRequestIdError (t * testing.T ) {
282+ headers := http.Header {}
283+ capturingClient := capturingClient {hdr : headers }
284+ ctx := context .WithValue (context .TODO (), DdSamplingPriority , mockSamplingPriority )
285+ ctx = context .WithValue (ctx , DdTraceId , mockTraceId )
286+ em := & ExtensionManager {
287+ startInvocationUrl : startInvocationUrl ,
288+ httpClient : capturingClient ,
289+ }
290+
291+ span := tracer .StartSpan ("aws.lambda" )
292+ logOutput := captureLog (func () { em .SendEndInvocationRequest (ctx , span , ddtrace.FinishConfig {}) })
293+ span .Finish ()
294+
295+ err := em .Flush ()
296+ assert .Nil (t , err )
297+ assert .Contains (t , logOutput , "missing lambda Context. Unable to set lambda-runtime-aws-request-id header" )
298+ lines := strings .Split (strings .TrimSpace (logOutput ), "\n " )
299+ assert .Equal (t , 1 , len (lines ))
300+ }
301+
263302func TestExtensionEndInvocationError (t * testing.T ) {
264303 em := & ExtensionManager {
265304 endInvocationUrl : endInvocationUrl ,
0 commit comments