Skip to content

Commit 85a92b9

Browse files
refactoring
1 parent 21040c0 commit 85a92b9

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/HandlerWrapperSetHandlerIntegration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public object OnDelegateBegin<TArg1>(object sender, ref TArg1 arg)
7171
LambdaCommon.Log("DelegateWrapper Running OnDelegateBegin");
7272

7373
Scope scope;
74-
object state = null;
74+
object requestid = null;
7575
var proxyInstance = arg.DuckCast<IInvocationRequest>();
7676
if (proxyInstance == null)
7777
{
@@ -82,11 +82,11 @@ public object OnDelegateBegin<TArg1>(object sender, ref TArg1 arg)
8282
{
8383
var jsonString = ConvertPayloadStream(proxyInstance.InputStream);
8484
scope = LambdaCommon.SendStartInvocation(new LambdaRequestBuilder(), jsonString, proxyInstance.LambdaContext);
85-
state = proxyInstance.LambdaContext?.AwsRequestId;
85+
requestid = proxyInstance.LambdaContext?.AwsRequestId;
8686
}
8787

8888
LambdaCommon.Log("DelegateWrapper FINISHED Running OnDelegateBegin");
89-
return new CallTargetState(scope, state);
89+
return new CallTargetState(scope, requestid);
9090
}
9191

9292
public void OnException(object sender, Exception ex)

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)