Skip to content

Commit 1933a15

Browse files
authored
writer: allow configuration of queue maxsize via env var (#1364)
* writer: allow configuration of queue maxsize via env var * rename to DD_TRACE_MAX_TPS
1 parent a6653c3 commit 1933a15

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ddtrace/internal/writer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# stdlib
22
import itertools
3+
import os
34
import random
45
import time
56
import sys
@@ -16,8 +17,6 @@
1617
log = get_logger(__name__)
1718

1819

19-
MAX_TRACES = 1000
20-
2120
DEFAULT_TIMEOUT = 5
2221
LOG_ERR_INTERVAL = 60
2322

@@ -82,6 +81,7 @@ def write(self, spans=None, services=None):
8281
class AgentWriter(_worker.PeriodicWorkerThread):
8382

8483
QUEUE_PROCESSING_INTERVAL = 1
84+
QUEUE_MAX_TRACES_DEFAULT = 1000
8585

8686
def __init__(
8787
self,
@@ -98,7 +98,9 @@ def __init__(
9898
super(AgentWriter, self).__init__(
9999
interval=self.QUEUE_PROCESSING_INTERVAL, exit_timeout=shutdown_timeout, name=self.__class__.__name__
100100
)
101-
self._trace_queue = Q(maxsize=MAX_TRACES)
101+
# DEV: provide a _temporary_ solution to allow users to specify a custom max
102+
maxsize = int(os.getenv("DD_TRACE_MAX_TPS", self.QUEUE_MAX_TRACES_DEFAULT))
103+
self._trace_queue = Q(maxsize=maxsize)
102104
self._filters = filters
103105
self._sampler = sampler
104106
self._priority_sampler = priority_sampler

tests/test_tracer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,3 +935,9 @@ def test_detect_agentless_env(self):
935935
@run_in_subprocess(env_overrides=dict(AWS_LAMBDA_FUNCTION_NAME="my-func", DD_AGENT_HOST="localhost"))
936936
def test_detect_agent_config(self):
937937
assert isinstance(self.tracer.original_writer, AgentWriter)
938+
939+
940+
def test_tracer_custom_max_traces(monkeypatch):
941+
monkeypatch.setenv("DD_TRACE_MAX_TPS", "2000")
942+
tracer = ddtrace.Tracer()
943+
assert tracer.writer._trace_queue.maxsize == 2000

0 commit comments

Comments
 (0)