Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Instrumentation.AWSLambda] Incoming FaaS Span attributes: detect and set attribute for cold start #2037

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class AWSLambdaWrapper

private static readonly ActivitySource AWSLambdaActivitySource = new(ActivitySourceName, typeof(AWSLambdaWrapper).Assembly.GetPackageVersion());

private static bool isColdStart = true;

/// <summary>
/// Gets or sets a value indicating whether AWS X-Ray propagation should be ignored. Default value is false.
/// </summary>
Expand Down Expand Up @@ -160,7 +162,14 @@ public static Task<TResult> TraceAsync<TInput, TResult>(
}
}

var functionTags = AWSLambdaUtils.GetFunctionTags(input, context);
// No parallel invocation of the same lambda handler.
bool faasColdStart = isColdStart;
if (faasColdStart)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if can be removed, it's fine to unconditionally set it to false here. Then we also might not need the local variable if you change it after calculating functionTags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do it. I removed the local variable and moved setting of the internal one after the calculation of functionTags.

{
isColdStart = false;
}

var functionTags = AWSLambdaUtils.GetFunctionTags(input, context, faasColdStart);
var httpTags = AWSLambdaHttpUtils.GetHttpTags(input);

// We assume that functionTags and httpTags have no intersection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ internal static class AWSLambdaSemanticConventions
public const string AttributeFaasName = "faas.name";
public const string AttributeFaasVersion = "faas.version";
public const string AttributeFaasTrigger = "faas.trigger";
public const string AttributeFaasColdStart = "faas.coldstart";
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ internal static string GetCloudProvider()
return Environment.GetEnvironmentVariable(FunctionVersion);
}

internal static IEnumerable<KeyValuePair<string, object>> GetFunctionTags<TInput>(TInput input, ILambdaContext context)
internal static IEnumerable<KeyValuePair<string, object>> GetFunctionTags<TInput>(TInput input, ILambdaContext context, bool isColdStart)
{
var tags = new List<KeyValuePair<string, object>>
{
new(AWSLambdaSemanticConventions.AttributeFaasTrigger, GetFaasTrigger(input)),
new(AWSLambdaSemanticConventions.AttributeFaasColdStart, isColdStart),
};

var functionName = GetFunctionName(context);
Expand Down
Loading