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 11 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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ 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
# RUN rm -rf ./python/lib/$runtime/site-packages/ddtrace/profiling
COPY ./ddtrace ./python/lib/$runtime/site-packages/ddtrace
12 changes: 10 additions & 2 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
)
from datadog_lambda.trigger import extract_trigger_tags, extract_http_status_code_tag
from datadog_lambda.tag_object import tag_object
from ddtrace.profiling import profiler

logger = logging.getLogger(__name__)

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

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

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

if profiling_env_var == True and is_cold_start():
print("starting profiler in _before()")
self.prof.start(stop_on_exit=False, profile_children=True)
logger.debug("datadog_lambda_wrapper _before() done")
except Exception:
traceback.print_exc()
Expand Down