Skip to content
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

APIGW + Lambda sample app #961

Merged
merged 6 commits into from
Dec 3, 2024
Merged

APIGW + Lambda sample app #961

merged 6 commits into from
Dec 3, 2024

Conversation

srprash
Copy link
Contributor

@srprash srprash commented Dec 2, 2024

Description of changes:

  • Adding a sample app to demonstrate the Application Signals Lambda Layer functionality.
  • The sample app is a Lambda function fronted by an APIGW with Lambda Proxy integration endpoint.
  • The lambda function makes 2 requests: 1) to an http endpoint using OkHttp client 2) to S3 using an AWS SDK v2 client.
  • The resources for the application are fully managed via Terraform
  • The lambda function and the 2 outbound calls can be instrumented via an ADOT/Application Signals lambda layer. Note that publishing the layer to the account is not part of this sample app and will be done separately.

Snapshots from the sample app:

image image

Trace raw data:

{
    "Id": "1-674e3143-74c046ef65fb600f267ea1af",
    "Duration": 9.344,
    "LimitExceeded": false,
    "Segments": [
        {
            "Id": "ce9c407b8f3d1ebc",
            "Document": {
                "id": "ce9c407b8f3d1ebc",
                "name": "aws-opentelemetry-distro-java",
                "start_time": 1733177672.547045,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.422516,
                "parent_id": "0919664b579b5b20",
                "aws": {
                    "cloudwatch_logs": [
                        {
                            "log_group": "/aws/lambda/aws-opentelemetry-distro-java"
                        }
                    ]
                },
                "annotations": {
                    "aws:responseLatency": 3860.693,
                    "aws:runtimeOverhead": 14.076,
                    "aws:responseDuration": 0.08
                },
                "origin": "AWS::Lambda::Function",
                "subsegments": [
                    {
                        "id": "72a9e3c3dee85096",
                        "name": "Overhead",
                        "start_time": 1733177676.407,
                        "end_time": 1733177676.421076
                    },
                    {
                        "id": "85d0d2ac268921fb",
                        "name": "Init",
                        "start_time": 1733177667.5521572,
                        "end_time": 1733177672.542581
                    }
                ]
            }
        },
        {
            "Id": "0919664b579b5b20",
            "Document": {
                "id": "0919664b579b5b20",
                "name": "aws-opentelemetry-distro-java",
                "start_time": 1733177667.152,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.408,
                "parent_id": "091fac537150be46",
                "http": {
                    "response": {
                        "status": 200
                    }
                },
                "aws": {
                    "request_id": "b7450ed4-2ac6-46a2-9698-1e55a997d11e"
                },
                "origin": "AWS::Lambda",
                "resource_arn": "arn:aws:lambda:us-west-2:702258172533:function:aws-opentelemetry-distro-java"
            }
        },
        {
            "Id": "420c3c1d304b104c",
            "Document": {
                "id": "420c3c1d304b104c",
                "name": "aws-opentelemetry-distro-java",
                "start_time": 1733177672.6612847,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.3421717,
                "parent_id": "ce9c407b8f3d1ebc",
                "aws": {
                    "span.kind": "LOCAL_ROOT"
                },
                "annotations": {
                    "aws.local.service": "aws-opentelemetry-distro-java",
                    "span.name": "aws-opentelemetry-distro-java",
                    "aws.local.operation": "aws-opentelemetry-distro-java/FunctionHandler",
                    "span.kind": "SERVER",
                    "aws.local.environment": "lambda:default"
                },
                "metadata": {
                    "process.command_args": [
                        "/var/lang/bin/java",
                        "-XX:MaxHeapSize=445645k",
                        "-javaagent:/var/runtime/lib/Log4jHotPatch.jar=log4jFixerVerbose=false",
                        "-XX:+UseSerialGC",
                        "-Xshare:on",
                        "-XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa",
                        "-XX:+TieredCompilation",
                        "-XX:TieredStopAtLevel=1",
                        "--add-opens=java.base/java.io=ALL-UNNAMED",
                        "-Dorg.crac.Core.Compat=com.amazonaws.services.lambda.crac",
                        "-XX:+ErrorFileToStderr",
                        "-Dcom.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.JNI=/var/runtime/lib/jni/libaws-lambda-jni.linux-x86_64.so",
                        "-classpath",
                        "/var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.6.0-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar",
                        "com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
                        "com.amazon.sampleapp.LambdaHandler::handleRequest"
                    ],
                    "process.runtime.version": "17.0.13+11-LTS",
                    "os.type": "linux",
                    "thread.name": "main",
                    "process.pid": 2,
                    "telemetry.sdk.name": "opentelemetry",
                    "telemetry.sdk.language": "java",
                    "process.runtime.name": "OpenJDK Runtime Environment",
                    "os.description": "Linux 5.10.227-239.884.amzn2.x86_64",
                    "host.arch": "amd64",
                    "cloud.resource_id": "arn:aws:lambda:us-west-2:702258172533:function:aws-opentelemetry-distro-java",
                    "host.name": "169.254.3.42",
                    "telemetry.sdk.version": "1.34.1",
                    "cloud.platform": "aws_lambda",
                    "telemetry.auto.version": "1.32.1-adot-lambda1-aws",
                    "thread.id": 1,
                    "cloud.region": "us-west-2",
                    "service.name": "aws-opentelemetry-distro-java",
                    "faas.name": "aws-opentelemetry-distro-java",
                    "cloud.provider": "aws",
                    "faas.invocation_id": "b7450ed4-2ac6-46a2-9698-1e55a997d11e",
                    "cloud.account.id": "702258172533",
                    "process.executable.path": "/var/lang/bin/java",
                    "faas.instance": "2024/12/02/[$LATEST]dab00aa4dd1744f7b6ef2f576af20320",
                    "faas.version": "$LATEST",
                    "PlatformType": "AWS::Lambda",
                    "process.runtime.description": "Amazon.com Inc. OpenJDK 64-Bit Server VM 17.0.13+11-LTS"
                }
            }
        },
        {
            "Id": "26a8076f05800950",
            "Document": {
                "id": "26a8076f05800950",
                "name": "aws-opentelemetry-distro-java/default",
                "start_time": 1733177667.079,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.409,
                "http": {
                    "request": {
                        "url": "https://v4xcvw0sd8.execute-api.us-west-2.amazonaws.com/default/lambda",
                        "method": "GET",
                        "user_agent": "curl/8.7.1",
                        "client_ip": "73.140.35.122",
                        "x_forwarded_for": true
                    },
                    "response": {
                        "status": 200,
                        "content_length": 0
                    }
                },
                "aws": {
                    "api_gateway": {
                        "account_id": "702258172533",
                        "rest_api_id": "v4xcvw0sd8",
                        "stage": "default",
                        "request_id": "c5524aa2-c2a5-4310-9a2e-370b1faedd07"
                    }
                },
                "annotations": {
                    "aws:api_id": "v4xcvw0sd8",
                    "aws:api_stage": "default"
                },
                "metadata": {
                    "default": {
                        "extended_request_id": "CLyiiFL0vHcEclw=",
                        "request_id": "c5524aa2-c2a5-4310-9a2e-370b1faedd07"
                    }
                },
                "origin": "AWS::ApiGateway::Stage",
                "resource_arn": "arn:aws:apigateway:us-west-2::/restapis/v4xcvw0sd8/stages/default",
                "subsegments": [
                    {
                        "id": "091fac537150be46",
                        "name": "Lambda",
                        "start_time": 1733177667.142,
                        "end_time": 1733177676.409,
                        "http": {
                            "request": {
                                "url": "https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-west-2:702258172533:function:aws-opentelemetry-distro-java/invocations",
                                "method": "ANY"
                            },
                            "response": {
                                "status": 200,
                                "content_length": 197
                            }
                        },
                        "aws": {
                            "function_name": "aws-opentelemetry-distro-java",
                            "region": "us-west-2",
                            "operation": "Invoke",
                            "resource_names": [
                                "aws-opentelemetry-distro-java"
                            ]
                        },
                        "namespace": "aws"
                    }
                ]
            }
        },
        {
            "Id": "97238b9c10f4ff4b",
            "Document": {
                "id": "97238b9c10f4ff4b",
                "name": "aws-opentelemetry-distro-java",
                "start_time": 1733177673.4013793,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.206476,
                "parent_id": "ce9c407b8f3d1ebc",
                "aws": {
                    "span.kind": "LOCAL_ROOT"
                },
                "annotations": {
                    "aws.local.service": "aws-opentelemetry-distro-java",
                    "span.name": "aws-opentelemetry-distro-java",
                    "aws.local.operation": "aws-opentelemetry-distro-java/FunctionHandler",
                    "span.kind": "SERVER",
                    "aws.local.environment": "lambda:default"
                },
                "metadata": {
                    "process.command_args": [
                        "/var/lang/bin/java",
                        "-XX:MaxHeapSize=445645k",
                        "-javaagent:/var/runtime/lib/Log4jHotPatch.jar=log4jFixerVerbose=false",
                        "-XX:+UseSerialGC",
                        "-Xshare:on",
                        "-XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa",
                        "-XX:+TieredCompilation",
                        "-XX:TieredStopAtLevel=1",
                        "--add-opens=java.base/java.io=ALL-UNNAMED",
                        "-Dorg.crac.Core.Compat=com.amazonaws.services.lambda.crac",
                        "-XX:+ErrorFileToStderr",
                        "-Dcom.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.JNI=/var/runtime/lib/jni/libaws-lambda-jni.linux-x86_64.so",
                        "-classpath",
                        "/var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.6.0-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar",
                        "com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
                        "com.amazon.sampleapp.LambdaHandler::handleRequest"
                    ],
                    "process.runtime.version": "17.0.13+11-LTS",
                    "os.type": "linux",
                    "thread.name": "main",
                    "process.pid": 2,
                    "telemetry.sdk.name": "opentelemetry",
                    "telemetry.sdk.language": "java",
                    "process.runtime.name": "OpenJDK Runtime Environment",
                    "os.description": "Linux 5.10.227-239.884.amzn2.x86_64",
                    "host.arch": "amd64",
                    "cloud.resource_id": "arn:aws:lambda:us-west-2:702258172533:function:aws-opentelemetry-distro-java",
                    "host.name": "169.254.3.42",
                    "telemetry.sdk.version": "1.34.1",
                    "cloud.platform": "aws_lambda",
                    "telemetry.auto.version": "1.32.1-adot-lambda1-aws",
                    "thread.id": 1,
                    "cloud.region": "us-west-2",
                    "service.name": "aws-opentelemetry-distro-java",
                    "faas.name": "aws-opentelemetry-distro-java",
                    "cloud.provider": "aws",
                    "faas.invocation_id": "b7450ed4-2ac6-46a2-9698-1e55a997d11e",
                    "cloud.account.id": "702258172533",
                    "process.executable.path": "/var/lang/bin/java",
                    "faas.instance": "2024/12/02/[$LATEST]dab00aa4dd1744f7b6ef2f576af20320",
                    "faas.version": "$LATEST",
                    "PlatformType": "AWS::Lambda",
                    "process.runtime.description": "Amazon.com Inc. OpenJDK 64-Bit Server VM 17.0.13+11-LTS"
                },
                "subsegments": [
                    {
                        "id": "fecf82e4c2bd1b86",
                        "name": "www.amazon.com:443",
                        "start_time": 1733177674.4243093,
                        "end_time": 1733177674.6034126,
                        "http": {
                            "request": {
                                "url": "https://www.amazon.com/",
                                "method": "GET"
                            },
                            "response": {
                                "status": 200
                            }
                        },
                        "aws": {
                            "span.kind": "CLIENT"
                        },
                        "annotations": {
                            "aws.local.service": "aws-opentelemetry-distro-java",
                            "span.name": "GET",
                            "aws.local.operation": "aws-opentelemetry-distro-java/FunctionHandler",
                            "span.kind": "CLIENT",
                            "aws.remote.service": "www.amazon.com:443",
                            "aws.remote.operation": "GET /",
                            "aws.local.environment": "lambda:default"
                        },
                        "metadata": {
                            "http.url": "https://www.amazon.com/",
                            "process.command_args": [
                                "/var/lang/bin/java",
                                "-XX:MaxHeapSize=445645k",
                                "-javaagent:/var/runtime/lib/Log4jHotPatch.jar=log4jFixerVerbose=false",
                                "-XX:+UseSerialGC",
                                "-Xshare:on",
                                "-XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa",
                                "-XX:+TieredCompilation",
                                "-XX:TieredStopAtLevel=1",
                                "--add-opens=java.base/java.io=ALL-UNNAMED",
                                "-Dorg.crac.Core.Compat=com.amazonaws.services.lambda.crac",
                                "-XX:+ErrorFileToStderr",
                                "-Dcom.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.JNI=/var/runtime/lib/jni/libaws-lambda-jni.linux-x86_64.so",
                                "-classpath",
                                "/var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.6.0-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar",
                                "com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
                                "com.amazon.sampleapp.LambdaHandler::handleRequest"
                            ],
                            "process.runtime.version": "17.0.13+11-LTS",
                            "os.type": "linux",
                            "thread.name": "main",
                            "process.pid": 2,
                            "telemetry.sdk.name": "opentelemetry",
                            "net.peer.name": "www.amazon.com",
                            "telemetry.sdk.language": "java",
                            "process.runtime.name": "OpenJDK Runtime Environment",
                            "os.description": "Linux 5.10.227-239.884.amzn2.x86_64",
                            "host.arch": "amd64",
                            "net.protocol.name": "http",
                            "host.name": "169.254.3.42",
                            "telemetry.sdk.version": "1.34.1",
                            "http.method": "GET",
                            "cloud.platform": "aws_lambda",
                            "telemetry.auto.version": "1.32.1-adot-lambda1-aws",
                            "thread.id": 1,
                            "net.peer.port": 443,
                            "cloud.region": "us-west-2",
                            "service.name": "aws-opentelemetry-distro-java",
                            "faas.name": "aws-opentelemetry-distro-java",
                            "http.status_code": 200,
                            "cloud.provider": "aws",
                            "process.executable.path": "/var/lang/bin/java",
                            "faas.instance": "2024/12/02/[$LATEST]dab00aa4dd1744f7b6ef2f576af20320",
                            "faas.version": "$LATEST",
                            "PlatformType": "AWS::Lambda",
                            "process.runtime.description": "Amazon.com Inc. OpenJDK 64-Bit Server VM 17.0.13+11-LTS",
                            "net.protocol.version": "2"
                        },
                        "namespace": "remote"
                    },
                    {
                        "id": "207cb218ec1c0517",
                        "name": "s3.us-west-2.amazonaws.com",
                        "start_time": 1733177675.7453682,
                        "end_time": 1733177676.102766,
                        "error": true,
                        "http": {
                            "request": {
                                "url": "https://s3.us-west-2.amazonaws.com/SomeDummyBucket",
                                "method": "HEAD"
                            },
                            "response": {
                                "status": 404
                            }
                        },
                        "aws": {
                            "span.kind": "CLIENT"
                        },
                        "annotations": {
                            "aws.local.service": "aws-opentelemetry-distro-java",
                            "span.name": "HEAD",
                            "aws.local.operation": "aws-opentelemetry-distro-java/FunctionHandler",
                            "span.kind": "CLIENT",
                            "aws.remote.service": "s3.us-west-2.amazonaws.com",
                            "aws.remote.operation": "HEAD /SomeDummyBucket",
                            "aws.local.environment": "lambda:default"
                        },
                        "metadata": {
                            "http.url": "https://s3.us-west-2.amazonaws.com/SomeDummyBucket",
                            "process.command_args": [
                                "/var/lang/bin/java",
                                "-XX:MaxHeapSize=445645k",
                                "-javaagent:/var/runtime/lib/Log4jHotPatch.jar=log4jFixerVerbose=false",
                                "-XX:+UseSerialGC",
                                "-Xshare:on",
                                "-XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa",
                                "-XX:+TieredCompilation",
                                "-XX:TieredStopAtLevel=1",
                                "--add-opens=java.base/java.io=ALL-UNNAMED",
                                "-Dorg.crac.Core.Compat=com.amazonaws.services.lambda.crac",
                                "-XX:+ErrorFileToStderr",
                                "-Dcom.amazonaws.services.lambda.runtime.api.client.runtimeapi.NativeClient.JNI=/var/runtime/lib/jni/libaws-lambda-jni.linux-x86_64.so",
                                "-classpath",
                                "/var/runtime/lib/aws-lambda-java-core-1.2.3.jar:/var/runtime/lib/aws-lambda-java-runtime-interface-client-2.6.0-linux-x86_64.jar:/var/runtime/lib/aws-lambda-java-serialization-1.1.5.jar",
                                "com.amazonaws.services.lambda.runtime.api.client.AWSLambda",
                                "com.amazon.sampleapp.LambdaHandler::handleRequest"
                            ],
                            "process.runtime.version": "17.0.13+11-LTS",
                            "os.type": "linux",
                            "thread.name": "main",
                            "process.pid": 2,
                            "telemetry.sdk.name": "opentelemetry",
                            "net.peer.name": "s3.us-west-2.amazonaws.com",
                            "telemetry.sdk.language": "java",
                            "process.runtime.name": "OpenJDK Runtime Environment",
                            "os.description": "Linux 5.10.227-239.884.amzn2.x86_64",
                            "host.arch": "amd64",
                            "net.protocol.name": "http",
                            "host.name": "169.254.3.42",
                            "telemetry.sdk.version": "1.34.1",
                            "http.method": "HEAD",
                            "cloud.platform": "aws_lambda",
                            "telemetry.auto.version": "1.32.1-adot-lambda1-aws",
                            "thread.id": 1,
                            "cloud.region": "us-west-2",
                            "service.name": "aws-opentelemetry-distro-java",
                            "faas.name": "aws-opentelemetry-distro-java",
                            "http.status_code": 404,
                            "cloud.provider": "aws",
                            "process.executable.path": "/var/lang/bin/java",
                            "faas.instance": "2024/12/02/[$LATEST]dab00aa4dd1744f7b6ef2f576af20320",
                            "faas.version": "$LATEST",
                            "PlatformType": "AWS::Lambda",
                            "process.runtime.description": "Amazon.com Inc. OpenJDK 64-Bit Server VM 17.0.13+11-LTS",
                            "net.protocol.version": "1.1"
                        },
                        "namespace": "remote"
                    }
                ]
            }
        },
        {
            "Id": "2f9a70de277a6190",
            "Document": {
                "id": "2f9a70de277a6190",
                "name": "s3.us-west-2.amazonaws.com",
                "start_time": 1733177675.7453682,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177676.102766,
                "parent_id": "207cb218ec1c0517",
                "inferred": true,
                "error": true,
                "http": {
                    "request": {
                        "url": "https://s3.us-west-2.amazonaws.com/SomeDummyBucket",
                        "method": "HEAD"
                    },
                    "response": {
                        "status": 404
                    }
                },
                "annotations": {
                    "aws.local.service": "s3.us-west-2.amazonaws.com",
                    "aws.local.operation": "HEAD /SomeDummyBucket"
                }
            }
        },
        {
            "Id": "3dbed31c35ffdb14",
            "Document": {
                "id": "3dbed31c35ffdb14",
                "name": "www.amazon.com:443",
                "start_time": 1733177674.4243093,
                "trace_id": "1-674e3143-74c046ef65fb600f267ea1af",
                "end_time": 1733177674.6034126,
                "parent_id": "fecf82e4c2bd1b86",
                "inferred": true,
                "http": {
                    "request": {
                        "url": "https://www.amazon.com/",
                        "method": "GET"
                    },
                    "response": {
                        "status": 200
                    }
                },
                "annotations": {
                    "aws.local.service": "www.amazon.com:443",
                    "aws.local.operation": "GET /"
                }
            }
        }
    ]
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@srprash srprash marked this pull request as ready for review December 2, 2024 21:54
@srprash srprash requested a review from a team as a code owner December 2, 2024 21:54
Copy link
Member

@mxiamxia mxiamxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@srprash srprash merged commit eae57c5 into aws-observability:main Dec 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants