Skip to content

Reduce size of dependency #187

Open
Open

Description

@seanamos

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

After adding dependency:

➜ du -h bin/linux/arm64/*
 32M    bin/linux/arm64/xxx

Specifications

  • Datadog Go Lambda package version: 1.47.0
  • Go version: 1.23.5

Activity

  1. krzysiek1507 commented on Feb 28, 2025

    @krzysiek1507

    Hey! Updating this package to use github.com/aws/aws-xray-sdk-go v2 should reduce the size I guess? v2 got rid of AWS SDK Go v1.

  2. krzysiek1507 commented on Feb 28, 2025

    @krzysiek1507
  3. krzysiek1507 commented on Feb 28, 2025

    @krzysiek1507

    I opened a PR with the update #190

  4. seanamos commented on Mar 14, 2025

    @seanamos
    Author

    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.

  5. debugmiller commented on May 2, 2025

    @debugmiller

    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

  6. seanamos commented on Mar 12, 2026

    @seanamos
    Author

    I just wanted to add this before this repo is closed.

    Even with go build -tags lambda.norpc,grpcnotrace and fully functioning DCE (confirmed with https://github.com/aarzilli/whydeadcode), the base cost of this package is 17mb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions