Repository: elastic/apm-agent-python

Issue:
[META 679] Add support for ELB and Lambda URL metadata in lambda integrations
See meta issue for the description and details:
- Meta issue: https://github.com/elastic/apm/issues/679


Discussion:
apmmachine: 
## :green_heart: Build Succeeded


<!-- BUILD BADGES-->
> _the below badges are clickable and redirect to their specific view in the CI or DOCS_
[![Pipeline View](https://img.shields.io/badge/pipeline-pipeline%20-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-python%2Fapm-agent-python-mbp%2FPR-1623/detail/PR-1623/1//pipeline) [![Test View](https://img.shields.io/badge/test-test-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-python%2Fapm-agent-python-mbp%2FPR-1623/detail/PR-1623/1//tests) [![Changes](https://img.shields.io/badge/changes-changes-green)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-python%2Fapm-agent-python-mbp%2FPR-1623/detail/PR-1623/1//changes) [![Artifacts](https://img.shields.io/badge/artifacts-artifacts-yellow)](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-python%2Fapm-agent-python-mbp%2FPR-1623/detail/PR-1623/1//artifacts) [![preview](https://img.shields.io/badge/docs-preview-yellowgreen)](http://apm-agent-python_1623.docs-preview.app.elstc.co/diff)  [![preview](https://img.shields.io/badge/elastic-observability-blue)](https://ci-stats.elastic.co/app/apm/services/apm-ci/transactions/view?rangeFrom=2022-08-30T17:48:55.537Z&rangeTo=2022-08-30T18:08:55.537Z&transactionName=BUILD+apm-agent-python%2Fapm-agent-python-mbp%2FPR-%7Bnumber%7D&transactionType=job&latencyAggregationType=avg&traceId=5a6551450f2a1d0e739fcd6f3183a6ee&transactionId=5da90229bae29449)

<!-- BUILD SUMMARY-->
<details><summary>Expand to view the summary</summary>
<p>

#### Build stats




* Start Time: 2022-08-30T17:58:55.537+0000


* Duration: 30 min 44 sec




#### Test stats :test_tube:

| Test         | Results                         |
| ------------ | :-----------------------------: |
| Failed       | 0  |
| Passed       | 4974  |
| Skipped      | 3338 |
| Total        | 8312   |


</p>
</details>

<!-- TEST RESULTS IF ANY-->


<!-- STEPS ERRORS IF ANY -->














## :green_heart: Flaky test report
Tests succeeded.



## :robot: GitHub comments

To re-run your PR in the CI, just comment with:



- `/test` : Re-trigger the build.


- `/test linters` : Run the Python linters only.


- `/test full` : Run the full matrix of tests.


- `/test benchmark` : Run the APM Agent Python benchmarks tests.


- `run` `elasticsearch-ci/docs` : Re-trigger the docs validation. (use unformatted text in the comment!)




<!--COMMENT_GENERATED_WITH_ID_comment.id-->
apmmachine: ### :globe_with_meridians: Coverage report

Name | Metrics % (`covered/total`) | Diff
 --- | --- | ---
Packages | 100.0% (`66/66`) | :green_heart: 
Files | 100.0% (`225/225`) | :green_heart: 
Classes | 100.0% (`225/225`) | :green_heart: 
Lines | 89.841% (`17439/19411`) | :+1: 
Conditionals | 77.279% (`3187/4124`) | :+1: 0.024

<!--COMMENT_GENERATED_WITH_ID_coverage-->

Patch:
diff --git a/elasticapm/contrib/serverless/aws.py b/elasticapm/contrib/serverless/aws.py
index 8fc14cbc..4bd2ae2f 100644
--- a/elasticapm/contrib/serverless/aws.py
+++ b/elasticapm/contrib/serverless/aws.py
@@ -261,8 +261,7 @@ class capture_serverless(object):
         elif self.source == "elb":
             elb_target_group_arn = self.event["requestContext"]["elb"]["targetGroupArn"]
             faas["trigger"]["type"] = "http"
-            faas["trigger"]["request_id"] = self.event["headers"]["x-amzn-trace-id"]
-            service_context["origin"] = {"name": elb_target_group_arn.split(":")[5]}
+            service_context["origin"] = {"name": elb_target_group_arn.split(":")[5].split("/")[1]}
             service_context["origin"]["id"] = elb_target_group_arn
             cloud_context["origin"] = {}
             cloud_context["origin"]["service"] = {"name": "elb"}


Test patch:
diff --git a/tests/contrib/serverless/aws_tests.py b/tests/contrib/serverless/aws_tests.py
index 55331c9a..15264cad 100644
--- a/tests/contrib/serverless/aws_tests.py
+++ b/tests/contrib/serverless/aws_tests.py
@@ -265,6 +265,7 @@ def test_capture_serverless_elb(event_elb, context, elasticapm_client):
     assert transaction["context"]["request"]["method"] == "POST"
     assert transaction["context"]["request"]["headers"]
     assert transaction["context"]["response"]["status_code"] == 200
+    assert transaction["context"]["service"]["origin"]["name"] == "lambda-279XGJDqGZ5rsrHC2Fjr"
 
 
 def test_capture_serverless_s3(event_s3, context, elasticapm_client):