From f6bd2bbbde4606dfc0a3583fe15dc45e31835f7a Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 14 Aug 2025 10:47:36 -0400 Subject: [PATCH 1/9] updated lambda detector to use bytes instead of MB --- detectors/aws/lambda/detector.go | 3 ++- detectors/aws/lambda/detector_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/detectors/aws/lambda/detector.go b/detectors/aws/lambda/detector.go index ac5ae4c0960..70b62746d01 100644 --- a/detectors/aws/lambda/detector.go +++ b/detectors/aws/lambda/detector.go @@ -23,6 +23,7 @@ const ( lambdaFunctionVersionEnvVar = "AWS_LAMBDA_FUNCTION_VERSION" lambdaLogStreamNameEnvVar = "AWS_LAMBDA_LOG_STREAM_NAME" lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" + bytesInMegabyte = 1048576 ) var ( @@ -65,7 +66,7 @@ func (*resourceDetector) Detect(context.Context) (*resource.Resource, error) { maxMemoryStr := os.Getenv(lambdaMemoryLimitEnvVar) maxMemory, err := strconv.Atoi(maxMemoryStr) if err == nil { - attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory)) + attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory*bytesInMegabyte)) } return resource.NewWithAttributes(semconv.SchemaURL, attrs...), nil diff --git a/detectors/aws/lambda/detector_test.go b/detectors/aws/lambda/detector_test.go index c4a093195f3..5aaf4fc4b99 100644 --- a/detectors/aws/lambda/detector_test.go +++ b/detectors/aws/lambda/detector_test.go @@ -28,7 +28,7 @@ func TestDetectSuccess(t *testing.T) { semconv.FaaSName("testFunction"), semconv.FaaSVersion("$LATEST"), semconv.FaaSInstance("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - semconv.FaaSMaxMemory(128), + semconv.FaaSMaxMemory(128 * bytesInMegabyte), } expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...) detector := resourceDetector{} From dd3bd71fdf040528876cc3287f4ad07e6a7a29c4 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 14 Aug 2025 10:53:05 -0400 Subject: [PATCH 2/9] updated lambda detector to use bytes instead of MB --- detectors/aws/lambda/detector.go | 4 ++-- detectors/aws/lambda/detector_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/detectors/aws/lambda/detector.go b/detectors/aws/lambda/detector.go index 70b62746d01..6e78dc87f15 100644 --- a/detectors/aws/lambda/detector.go +++ b/detectors/aws/lambda/detector.go @@ -23,7 +23,7 @@ const ( lambdaFunctionVersionEnvVar = "AWS_LAMBDA_FUNCTION_VERSION" lambdaLogStreamNameEnvVar = "AWS_LAMBDA_LOG_STREAM_NAME" lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" - bytesInMegabyte = 1048576 + MiB = 1 << 20 ) var ( @@ -66,7 +66,7 @@ func (*resourceDetector) Detect(context.Context) (*resource.Resource, error) { maxMemoryStr := os.Getenv(lambdaMemoryLimitEnvVar) maxMemory, err := strconv.Atoi(maxMemoryStr) if err == nil { - attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory*bytesInMegabyte)) + attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory*MiB)) } return resource.NewWithAttributes(semconv.SchemaURL, attrs...), nil diff --git a/detectors/aws/lambda/detector_test.go b/detectors/aws/lambda/detector_test.go index 5aaf4fc4b99..bf667f7c65f 100644 --- a/detectors/aws/lambda/detector_test.go +++ b/detectors/aws/lambda/detector_test.go @@ -28,7 +28,7 @@ func TestDetectSuccess(t *testing.T) { semconv.FaaSName("testFunction"), semconv.FaaSVersion("$LATEST"), semconv.FaaSInstance("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - semconv.FaaSMaxMemory(128 * bytesInMegabyte), + semconv.FaaSMaxMemory(128 * MiB), } expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...) detector := resourceDetector{} From 8c280552801995cfa193f92810a82302d474d635 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 14 Aug 2025 11:05:33 -0400 Subject: [PATCH 3/9] updated lambda instrumentation tests --- .../github.com/aws/aws-lambda-go/otellambda/lambda_test.go | 2 ++ .../aws/aws-lambda-go/otellambda/lambdatest_test.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go index acca209639a..9ef975867d5 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go @@ -18,6 +18,8 @@ import ( "github.com/stretchr/testify/assert" ) +const MiB = 1 << 20 + var ( mockLambdaContext = lambdacontext.LambdaContext{ AwsRequestID: "123", diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go index d34d6131596..239898ff4c3 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go @@ -142,7 +142,7 @@ var ( attribute.String("faas.name", "testFunction"), attribute.String("faas.version", "$LATEST"), attribute.String("faas.instance", "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - attribute.Int("faas.max_memory", 128)), + attribute.Int("faas.max_memory", 128*lambdadetector.MiB)), InstrumentationScope: instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda", Version: otellambda.Version(), @@ -337,7 +337,7 @@ var ( attribute.String("faas.name", "testFunction"), attribute.String("faas.version", "$LATEST"), attribute.String("faas.instance", "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - attribute.Int("faas.max_memory", 128)), + attribute.Int("faas.max_memory", 128*lambdadetector.MiB)), InstrumentationScope: instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda", Version: otellambda.Version(), From 466cef80200a1ae0865ce7d2530884dcbc8678ac Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 14 Aug 2025 11:11:49 -0400 Subject: [PATCH 4/9] add chlog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fecb966b82..d13dd3897b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - Change the default span name to be `GET /path` so it complies with the HTTP semantic conventions in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`. (#7551) +- Change the faas.max_memory unit to be bytes instead of MB to comply with the semantic conventions in `"go.opentelemetry.io/contrib/detectors/aws/lambda`. (#7745) ### Deprecated From ab83bd05acd26477a6fcf871194308c4c4ebe84d Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Thu, 14 Aug 2025 11:13:53 -0400 Subject: [PATCH 5/9] remove unnecessary const --- .../github.com/aws/aws-lambda-go/otellambda/lambda_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go index 9ef975867d5..acca209639a 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda_test.go @@ -18,8 +18,6 @@ import ( "github.com/stretchr/testify/assert" ) -const MiB = 1 << 20 - var ( mockLambdaContext = lambdacontext.LambdaContext{ AwsRequestID: "123", From 145c85c7f140f4ca385da8e5d296c63976e36109 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 20 Aug 2025 15:10:15 -0400 Subject: [PATCH 6/9] unexported miB --- detectors/aws/lambda/detector.go | 6 +++--- detectors/aws/lambda/detector_test.go | 2 +- .../aws/aws-lambda-go/otellambda/lambdatest_test.go | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/detectors/aws/lambda/detector.go b/detectors/aws/lambda/detector.go index 6e78dc87f15..65f9ff48ba9 100644 --- a/detectors/aws/lambda/detector.go +++ b/detectors/aws/lambda/detector.go @@ -22,8 +22,8 @@ const ( awsRegionEnvVar = "AWS_REGION" lambdaFunctionVersionEnvVar = "AWS_LAMBDA_FUNCTION_VERSION" lambdaLogStreamNameEnvVar = "AWS_LAMBDA_LOG_STREAM_NAME" - lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" - MiB = 1 << 20 + lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" + miB = 1 << 20 ) var ( @@ -66,7 +66,7 @@ func (*resourceDetector) Detect(context.Context) (*resource.Resource, error) { maxMemoryStr := os.Getenv(lambdaMemoryLimitEnvVar) maxMemory, err := strconv.Atoi(maxMemoryStr) if err == nil { - attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory*MiB)) + attrs = append(attrs, semconv.FaaSMaxMemory(maxMemory*miB)) } return resource.NewWithAttributes(semconv.SchemaURL, attrs...), nil diff --git a/detectors/aws/lambda/detector_test.go b/detectors/aws/lambda/detector_test.go index bf667f7c65f..43f7720a396 100644 --- a/detectors/aws/lambda/detector_test.go +++ b/detectors/aws/lambda/detector_test.go @@ -28,7 +28,7 @@ func TestDetectSuccess(t *testing.T) { semconv.FaaSName("testFunction"), semconv.FaaSVersion("$LATEST"), semconv.FaaSInstance("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - semconv.FaaSMaxMemory(128 * MiB), + semconv.FaaSMaxMemory(128 * miB), } expectedResource := resource.NewWithAttributes(semconv.SchemaURL, attributes...) detector := resourceDetector{} diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go index 239898ff4c3..6d6f4e7b548 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go @@ -32,6 +32,8 @@ import ( "go.opentelemetry.io/contrib/propagators/aws/xray" ) +const miB = 1 << 20 + var errorLogger = log.New(log.Writer(), "OTel Lambda Test Error: ", 0) type mockIDGenerator struct { @@ -142,7 +144,7 @@ var ( attribute.String("faas.name", "testFunction"), attribute.String("faas.version", "$LATEST"), attribute.String("faas.instance", "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - attribute.Int("faas.max_memory", 128*lambdadetector.MiB)), + attribute.Int("faas.max_memory", 128*miB)), InstrumentationScope: instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda", Version: otellambda.Version(), @@ -337,7 +339,7 @@ var ( attribute.String("faas.name", "testFunction"), attribute.String("faas.version", "$LATEST"), attribute.String("faas.instance", "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"), - attribute.Int("faas.max_memory", 128*lambdadetector.MiB)), + attribute.Int("faas.max_memory", 128*miB)), InstrumentationScope: instrumentation.Scope{ Name: "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda", Version: otellambda.Version(), From 034a9651b2c96bb9963be21c21c9fe44f802ce2b Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 20 Aug 2025 15:19:12 -0400 Subject: [PATCH 7/9] lint update --- detectors/aws/lambda/detector.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detectors/aws/lambda/detector.go b/detectors/aws/lambda/detector.go index 65f9ff48ba9..eeffded7dc9 100644 --- a/detectors/aws/lambda/detector.go +++ b/detectors/aws/lambda/detector.go @@ -22,8 +22,8 @@ const ( awsRegionEnvVar = "AWS_REGION" lambdaFunctionVersionEnvVar = "AWS_LAMBDA_FUNCTION_VERSION" lambdaLogStreamNameEnvVar = "AWS_LAMBDA_LOG_STREAM_NAME" - lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" - miB = 1 << 20 + lambdaMemoryLimitEnvVar = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" + miB = 1 << 20 ) var ( From 6d997032680f278eebe66f6c2ca21c93c62ec802 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Tue, 26 Aug 2025 03:58:06 -0400 Subject: [PATCH 8/9] fixed test using lambda detector --- .../aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go index dab301b9f22..6e8899001b2 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/xrayconfig_test.go @@ -23,6 +23,8 @@ import ( "go.opentelemetry.io/contrib/propagators/aws/xray" ) +const miB = 1 << 20 + func TestEventToCarrier(t *testing.T) { t.Setenv("_X_AMZN_TRACE_ID", "traceID") carrier := xrayEventToCarrier([]byte{}) @@ -107,7 +109,7 @@ var ( {Key: "cloud.provider", Value: &v1common.AnyValue{Value: &v1common.AnyValue_StringValue{StringValue: "aws"}}}, {Key: "cloud.region", Value: &v1common.AnyValue{Value: &v1common.AnyValue_StringValue{StringValue: "us-texas-1"}}}, {Key: "faas.instance", Value: &v1common.AnyValue{Value: &v1common.AnyValue_StringValue{StringValue: "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"}}}, - {Key: "faas.max_memory", Value: &v1common.AnyValue{Value: &v1common.AnyValue_IntValue{IntValue: 128}}}, + {Key: "faas.max_memory", Value: &v1common.AnyValue{Value: &v1common.AnyValue_IntValue{IntValue: 128 * miB}}}, {Key: "faas.name", Value: &v1common.AnyValue{Value: &v1common.AnyValue_StringValue{StringValue: "testFunction"}}}, {Key: "faas.version", Value: &v1common.AnyValue{Value: &v1common.AnyValue_StringValue{StringValue: "$LATEST"}}}, }, From 9a1890a8b7dfe18c8673906d712de3943ff8f8d7 Mon Sep 17 00:00:00 2001 From: Alex Kats Date: Wed, 27 Aug 2025 21:08:46 -0400 Subject: [PATCH 9/9] chlog update --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bec7300b2f5..a93c8e9a26d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The next release will require at least [Go 1.24]. ### Changed - Change the default span name to be `GET /path` so it complies with the HTTP semantic conventions in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux`. (#7551) -- Change the faas.max_memory unit to be bytes instead of MB to comply with the semantic conventions in `"go.opentelemetry.io/contrib/detectors/aws/lambda`. (#7745) +- Change the faas.max_memory unit to be bytes instead of MB to comply with the semantic conventions in `go.opentelemetry.io/contrib/detectors/aws/lambda`. (#7745) - Transform attribute values of `go.opentelemetry.io/otel/attribute.Value` and `go.opentelemetry.io/otel/log.Value` types to appropriate `go.opentelemetry.io/otel/log.Value` type instead of `log.StringValue` in the modules below. (#7660) - `go.opentelemetry.io/contrib/bridges/otellogr` - `go.opentelemetry.io/contrib/bridges/otellogrus`