-
Notifications
You must be signed in to change notification settings - Fork 357
Implement AWS Lambda detector #3411
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
Open
AzharH
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
AzharH:feature/implement-aws-lambda-detector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−0
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c8bf07
implement AWS Lambda detector
AzharH a00874c
update changelog
AzharH 840ee3b
Update CHANGELOG for AWS Lambda detector implementation
AzharH 32b8659
Merge branch 'main' into feature/implement-aws-lambda-detector
AzharH 20d0385
refactor test
AzharH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaResourceBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaResourceBuilderExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!)); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.