Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AWS;
using OpenTelemetry.Instrumentation.AWSLambda.Implementation;
using OpenTelemetry.Internal;
using OpenTelemetry.Resources;

namespace OpenTelemetry.Instrumentation.AWSLambda;

/// <summary>
/// Extension methods to simplify registering of AWS Lambda resource detectors.
/// </summary>
public static class AWSLambdaResourceBuilderExtensions
{
/// <summary>
/// Enables AWS Lambda resource detector.
/// </summary>
/// <param name="builder">The <see cref="ResourceBuilder"/> being configured.</param>
/// <param name="configure">Optional callback action for configuring <see cref="AWSLambdaInstrumentationOptions"/>.</param>
/// <returns>The instance of <see cref="ResourceBuilder"/> being configured.</returns>
public static ResourceBuilder AddAWSLambdaDetector(this ResourceBuilder builder, Action<AWSLambdaInstrumentationOptions>? configure = null)
{
Guard.ThrowIfNull(builder);

var options = new AWSLambdaInstrumentationOptions();
configure?.Invoke(options);

var semanticConventionBuilder = new AWSSemanticConventions(options.SemanticConventionVersion);

return builder.AddDetector(new AWSLambdaResourceDetector(semanticConventionBuilder));
}
}
1 change: 1 addition & 0 deletions src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add support for .NET 10.0.
([#2822](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2822))
* Implement AWS Lambda detector ([#3411](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3411))

## 1.13.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.Resources;
using Xunit;

namespace OpenTelemetry.Instrumentation.AWSLambda.Tests;

public class AWSLambdaResourceBuilderExtensionsTests
{
// Expected Semantic Conventions
private const string AttributeCloudProvider = "cloud.provider";
private const string AttributeCloudRegion = "cloud.region";
private const string AttributeFaasName = "faas.name";
private const string AttributeFaasVersion = "faas.version";
private const string AttributeFaasInstance = "faas.instance";
private const string AttributeFaasMaxMemory = "faas.max_memory";

public AWSLambdaResourceBuilderExtensionsTests()
{
Environment.SetEnvironmentVariable("AWS_REGION", "us-east-1");
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", "testfunction");
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", "latest");
Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "128");
Environment.SetEnvironmentVariable("AWS_LAMBDA_LOG_STREAM_NAME",
"2025/07/21/[$LATEST]7b176c212e954e62adfb9b5451cb5374");
}

[Fact]
public void AssertAttributes()
{
var resourceBuilder = ResourceBuilder.CreateDefault();
resourceBuilder.AddAWSLambdaDetector();

var resource = resourceBuilder.Build();

var resourceAttributes = resource.Attributes
.ToDictionary(x => x.Key, x => x.Value);

Assert.Equal("aws", resourceAttributes[AttributeCloudProvider]);
Assert.Equal("us-east-1", resourceAttributes[AttributeCloudRegion]);
Assert.Equal("testfunction", resourceAttributes[AttributeFaasName]);
Assert.Equal("latest", resourceAttributes[AttributeFaasVersion]);
Assert.Equal("2025/07/21/[$LATEST]7b176c212e954e62adfb9b5451cb5374",
resourceAttributes[AttributeFaasInstance]);
Assert.Equal(134217728L, resourceAttributes[AttributeFaasMaxMemory]);
}

[Fact]
public void AssertArgumentNullException() =>
Assert.Throws<ArgumentNullException>(() => AWSLambdaResourceBuilderExtensions.AddAWSLambdaDetector(null!));
}