Skip to content

Commit de9caa5

Browse files
committed
Use vendored version of requests package in layer.
1 parent ed8c462 commit de9caa5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ RUN rm ./python/lib/$runtime/site-packages/ddtrace/internal/datadog/profiling/dd
3030
RUN rm ./python/lib/$runtime/site-packages/ddtrace/internal/datadog/profiling/stack_v2/_stack_v2.*.so
3131
RUN find . -name "*.dist-info" -type d | xargs rm -rf
3232

33+
# The requests package is available in the lambda runtime already as
34+
# pip._vendor.requests. Before importing requests, `/path/to/pip/_vendor` must
35+
# be added to `sys.path`.
36+
RUN rm -rf \
37+
./python/lib/$runtime/site-packages/requests* \
38+
./python/lib/$runtime/site-packages/certifi* \
39+
./python/lib/$runtime/site-packages/idna* \
40+
./python/lib/$runtime/site-packages/charset_normalizer*
41+
3342
# Precompile all .pyc files and remove .py files. This speeds up load time.
3443
# Compile with optimization level 2 (-OO) and PYTHONNODEBUGRANGES=1 to redtce
3544
# size of .pyc files.

datadog_lambda/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import sys
2+
3+
4+
# The requests package is no longer included in the lambda layer, instead use
5+
# the vendored version of requests included in the pip package. Appending to
6+
# sys.path will make the vendered requests package discoverable.
7+
for i in range(len(sys.path)):
8+
path = sys.path[i]
9+
sys.path.append(f"{path}/pip/_vendor")
10+
111
from datadog_lambda.cold_start import initialize_cold_start_tracing
212
import os
313

scripts/check_layer_size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
set -e
1111
MAX_LAYER_COMPRESSED_SIZE_KB=$(expr 5 \* 1024)
12-
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 13 \* 1024)
12+
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 12 \* 1024)
1313

1414

1515
LAYER_FILES_PREFIX="datadog_lambda_py"

tests/integration/handle.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import requests
2-
31
from datadog_lambda.metric import lambda_metric
42
from datadog_lambda.wrapper import datadog_lambda_wrapper
53

4+
import requests
5+
import time
6+
67

78
@datadog_lambda_wrapper
89
def handle(event, context):
@@ -20,7 +21,11 @@ def handle(event, context):
2021
record_ids.append(record["Sns"]["MessageId"])
2122

2223
# Generate custom metrics
24+
timestamp = time.time() - 60
2325
lambda_metric("hello.dog", 1, tags=["team:serverless", "role:hello"])
26+
lambda_metric(
27+
"hello.cat", 1, tags=["team:serverless", "role:hello"], timestamp=timestamp
28+
)
2429
lambda_metric(
2530
"tests.integration.count", 21, tags=["test:integration", "role:hello"]
2631
)

0 commit comments

Comments
 (0)