Skip to content

Commit

Permalink
improve priority info
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-papazian committed Mar 1, 2024
1 parent 566bafc commit 705fd7d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ddtrace/appsec/_api_security/api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from typing import Optional

from ddtrace import constants
from ddtrace._trace._limits import MAX_SPAN_META_VALUE_LEN
from ddtrace.appsec import _processor as appsec_processor
from ddtrace.appsec._asm_request_context import add_context_callback
Expand Down Expand Up @@ -126,10 +127,20 @@ def _schema_callback(self, env):
return

try:
if not self._should_collect_schema(env, env.span.context.sampling_priority):
# check both current span and root span for sampling priority
# if any of them is set to USER_KEEP or USER_REJECT, we should respect it
priorities = (root.context.sampling_priority or 0, env.span.context.sampling_priority or 0)
if constants.USER_KEEP in priorities:
priority = constants.USER_KEEP
elif constants.USER_REJECT in priorities:
priority = constants.USER_REJECT
else:
priority = max(priorities)
if not self._should_collect_schema(env, priority):
return
except Exception:
log.warning("Failed to sample request for schema generation", exc_info=True)
return

# we need the request content type on the span
try:
Expand Down

0 comments on commit 705fd7d

Please sign in to comment.