Skip to content

Commit c63bad5

Browse files
authored
Fix: Lambda Topology Issue (#173)
1 parent c04b182 commit c63bad5

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/AwsAttributeKeys.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal sealed class AwsAttributeKeys
1111
internal static readonly string AttributeAWSLocalOperation = "aws.local.operation";
1212
internal static readonly string AttributeAWSRemoteDBUser = "aws.remote.db.user";
1313
internal static readonly string AttributeAWSRemoteService = "aws.remote.service";
14+
internal static readonly string AttributeAWSRemoteEnvironment = "aws.remote.environment";
1415
internal static readonly string AttributeAWSRemoteOperation = "aws.remote.operation";
1516

1617
internal static readonly string AttributeAWSRemoteResourceIdentifier = "aws.remote.resource.identifier";
@@ -48,6 +49,7 @@ internal sealed class AwsAttributeKeys
4849
internal static readonly string AttributeAWSDynamoTableName = "aws.table_name";
4950
internal static readonly string AttributeAWSSQSQueueUrl = "aws.queue_url";
5051

52+
internal static readonly string AttributeAWSLambdaFunctionName = "aws.lambda.function.name";
5153
internal static readonly string AttributeAWSLambdaResourceMappingId = "aws.lambda.resource_mapping.id";
5254
internal static readonly string AttributeAWSS3Bucket = "aws.s3.bucket";
5355
internal static readonly string AttributeAWSSecretsManagerSecretArn = "aws.secretsmanager.secret.arn";

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/AwsMetricAttributeGenerator.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ private static void SetRemoteResourceTypeAndIdentifier(Activity span, ActivityTa
410410
remoteResourceType = NormalizedKinesisServiceName + "::Stream";
411411
remoteResourceIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSKinesisStreamName));
412412
}
413+
else if (IsKeyPresent(span, AttributeAWSLambdaFunctionName))
414+
{
415+
if (GetRemoteOperation(span, AttributeRpcMethod) == "Invoke")
416+
{
417+
attributes[AttributeAWSRemoteService] = GetLambdaFunctionNameFromArn(EscapeDelimiters((string?)span.GetTagItem(AttributeAWSLambdaFunctionName)));
418+
419+
string lambdaRemoteEnv = Environment.GetEnvironmentVariable("LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT") ?? "default";
420+
attributes.Add(AttributeAWSRemoteEnvironment, $"lambda:{lambdaRemoteEnv}");
421+
}
422+
else
423+
{
424+
remoteResourceType = NormalizedLambdaServiceName + "::Function";
425+
remoteResourceIdentifier = GetLambdaFunctionNameFromArn(EscapeDelimiters((string?)span.GetTagItem(AttributeAWSLambdaFunctionName)));
426+
cloudformationPrimaryIdentifier = EscapeDelimiters((string?)span.GetTagItem(AttributeAWSLambdaFunctionName));
427+
}
428+
}
413429
else if (IsKeyPresent(span, AttributeAWSLambdaResourceMappingId))
414430
{
415431
remoteResourceType = NormalizedLambdaServiceName + "::EventSourceMapping";
@@ -505,6 +521,22 @@ private static void SetRemoteResourceTypeAndIdentifier(Activity span, ActivityTa
505521
}
506522
}
507523

524+
private static string? GetLambdaFunctionNameFromArn(string? stringArn)
525+
{
526+
if (stringArn == null)
527+
{
528+
return null;
529+
}
530+
531+
if (stringArn.StartsWith("arn:aws:lambda:", StringComparison.Ordinal))
532+
{
533+
string[] parts = stringArn.Split(':');
534+
return parts.Length > 0 ? parts[parts.Length - 1] : null;
535+
}
536+
537+
return stringArn;
538+
}
539+
508540
private static void SetRemoteDbUser(Activity span, ActivityTagsCollection attributes)
509541
{
510542
if (IsDBSpan(span) && IsKeyPresent(span, AttributeDBUser))

src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSSemanticConventions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal static class AWSSemanticConventions
1515
public const string AttributeAWSSQSQueueName = "aws.sqs.queue_name";
1616
public const string AttributeAWSS3BucketName = "aws.s3.bucket";
1717
public const string AttributeAWSKinesisStreamName = "aws.kinesis.stream_name";
18+
public const string AttributeAWSLambdaFunctionName = "aws.lambda.function.name";
1819
public const string AttributeAWSLambdaResourceMappingId = "aws.lambda.resource_mapping.id";
1920
public const string AttributeAWSSecretsManagerSecretArn = "aws.secretsmanager.secret.arn";
2021
public const string AttributeAWSSNSTopicArn = "aws.sns.topic.arn";

src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSServiceHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class AWSServiceHelper
1313
{ AWSServiceType.SQSService, new List<string> { "QueueUrl", "QueueName" } },
1414
{ AWSServiceType.S3Service, new List<string> { "BucketName" } },
1515
{ AWSServiceType.KinesisService, new List<string> { "StreamName" } },
16-
{ AWSServiceType.LambdaService, new List<string> { "UUID" } },
16+
{ AWSServiceType.LambdaService, new List<string> { "UUID", "FunctionName" } },
1717
{ AWSServiceType.SecretsManagerService, new List<string> { "SecretId" } },
1818
{ AWSServiceType.SNSService, new List<string> { "TopicArn" } },
1919
{ AWSServiceType.StepFunctionsService, new List<string> { "ActivityArn", "StateMachineArn" } },
@@ -42,6 +42,7 @@ internal class AWSServiceHelper
4242
{ "SecretId", AWSSemanticConventions.AttributeAWSSecretsManagerSecretArn },
4343
{ "ActivityArn", AWSSemanticConventions.AttributeAWSStepFunctionsActivityArn },
4444
{ "StateMachineArn", AWSSemanticConventions.AttributeAWSStepFunctionsStateMachineArn },
45+
{ "FunctionName", AWSSemanticConventions.AttributeAWSLambdaFunctionName },
4546
{ "UUID", AWSSemanticConventions.AttributeAWSLambdaResourceMappingId },
4647
{ "ModelId", AWSSemanticConventions.AttributeGenAiModelId },
4748
{ "GuardrailId", AWSSemanticConventions.AttributeAWSBedrockGuardrailId },

0 commit comments

Comments
 (0)