@@ -24,7 +24,7 @@ internal abstract class LambdaCommon
2424 private const string PlaceholderOperationName = "placeholder-operation" ;
2525 private const double ServerlessMaxWaitingFlushTime = 3 ;
2626 private const string LogLevelEnvName = "DD_LOG_LEVEL" ;
27- private const string LambdaRuntimeAwsRequestHeaderId = "lambda-runtime-aws-request-id" ;
27+ private const string LambdaRuntimeAwsRequestIdHeader = "lambda-runtime-aws-request-id" ;
2828
2929 internal static Scope CreatePlaceholderScope ( Tracer tracer , NameValueHeadersCollection headers )
3030 {
@@ -45,7 +45,12 @@ internal static Scope SendStartInvocation(ILambdaExtensionRequest requestBuilder
4545 {
4646 var request = requestBuilder . GetStartInvocationRequest ( ) ;
4747 WriteRequestPayload ( request , data ) ;
48- WriteRequestHeaders ( request , context ) ;
48+ WriteRequestHeaders ( request , context . ClientContext ? . Custom ) ;
49+ if ( context . AwsRequestId != null )
50+ {
51+ request . Headers . Add ( LambdaRuntimeAwsRequestIdHeader , context . AwsRequestId ) ;
52+ }
53+
4954 using var response = ( HttpWebResponse ) request . GetResponse ( ) ;
5055
5156 var headers = response . Headers . Wrap ( ) ;
@@ -121,23 +126,11 @@ private static void WriteRequestPayload(WebRequest request, string data)
121126 dataStream . Close ( ) ;
122127 }
123128
124- private static void WriteRequestHeaders ( WebRequest request , ILambdaContext context )
129+ private static void WriteRequestHeaders ( WebRequest request , IDictionary < string , string > context )
125130 {
126- if ( context != null )
131+ foreach ( var kv in context )
127132 {
128- var clientContext = context . ClientContext ? . Custom ;
129- if ( clientContext != null )
130- {
131- foreach ( var kv in clientContext )
132- {
133- request . Headers . Add ( kv . Key , kv . Value ) ;
134- }
135- }
136-
137- if ( context . AwsRequestId != null )
138- {
139- request . Headers . Add ( LambdaRuntimeAwsRequestHeaderId , context . AwsRequestId ) ;
140- }
133+ request . Headers . Add ( kv . Key , kv . Value ) ;
141134 }
142135 }
143136
0 commit comments