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

feat: integration with dd-trace-api #12057

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
eb66781
stub integration with dd-trace-api
emmettbutler Jan 22, 2025
198aaa9
a basic but valid failing test
emmettbutler Jan 23, 2025
d60b73c
fleshing out the test setup
emmettbutler Jan 24, 2025
4e1004d
working on the dummy tracer...
emmettbutler Jan 24, 2025
dae3efd
store tracer globally
emmettbutler Jan 24, 2025
3e40d48
pull from github
emmettbutler Jan 24, 2025
181b1c1
add dd_trace_api integration to CI
emmettbutler Jan 24, 2025
ffc79e5
linting
emmettbutler Jan 24, 2025
89e04a1
enable snapshots
emmettbutler Jan 24, 2025
9bc3423
doesnt work on 3.7
emmettbutler Jan 24, 2025
60ca763
stub verification
emmettbutler Jan 24, 2025
4ffec90
stub verification
emmettbutler Jan 24, 2025
b1db4dc
only hook once
emmettbutler Jan 24, 2025
d1a7353
more generic code
emmettbutler Jan 24, 2025
1b3cec2
methods on real spans to avoid bookkeeping
emmettbutler Jan 27, 2025
d3a6196
current_span APIs
emmettbutler Jan 27, 2025
026c06d
use singleton tracer
emmettbutler Jan 27, 2025
e1f1a68
convert stubs to real spans when passed to API functions
emmettbutler Jan 27, 2025
36cdb43
slight refactors
emmettbutler Jan 27, 2025
9bba449
remove some duplication from handlers list
emmettbutler Jan 27, 2025
2448b3e
remove some duplication from handlers list
emmettbutler Jan 27, 2025
35d8a49
reno
emmettbutler Jan 27, 2025
66bdb34
Merge branch 'main' into emmett.butler/dd-trace-api-integration
emmettbutler Jan 27, 2025
aaedab9
chore: update changelog for version 2.19.2 (#12088)
Yun-Kim Jan 27, 2025
e3045a1
fix(profiling): fix SystemError when collecting memory profiler event…
nsrip-dd Jan 27, 2025
55767a7
chore(tracing): refactor web server integrations to use the core modu…
wconti27 Jan 28, 2025
16d5280
ci(tracer): make serverless test unrequired (#12121)
christophe-papazian Jan 28, 2025
4f0bcb5
chore(asm): clean libddwaf loading (#12102)
christophe-papazian Jan 28, 2025
b787857
simplify
emmettbutler Jan 28, 2025
86d69dd
simplify
emmettbutler Jan 28, 2025
bae4cac
unused import
emmettbutler Jan 28, 2025
ee4492c
some more tests
emmettbutler Jan 28, 2025
c4448ea
fix(llmobs): propagate distributed headers via signal dispatching, no…
Yun-Kim Jan 28, 2025
cb41f8e
feat(provider): expose context provider in ddtrace.trace (#12135)
mabdinur Jan 29, 2025
50ce3bd
Merge branch 'main' into emmett.butler/dd-trace-api-integration
emmettbutler Jan 29, 2025
af9098c
chore(ci): skip non-linux OCI package creation (#12036)
randomanderson Jan 30, 2025
abca08f
Merge branch 'main' into emmett.butler/dd-trace-api-integration
emmettbutler Jan 31, 2025
17552de
add patching for tracer.wrap, which requires API accessing the return…
emmettbutler Feb 3, 2025
d147067
remove tests for removed functionality
emmettbutler Feb 3, 2025
db87343
remove tests
emmettbutler Feb 4, 2025
e043f22
code organization
emmettbutler Feb 4, 2025
5540bd1
no shared state
emmettbutler Feb 5, 2025
acac914
update requirements
emmettbutler Feb 5, 2025
0e679f8
one hook name
emmettbutler Feb 5, 2025
09c32e3
Merge branch 'main' into emmett.butler/dd-trace-api-integration
emmettbutler Feb 6, 2025
147891b
merge conflict
emmettbutler Feb 6, 2025
8620f4c
merge conflict
emmettbutler Feb 6, 2025
ff23412
disallow configuring dd_trace_api patching via envvars
emmettbutler Feb 6, 2025
d01d844
update suitespec to match reality
emmettbutler Feb 6, 2025
a2a4831
update import that broke with major version
emmettbutler Feb 6, 2025
2f07b12
change order of conditions to avoid a few instructions
emmettbutler Feb 7, 2025
94a7494
simpler span proxying code
emmettbutler Feb 7, 2025
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ ddtrace/internal/remoteconfig @DataDog/remote-config @DataDog/apm-core-pyt
tests/internal/remoteconfig @DataDog/remote-config @DataDog/apm-core-python

# API SDK
ddtrace/trace/ @DataDog/apm-sdk-api-python
ddtrace/_trace/ @DataDog/apm-sdk-api-python
ddtrace/opentelemetry/ @DataDog/apm-sdk-api-python
ddtrace/internal/opentelemetry @DataDog/apm-sdk-api-python
ddtrace/opentracer/ @DataDog/apm-sdk-api-python
ddtrace/propagation/ @DataDog/apm-sdk-api-python
ddtrace/filters.py @DataDog/apm-sdk-api-python
ddtrace/provider.py @DataDog/apm-sdk-api-python
ddtrace/pin.py @DataDog/apm-sdk-api-python
ddtrace/sampler.py @DataDog/apm-sdk-api-python
ddtrace/sampling_rule.py @DataDog/apm-sdk-api-python
Expand Down
1 change: 1 addition & 0 deletions .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ benchmark-serverless:
tags: ["arch:amd64"]
when: on_success
needs: [ "benchmark-serverless-trigger" ]
allow_failure: true
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/serverless-tools.git ./serverless-tools && cd ./serverless-tools
- ./ci/check_trigger_status.sh
Expand Down
5 changes: 5 additions & 0 deletions .gitlab/prepare-oci-package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
set -eo pipefail

if [ "$OS" != "linux" ]; then
echo "Only linux packages are supported. Exiting"
exit 0
fi

if [ -n "$CI_COMMIT_TAG" ] && [ -z "$PYTHON_PACKAGE_VERSION" ]; then
PYTHON_PACKAGE_VERSION=${CI_COMMIT_TAG##v}
fi
Expand Down
27 changes: 27 additions & 0 deletions .riot/requirements/10e65d1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/10e65d1.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.10
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
exceptiongroup==1.2.2
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.2.1
urllib3==2.3.0
25 changes: 25 additions & 0 deletions .riot/requirements/1261872.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/1261872.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.10
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
urllib3==2.3.0
27 changes: 27 additions & 0 deletions .riot/requirements/14d1688.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/14d1688.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.1
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
exceptiongroup==1.2.2
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==5.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.2.1
urllib3==2.2.3
27 changes: 27 additions & 0 deletions .riot/requirements/668f2f5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/668f2f5.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.10
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
exceptiongroup==1.2.2
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.2.1
urllib3==2.3.0
25 changes: 25 additions & 0 deletions .riot/requirements/d5f777e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# This file is autogenerated by pip-compile with Python 3.13
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/d5f777e.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.10
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
urllib3==2.3.0
25 changes: 25 additions & 0 deletions .riot/requirements/e49670c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/e49670c.in
#
attrs==24.3.0
certifi==2024.12.14
charset-normalizer==3.4.1
coverage[toml]==7.6.10
dd-trace-api @ git+https://github.com/DataDog/dd-trace-api-py
hypothesis==6.45.0
idna==3.10
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-cov==6.0.0
pytest-mock==3.14.0
pyyaml==6.0.2
requests==2.32.3
sortedcontainers==2.4.0
urllib3==2.3.0
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changelogs for versions not listed here can be found at https://github.com/DataD

---

## 2.19.2
### Bug Fixes

- Tracing
- celery: Fixes an issue where `celery.apply` spans from Celery prerun got closed too soon leading to span tags being missing.
- openai: Fixes a patching issue where asynchronous moderation endpoint calls resulted in coroutine scheduling errors.
- openai: Ensures the OpenAI integration is compatible with Python versions 3.12 and 3.13.
- vertexai: Resolves an issue with `chat.send_message()` where the content keyword argument was not parsed correctly.
- LLM Observability
- This fix resolves an issue where annotating a span with non latin-1 (but valid utf-8) input/output values resulted in encoding errors.
- Lib-Injection
- Fixes incorrect telemetry data payload format.

---

## 2.19.1
### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cassandra": True,
"celery": True,
"consul": True,
"dd_trace_api": True,
"django": True,
"dramatiq": True,
"elasticsearch": True,
Expand Down
56 changes: 54 additions & 2 deletions ddtrace/_trace/trace_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ def _get_parameters_for_new_span_directly_from_context(ctx: core.ExecutionContex
def _start_span(ctx: core.ExecutionContext, call_trace: bool = True, **kwargs) -> "Span":
span_kwargs = _get_parameters_for_new_span_directly_from_context(ctx)
call_trace = ctx.get_item("call_trace", call_trace)
tracer = (ctx.get_item("middleware") or ctx["pin"]).tracer
tracer = ctx.get_item("tracer") or (ctx.get_item("middleware") or ctx["pin"]).tracer
distributed_headers_config = ctx.get_item("distributed_headers_config")
if distributed_headers_config:
trace_utils.activate_distributed_headers(
tracer, int_config=distributed_headers_config, request_headers=ctx["distributed_headers"]
tracer,
int_config=distributed_headers_config,
request_headers=ctx["distributed_headers"],
override=ctx.get_item("distributed_headers_config_override"),
)
distributed_context = ctx.get_item("distributed_context")
if distributed_context and not call_trace:
Expand All @@ -126,6 +129,42 @@ def _start_span(ctx: core.ExecutionContext, call_trace: bool = True, **kwargs) -
return span


def _set_web_frameworks_tags(ctx, span, int_config):
span.set_tag_str(COMPONENT, int_config.integration_name)
span.set_tag_str(SPAN_KIND, SpanKind.SERVER)
span.set_tag(_SPAN_MEASURED_KEY)

analytics_enabled = ctx.get_item("analytics_enabled")
analytics_sample_rate = ctx.get_item("analytics_sample_rate", True)

# Configure trace search sample rate
if (config._analytics_enabled and analytics_enabled is not False) or analytics_enabled is True:
span.set_tag(_ANALYTICS_SAMPLE_RATE_KEY, analytics_sample_rate)


def _on_web_framework_start_request(ctx, int_config):
request_span = ctx.get_item("req_span")
_set_web_frameworks_tags(ctx, request_span, int_config)


def _on_web_framework_finish_request(
span, int_config, method, url, status_code, query, req_headers, res_headers, route, finish
):
trace_utils.set_http_meta(
span=span,
integration_config=int_config,
method=method,
url=url,
status_code=status_code,
query=query,
request_headers=req_headers,
response_headers=res_headers,
route=route,
)
if finish:
span.finish()


def _on_traced_request_context_started_flask(ctx):
current_span = ctx["pin"].tracer.current_span()
if not ctx["pin"].enabled or not current_span:
Expand Down Expand Up @@ -761,6 +800,10 @@ def listen():
core.on("azure.functions.request_call_modifier", _on_azure_functions_request_span_modifier)
core.on("azure.functions.start_response", _on_azure_functions_start_response)

# web frameworks general handlers
core.on("web.request.start", _on_web_framework_start_request)
core.on("web.request.finish", _on_web_framework_finish_request)

core.on("test_visibility.enable", _on_test_visibility_enable)
core.on("test_visibility.disable", _on_test_visibility_disable)
core.on("test_visibility.is_enabled", _on_test_visibility_is_enabled, "is_enabled")
Expand All @@ -769,6 +812,14 @@ def listen():
core.on("rq.queue.enqueue_job", _propagate_context)

for context_name in (
# web frameworks
"aiohttp.request",
"bottle.request",
"cherrypy.request",
"falcon.request",
"molten.request",
"pyramid.request",
"sanic.request",
"flask.call",
"flask.jsonify",
"flask.render_template",
Expand All @@ -779,6 +830,7 @@ def listen():
"django.template.render",
"django.process_exception",
"django.func.wrapped",
# non web frameworks
"botocore.instrumented_api_call",
"botocore.instrumented_lib_function",
"botocore.patched_kinesis_api_call",
Expand Down
3 changes: 3 additions & 0 deletions ddtrace/appsec/_ddwaf/ddwaf_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@

if system() == "Linux":
try:
asm_config._bypass_instrumentation_for_waf = True
ctypes.CDLL(ctypes.util.find_library("rt"), mode=ctypes.RTLD_GLOBAL)
except Exception: # nosec
pass
finally:
asm_config._bypass_instrumentation_for_waf = False

ARCHI = machine().lower()

Expand Down
Loading
Loading