Skip to content

Commit

Permalink
Merge branch 'main' into zachg/deprecate_patch_all
Browse files Browse the repository at this point in the history
  • Loading branch information
ZStriker19 authored Feb 6, 2025
2 parents efef2eb + 1247ac2 commit 0d3e8dc
Show file tree
Hide file tree
Showing 252 changed files with 5,443 additions and 2,480 deletions.
2 changes: 1 addition & 1 deletion .github/COMMIT_TEMPLATE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ feat/fix/docs/refactor/ci(xxx): commit title here
# mysqlpython, openai, opentelemetry, opentracer, profile, psycopg, pylibmc, pymemcache,
# pymongo, pymysql, pynamodb, pyodbc, pyramid, pytest, redis, rediscluster, requests, rq,
# sanic, snowflake, sourcecode, sqlalchemy, starlette, stdlib, structlog, subprocess,
# telemetry, test_logging, tornado, tracer, unittest, urllib3, vendor, vertica, wsgi,
# telemetry, test_logging, tornado, tracer, unittest, urllib3, valkey, vendor, vertica, wsgi,
# yaaredis
2 changes: 1 addition & 1 deletion .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
build_wheels:
uses: ./.github/workflows/build_python_3.yml
with:
cibw_build: 'cp37* cp38* cp39* cp310* cp311* cp312* cp313*'
cibw_build: 'cp38* cp39* cp310* cp311* cp312* cp313*'

build_sdist:
name: Build source distribution
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
6 changes: 6 additions & 0 deletions .gitlab/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
redis:
name: registry.ddbuild.io/redis:7.0.7
alias: redis
valkey:
name: registry.ddbuild.io/images/mirror/valkey:8.0-alpine
alias: valkey
kafka:
name: registry.ddbuild.io/images/mirror/apache/kafka:3.8.0
alias: kafka
Expand All @@ -54,6 +57,9 @@
rediscluster:
name: registry.ddbuild.io/images/mirror/grokzen/redis-cluster:6.2.0
alias: rediscluster
valkeycluster:
name: registry.ddbuild.io/images/mirror/grokzen/redis-cluster:6.2.0
alias: valkeycluster
elasticsearch:
name: registry.ddbuild.io/images/mirror/library/elasticsearch:7.17.23
alias: elasticsearch
Expand Down
26 changes: 26 additions & 0 deletions .riot/requirements/11ac941.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/11ac941.in
#
async-timeout==5.0.1
attrs==24.3.0
coverage[toml]==7.6.1
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
sortedcontainers==2.4.0
tomli==2.2.1
valkey==6.0.2
zipp==3.20.2
26 changes: 26 additions & 0 deletions .riot/requirements/1e98e9b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/1e98e9b.in
#
async-timeout==5.0.1
attrs==24.3.0
coverage[toml]==7.6.10
exceptiongroup==1.2.2
hypothesis==6.45.0
importlib-metadata==8.5.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
sortedcontainers==2.4.0
tomli==2.2.1
valkey==6.0.2
zipp==3.21.0
22 changes: 22 additions & 0 deletions .riot/requirements/4aa2a2a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/4aa2a2a.in
#
async-timeout==5.0.1
attrs==24.3.0
coverage[toml]==7.6.10
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
sortedcontainers==2.4.0
valkey==6.0.2
21 changes: 21 additions & 0 deletions .riot/requirements/7219cf4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# This file is autogenerated by pip-compile with Python 3.13
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/7219cf4.in
#
attrs==24.3.0
coverage[toml]==7.6.10
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
sortedcontainers==2.4.0
valkey==6.0.2
21 changes: 21 additions & 0 deletions .riot/requirements/b96b665.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/b96b665.in
#
attrs==24.3.0
coverage[toml]==7.6.10
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
sortedcontainers==2.4.0
valkey==6.0.2
24 changes: 24 additions & 0 deletions .riot/requirements/dd68acc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --no-annotate .riot/requirements/dd68acc.in
#
async-timeout==5.0.1
attrs==24.3.0
coverage[toml]==7.6.10
exceptiongroup==1.2.2
hypothesis==6.45.0
iniconfig==2.0.0
mock==5.1.0
opentracing==2.4.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.4
pytest-asyncio==0.23.7
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
sortedcontainers==2.4.0
tomli==2.2.1
valkey==6.0.2
1 change: 1 addition & 0 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"unittest": True,
"coverage": False,
"selenium": True,
"valkey": True,
}


Expand Down
70 changes: 39 additions & 31 deletions ddtrace/_trace/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import wrapt

import ddtrace
from ddtrace.vendor.debtcollector import deprecate

from ..internal.logger import get_logger

Expand All @@ -32,25 +31,17 @@ class Pin(object):
>>> conn = sqlite.connect('/tmp/image.db')
"""

__slots__ = ["tags", "tracer", "_target", "_config", "_initialized"]
__slots__ = ["tags", "_tracer", "_target", "_config", "_initialized"]

def __init__(
self,
service=None, # type: Optional[str]
tags=None, # type: Optional[Dict[str, str]]
tracer=None,
_config=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> None
if tracer is not None and tracer is not ddtrace.tracer:
deprecate(
"Initializing ddtrace.trace.Pin with `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)
tracer = tracer or ddtrace.tracer
self.tags = tags
self.tracer = tracer
self._tracer = ddtrace.tracer
self._target = None # type: Optional[int]
# keep the configuration attribute internal because the
# public API to access it is not the Pin class
Expand All @@ -68,10 +59,14 @@ def service(self):
return self._config["service_name"]

def __setattr__(self, name, value):
if getattr(self, "_initialized", False) and name != "_target":
if getattr(self, "_initialized", False) and name not in ("_target", "_tracer"):
raise AttributeError("can't mutate a pin, use override() or clone() instead")
super(Pin, self).__setattr__(name, value)

@property
def tracer(self):
return self._tracer

def __repr__(self):
return "Pin(service=%s, tags=%s, tracer=%s)" % (self.service, self.tags, self.tracer)

Expand Down Expand Up @@ -127,7 +122,6 @@ def override(
obj, # type: Any
service=None, # type: Optional[str]
tags=None, # type: Optional[Dict[str, str]]
tracer=None,
):
# type: (...) -> None
"""Override an object with the given attributes.
Expand All @@ -139,20 +133,32 @@ def override(
>>> # Override a pin for a specific connection
>>> Pin.override(conn, service='user-db')
"""
if tracer is not None:
deprecate(
"Calling ddtrace.trace.Pin.override(...) with the `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)
Pin._override(obj, service=service, tags=tags)

@classmethod
def _override(
cls,
obj, # type: Any
service=None, # type: Optional[str]
tags=None, # type: Optional[Dict[str, str]]
tracer=None,
):
# type: (...) -> None
"""
Internal method that allows overriding the global tracer in tests
"""
if not obj:
return

pin = cls.get_from(obj)
if pin is None:
Pin(service=service, tags=tags, tracer=tracer).onto(obj)
pin = Pin(service=service, tags=tags)
else:
pin.clone(service=service, tags=tags, tracer=tracer).onto(obj)
pin = pin.clone(service=service, tags=tags)

if tracer:
pin._tracer = tracer
pin.onto(obj)

def enabled(self):
# type: () -> bool
Expand Down Expand Up @@ -198,21 +204,22 @@ def clone(
self,
service=None, # type: Optional[str]
tags=None, # type: Optional[Dict[str, str]]
tracer=None,
):
# type: (...) -> Pin
"""Return a clone of the pin with the given attributes replaced."""
return self._clone(service=service, tags=tags)

def _clone(
self,
service=None, # type: Optional[str]
tags=None, # type: Optional[Dict[str, str]]
tracer=None,
):
"""Internal method that can clone the tracer from an existing Pin. This is used in tests"""
# do a shallow copy of Pin dicts
if not tags and self.tags:
tags = self.tags.copy()

if tracer is not None:
deprecate(
"Initializing ddtrace.trace.Pin with `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)

# we use a copy instead of a deepcopy because we expect configurations
# to have only a root level dictionary without nested objects. Using
# deepcopy introduces a big overhead:
Expand All @@ -221,9 +228,10 @@ def clone(
# deepcopy: 0.2787208557128906
config = self._config.copy()

return Pin(
pin = Pin(
service=service or self.service,
tags=tags,
tracer=tracer or self.tracer, # do not clone the Tracer
_config=config,
)
pin._tracer = tracer or self.tracer
return pin
8 changes: 8 additions & 0 deletions ddtrace/_trace/trace_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ def _on_redis_command_post(ctx: core.ExecutionContext, rowcount):
ctx.span.set_metric(db.ROWCOUNT, rowcount)


def _on_valkey_command_post(ctx: core.ExecutionContext, rowcount):
if rowcount is not None:
ctx.span.set_metric(db.ROWCOUNT, rowcount)


def _on_test_visibility_enable(config) -> None:
from ddtrace.internal.ci_visibility import CIVisibility

Expand Down Expand Up @@ -797,6 +802,8 @@ def listen():
core.on("botocore.kinesis.GetRecords.post", _on_botocore_kinesis_getrecords_post)
core.on("redis.async_command.post", _on_redis_command_post)
core.on("redis.command.post", _on_redis_command_post)
core.on("valkey.async_command.post", _on_valkey_command_post)
core.on("valkey.command.post", _on_valkey_command_post)
core.on("azure.functions.request_call_modifier", _on_azure_functions_request_span_modifier)
core.on("azure.functions.start_response", _on_azure_functions_start_response)

Expand Down Expand Up @@ -838,6 +845,7 @@ def listen():
"botocore.patched_stepfunctions_api_call",
"botocore.patched_bedrock_api_call",
"redis.command",
"valkey.command",
"rq.queue.enqueue_job",
"rq.traced_queue_fetch_job",
"rq.worker.perform_job",
Expand Down
Loading

0 comments on commit 0d3e8dc

Please sign in to comment.