Skip to content

[beta] Python Profiling support #244

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

Merged
merged 25 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7d1f671
feat: Python Profiler WIP
astuyve May 20, 2022
88d8285
feat: start on cold start, stop never
astuyve Jun 22, 2022
e987052
breaking: bump dd trace to 1.2.1
astuyve Jun 29, 2022
261ad7e
feat: Add major version notes
astuyve Jun 29, 2022
af0105f
Merge branch 'main' into aj/bump-dd-trace-to-1x
astuyve Jun 29, 2022
65a3bf9
fix: readme header size
astuyve Jun 29, 2022
f1de303
fix: Fix test using old method. Describe change in changes list
astuyve Jun 29, 2022
6165ad7
fix: use tracer instead of correlation ids
astuyve Jun 30, 2022
ef1ab57
Merge branch 'aj/bump-dd-trace-to-1x' into aj/profiling-poc
astuyve Jul 8, 2022
a920b1a
feat: Add the profiler
astuyve Aug 23, 2022
8f242ac
Merge branch 'main' into aj/profiling-poc
astuyve Aug 23, 2022
db1c6e5
fix: remove debug
astuyve Aug 23, 2022
43f9677
feat: Remove profiling comment line
astuyve Aug 23, 2022
6814ed6
feat: Go to ddtrace 1.4. Conditionally import profiler.
astuyve Aug 23, 2022
1151b86
fix: remove duplicate declaration of profiling_env_var
astuyve Aug 23, 2022
5cdc307
feat: Black, with the right version
astuyve Aug 23, 2022
8d50a02
feat: Readme on profiler beta period
astuyve Aug 23, 2022
050abf7
fix: Remove dev changes used to package dd-trace locally
astuyve Aug 23, 2022
c68ea90
feat: Remove == from if True
astuyve Aug 23, 2022
b490104
feat: Bump layer size maximums
astuyve Aug 23, 2022
8392d5d
feat: Remove python36 integration tests, as we can no longer create s…
astuyve Aug 23, 2022
fa3346c
feat: Update snapshots
astuyve Aug 23, 2022
f0e3f5d
feat: More python 3.6 deprecation
astuyve Aug 23, 2022
7d6ea39
Merge branch 'main' into aj/profiling-poc
astuyve Aug 23, 2022
c392111
feat: Readme update - dropping python36
astuyve Aug 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ RUN find ./python/lib/$runtime/site-packages -name \*.pyc -delete
# Remove botocore (40MB) to reduce package size. aws-xray-sdk
# installs it, while it's already provided by the Lambda Runtime.
RUN rm -rf ./python/lib/$runtime/site-packages/botocore*

# Remove profiling (7MB) to reduce package size.
# Continous profiling is not yet supported anyway.
RUN rm -rf ./python/lib/$runtime/site-packages/ddtrace/profiling
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ When opening an issue, include the Datadog Lambda Library version, Python versio

You can also open an issue for a feature request.

## Lambda Profiling Beta

Datadog's Continuous Profiler is now available in beta for Python. This optional feature is enabled by setting the `DD_PROFILING_ENABLED` environment variable to `True`. During the beta period, profiling is available at no cost.

## Major Version Notes

### 4.x
### 4.x / Layer version 61+

- `dd-trace` upgraded from 0.61 to 1.2, full release notes are available [here](https://ddtrace.readthedocs.io/en/stable/release_notes.html#v1-0-0)
- Python3.6 support has been [deprecated](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) by AWS, and support removed from this library.
- `dd-trace` upgraded from 0.61 to 1.4, full release notes are available [here](https://ddtrace.readthedocs.io/en/stable/release_notes.html#v1-0-0)
- `get_correlation_ids()` has been changed to `get_log_correlation_context()`, which now returns a dictionary containing the active `span_id`, `trace_id`, as well as `service` and `env`.

## Contributing
Expand Down
12 changes: 10 additions & 2 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@
from datadog_lambda.trigger import extract_trigger_tags, extract_http_status_code_tag
from datadog_lambda.tag_object import tag_object

profiling_env_var = os.environ.get("DD_PROFILING_ENABLED", "false").lower() == "true"
if profiling_env_var:
from ddtrace.profiling import profiler

logger = logging.getLogger(__name__)

dd_capture_lambda_payload_enabled = (
os.environ.get("DD_CAPTURE_LAMBDA_PAYLOAD", "false").lower() == "true"
)
service_env_var = os.environ.get("DD_SERVICE", "DefaultServiceName")
env_env_var = os.environ.get("DD_ENV", None)

"""
Usage:
Expand Down Expand Up @@ -111,7 +117,8 @@ def __init__(self, func):
os.environ.get("DD_TRACE_MANAGED_SERVICES", "true").lower() == "true"
)
self.response = None

if profiling_env_var:
self.prof = profiler.Profiler(env=env_env_var, service=service_env_var)
if self.extractor_env:
extractor_parts = self.extractor_env.rsplit(".", 1)
if len(extractor_parts) == 2:
Expand Down Expand Up @@ -181,7 +188,8 @@ def _before(self, event, context):
)
else:
set_correlation_ids()

if profiling_env_var and is_cold_start():
self.prof.start(stop_on_exit=False, profile_children=True)
logger.debug("datadog_lambda_wrapper _before() done")
except Exception:
traceback.print_exc()
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions scripts/check_layer_size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# Compares layer size to threshold, and fails if below that threshold

# 5 mb size limit
MAX_LAYER_COMPRESSED_SIZE_KB=$(expr 5 \* 1024)
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 16 \* 1024)
# 6 mb size limit
MAX_LAYER_COMPRESSED_SIZE_KB=$(expr 6 \* 1024)
MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 24 \* 1024)


LAYER_FILES_PREFIX="datadog_lambda_py"
Expand Down
99 changes: 54 additions & 45 deletions tests/integration/snapshots/logs/async-metrics_python37.log

Large diffs are not rendered by default.

99 changes: 54 additions & 45 deletions tests/integration/snapshots/logs/async-metrics_python38.log

Large diffs are not rendered by default.

99 changes: 54 additions & 45 deletions tests/integration/snapshots/logs/async-metrics_python39.log

Large diffs are not rendered by default.

180 changes: 99 additions & 81 deletions tests/integration/snapshots/logs/sync-metrics_python37.log

Large diffs are not rendered by default.

180 changes: 99 additions & 81 deletions tests/integration/snapshots/logs/sync-metrics_python38.log

Large diffs are not rendered by default.

180 changes: 99 additions & 81 deletions tests/integration/snapshots/logs/sync-metrics_python39.log

Large diffs are not rendered by default.