-
Notifications
You must be signed in to change notification settings - Fork 360
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
base: main
Are you sure you want to change the base?
Changes from all commits
6c8bf07
a00874c
840ee3b
32b8659
20d0385
b6b3443
f1290a6
c80f940
d2206e2
db9dc0f
1e0764f
1c6d70d
ec22407
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| OpenTelemetry.Instrumentation.AWSLambda.AWSLambdaResourceBuilderExtensions | ||
| static OpenTelemetry.Instrumentation.AWSLambda.AWSLambdaResourceBuilderExtensions.AddAWSLambdaDetector(this OpenTelemetry.Resources.ResourceBuilder! builder) -> OpenTelemetry.Resources.ResourceBuilder! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.AWS; | ||
| using OpenTelemetry.Instrumentation.AWSLambda.Implementation; | ||
| using OpenTelemetry.Internal; | ||
| using OpenTelemetry.Resources; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| 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. Do not call this method while also calling <see cref="TracerProviderBuilderExtensions.AddAWSLambdaConfigurations(TracerProviderBuilder)" /> or <see cref="TracerProviderBuilderExtensions.AddAWSLambdaConfigurations(TracerProviderBuilder, System.Action{AWSLambdaInstrumentationOptions})" />. | ||
| /// </summary> | ||
| /// <param name="builder">The <see cref="ResourceBuilder"/> being configured.</param> | ||
| /// <returns>The instance of <see cref="ResourceBuilder"/> being configured.</returns> | ||
| public static ResourceBuilder AddAWSLambdaDetector(this ResourceBuilder builder) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another comment, whole package relay on the SsmanticVersion property. I think that, it should be honored by this builder also. I would recommend add option class specific only for resource builder. As for all cases, if there is no parameter available it should stick with 1.28.0. Without this, there should be no new stable release. |
||
| { | ||
| Guard.ThrowIfNull(builder); | ||
|
|
||
| var semanticConventionBuilder = new AWSSemanticConventions(); | ||
| return builder.AddDetector(new AWSLambdaResourceDetector(semanticConventionBuilder)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.Resources; | ||
| using Xunit; | ||
|
|
||
| namespace OpenTelemetry.Instrumentation.AWSLambda.Tests; | ||
|
|
||
| public class AWSLambdaResourceBuilderExtensionsTests : IDisposable | ||
| { | ||
| // 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"; | ||
|
|
||
| private readonly IDisposable environmentScope = EnvironmentVariableScope.Create( | ||
| ("AWS_REGION", "us-east-1"), | ||
| ("AWS_LAMBDA_FUNCTION_NAME", "testfunction"), | ||
| ("AWS_LAMBDA_FUNCTION_VERSION", "latest"), | ||
| ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "128"), | ||
| ("AWS_LAMBDA_LOG_STREAM_NAME", "2025/07/21/[$LATEST]7b176c212e954e62adfb9b5451cb5374")); | ||
|
|
||
| public void Dispose() => this.environmentScope.Dispose(); | ||
|
|
||
| [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!)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that, this deserves documentation in the README.