Skip to content

Commit

Permalink
Merge branch 'main' into quinna/add-tests-pymongo-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
quinna-h committed Sep 23, 2024
2 parents e3a899d + 41b9975 commit 80e4438
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 50 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,3 @@ jobs:
run: python $GITHUB_WORKSPACE/tests/smoke_test.py
# Move out of the workspace to avoid importing ddtrace from the source
working-directory: /

upload_pypi:
needs:
- build_wheels
- test_alpine_sdist
runs-on: ubuntu-latest
if: (github.event_name == 'release' && github.event.action == 'published')
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# To test: repository_url: https://test.pypi.org/legacy/
# Setting skip_existing will prevent the deploy from erring out early
# due to a duplicate wheel being present which will ensure that the rest
# of the wheels will be uploaded if some are uploaded manually.
skip_existing: true
18 changes: 9 additions & 9 deletions .gitlab/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ variables:
- pywheels/*.whl
- pywheels/*.tar.gz

release_pypi_test:
# Can be used to validate uploading of artifacts
# release_pypi_test:
# extends: .release_pypi
# dependencies: [ "download_ddtrace_artifacts" ]
# variables:
# PYPI_REPOSITORY: testpypi

release_pypi_prod:
extends: .release_pypi
dependencies: [ "download_ddtrace_artifacts" ]
variables:
PYPI_REPOSITORY: testpypi

# TODO: Replace GitHub Action PyPI upload with this job
# release_pypi_prod:
# extends: .release_pypi
# needs: [ "release_pypi_test" ]
# variables:
# PYPI_REPOSITORY: pypi
PYPI_REPOSITORY: pypi
23 changes: 22 additions & 1 deletion ddtrace/_trace/trace_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

import wrapt

from ddtrace._trace._span_pointer import _SpanPointerDescription
from ddtrace._trace.span import Span
from ddtrace._trace.utils import extract_DD_context_from_messages
from ddtrace._trace.utils import set_botocore_patched_api_call_span_tags as set_patched_api_call_span_tags
from ddtrace._trace.utils import set_botocore_response_metadata_tags
from ddtrace._trace.utils_botocore.span_pointers import extract_span_pointers_from_successful_botocore_response
from ddtrace.constants import _ANALYTICS_SAMPLE_RATE_KEY
from ddtrace.constants import SPAN_KIND
from ddtrace.constants import SPAN_MEASURED_KEY
Expand Down Expand Up @@ -620,7 +622,17 @@ def _on_botocore_patched_api_call_exception(ctx, response, exception_type, is_er


def _on_botocore_patched_api_call_success(ctx, response):
set_botocore_response_metadata_tags(ctx.get_item(ctx.get_item("call_key")), response)
span = ctx.get_item(ctx.get_item("call_key"))

set_botocore_response_metadata_tags(span, response)

for span_pointer_description in extract_span_pointers_from_successful_botocore_response(
endpoint_name=ctx.get_item("endpoint_name"),
operation_name=ctx.get_item("operation"),
request_parameters=ctx.get_item("params"),
response=response,
):
_set_span_pointer(span, span_pointer_description)


def _on_botocore_trace_context_injection_prepared(
Expand Down Expand Up @@ -774,6 +786,15 @@ def _on_test_visibility_is_enabled() -> bool:
return CIVisibility.enabled


def _set_span_pointer(span: Span, span_pointer_description: _SpanPointerDescription) -> None:
span._add_span_pointer(
pointer_kind=span_pointer_description.pointer_kind,
pointer_direction=span_pointer_description.pointer_direction,
pointer_hash=span_pointer_description.pointer_hash,
extra_attributes=span_pointer_description.extra_attributes,
)


def listen():
core.on("wsgi.block.started", _wsgi_make_block_content, "status_headers_content")
core.on("asgi.block.started", _asgi_make_block_content, "status_headers_content")
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/settings/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,14 @@ def __init__(self):
self._ddtrace_bootstrapped = False
self._subscriptions = [] # type: List[Tuple[List[str], Callable[[Config, List[str]], None]]]
self._span_aggregator_rlock = asbool(os.getenv("DD_TRACE_SPAN_AGGREGATOR_RLOCK", True))
if self._span_aggregator_rlock is False:
deprecate(
"DD_TRACE_SPAN_AGGREGATOR_RLOCK is deprecated",
message="Soon the ddtrace library will only support using threading.Rlock to "
"aggregate and encode span data. If you need to disable the re-entrant lock and "
"revert to using threading.Lock, please contact Datadog support.",
removal_version="3.0.0",
)

self.trace_methods = os.getenv("DD_TRACE_METHODS")

Expand Down
8 changes: 0 additions & 8 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,6 @@ The following environment variables for the tracer are supported:
default: True
description: Send query strings in http.url tag in http server integrations.

DD_TRACE_SPAN_AGGREGATOR_RLOCK:
type: Boolean
default: True
description: Whether the ``SpanAggregator`` should use an RLock or a Lock.
version_added:
v1.16.2: added with default of False
v1.19.0: default changed to True

DD_TRACE_METHODS:
type: String
default: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
deprecations:
- |
tracing: Deprecates the ``DD_TRACE_SPAN_AGGREGATOR_RLOCK`` environment variable. It will be removed in 3.0.0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
botocore: Adds span pointers to some successful AWS botocore spans. Currently only supports S3 PutObject.
27 changes: 27 additions & 0 deletions tests/contrib/botocore/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from moto import mock_stepfunctions
import pytest

from ddtrace._trace._span_pointer import _SpanPointer
from ddtrace._trace._span_pointer import _SpanPointerDirection
from tests.utils import get_128_bit_trace_id_from_headers


Expand Down Expand Up @@ -284,6 +286,8 @@ def test_s3_client(self):
assert span.service == "test-botocore-tracing.s3"
assert span.resource == "s3.listbuckets"

assert not span._links, "no links, i.e. no span pointers"

# testing for span error
self.reset()
try:
Expand Down Expand Up @@ -392,6 +396,17 @@ def test_s3_put(self):
assert span.get_tag("aws.s3.bucket_name") == "mybucket"
assert span.get_tag("bucketname") == "mybucket"

assert span._links == [
_SpanPointer(
pointer_kind="aws.s3.object",
pointer_direction=_SpanPointerDirection.DOWNSTREAM,
# We have more detailed tests for the hashing behavior
# elsewhere. Here we just want to make sure that the pointer is
# correctly attached to the span.
pointer_hash="def44fdefcd83bc907515567dc742be1",
),
]

@mock_s3
def test_s3_put_no_params(self):
with self.override_config("botocore", dict(tag_no_params=True)):
Expand All @@ -403,6 +418,18 @@ def test_s3_put_no_params(self):
assert span.get_tag("params.Body") is None
assert span.get_tag("component") == "botocore"

# We still create the link since we're hashing the parameter data.
assert span._links == [
_SpanPointer(
pointer_kind="aws.s3.object",
pointer_direction=_SpanPointerDirection.DOWNSTREAM,
# We have more detailed tests for the hashing behavior
# elsewhere. Here we just want to make sure that the pointer is
# correctly attached to the span.
pointer_hash="def44fdefcd83bc907515567dc742be1",
),
]

@mock_s3
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_BOTOCORE_SERVICE="botocore"))
def test_service_name_override(self):
Expand Down
10 changes: 0 additions & 10 deletions tests/contrib/gunicorn/test_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _gunicorn_settings_factory(
debug_mode=False, # type: bool
dd_service=None, # type: Optional[str]
schema_version=None, # type: Optional[str]
rlock=True, # type: bool
):
# type: (...) -> GunicornServerSettings
"""Factory for creating gunicorn settings with simple defaults if settings are not defined."""
Expand All @@ -75,8 +74,6 @@ def _gunicorn_settings_factory(
env["DD_SERVICE"] = dd_service
if schema_version is not None:
env["DD_TRACE_SPAN_ATTRIBUTE_SCHEMA"] = schema_version
if rlock is not None:
env["DD_TRACE_SPAN_AGGREGATOR_RLOCK"] = "true"
return GunicornServerSettings(
env=env,
directory=directory,
Expand Down Expand Up @@ -168,12 +165,6 @@ def gunicorn_server(gunicorn_server_settings, tmp_path):
debug_mode=True,
enable_module_cloning=True,
)
SETTINGS_GEVENT_SPANAGGREGATOR_NO_RLOCK = _gunicorn_settings_factory(
worker_class="gevent",
use_ddtracerun=False,
import_auto_in_app=True,
rlock=False,
)


@flaky(until=1706677200)
Expand All @@ -185,7 +176,6 @@ def test_no_known_errors_occur(tmp_path):
SETTINGS_GEVENT_DDTRACERUN,
SETTINGS_GEVENT_DDTRACERUN_MODULE_CLONE,
SETTINGS_GEVENT_DDTRACERUN_DEBUGMODE_MODULE_CLONE,
SETTINGS_GEVENT_SPANAGGREGATOR_NO_RLOCK,
]:
with gunicorn_server(gunicorn_server_settings, tmp_path) as context:
_, client = context
Expand Down

0 comments on commit 80e4438

Please sign in to comment.