You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the intended target for this package is lambda functions, minimizing the impact on the size of the final binary and reducing dependencies should be a high priority.
Adding datadog-lambda-go as a dependency can significantly increase the size of the final binary and brings in a large amount of transitive dependencies.
Before adding dependency:
➜ du -h bin/linux/arm64/*
8.7M bin/linux/arm64/xxx
I believe the issue here is that this library disables go's dead code elimination which can significantly increase binary sizes. This is because one of this library's transitive dependencies uses reflect.Value.MethodByName which disables dead code elimination (see this blog).
The import chain is:
the init() function in golang.org/x/net/trace uses html/template which disables dead code elimination because it calls reflect.Value.MethodByName
golang.org/x/net/trace is imported by google.golang.org/grpc
google.golang.org/grpc is imported by github.com/aws/aws-xray-sdk-go/v2/xray
github.com/aws/aws-xray-sdk-go/v2/xray is imported by github.com/DataDog/datadog-lambda-go/internal/trace
In short the problem is with the import here. It looks like only a small number of functionality is needed. Consider reimplementing those functions.
Alternatively, users can opt out of grpc tracing (if their usecase allows) by building with go build -tags grpcnotrace per this comment
Activity
krzysiek1507 commentedon Feb 28, 2025
Hey! Updating this package to use
github.com/aws/aws-xray-sdk-gov2 should reduce the size I guess? v2 got rid of AWS SDK Go v1.krzysiek1507 commentedon Feb 28, 2025
cc @nhulston
krzysiek1507 commentedon Feb 28, 2025
I opened a PR with the update #190
seanamos commentedon Mar 14, 2025
After upgrading to v1.22.0, we saw a reduction of 4mb. So 8.7M without the dependency, 28M with it, down from 32M.
Trending in the right direction.
debugmiller commentedon May 2, 2025
I believe the issue here is that this library disables go's dead code elimination which can significantly increase binary sizes. This is because one of this library's transitive dependencies uses
reflect.Value.MethodByNamewhich disables dead code elimination (see this blog).The import chain is:
golang.org/x/net/traceuseshtml/templatewhich disables dead code elimination because it callsreflect.Value.MethodByNamegolang.org/x/net/traceis imported bygoogle.golang.org/grpcgoogle.golang.org/grpcis imported bygithub.com/aws/aws-xray-sdk-go/v2/xraygithub.com/aws/aws-xray-sdk-go/v2/xrayis imported bygithub.com/DataDog/datadog-lambda-go/internal/traceIn short the problem is with the import here. It looks like only a small number of functionality is needed. Consider reimplementing those functions.
Alternatively, users can opt out of grpc tracing (if their usecase allows) by building with
go build -tags grpcnotraceper this commentseanamos commentedon Mar 12, 2026
I just wanted to add this before this repo is closed.
Even with
go build -tags lambda.norpc,grpcnotraceand fully functioning DCE (confirmed with https://github.com/aarzilli/whydeadcode), the base cost of this package is 17mb.