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(tracing): support http server error status configuration #10723

Merged
merged 10 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion ddtrace/settings/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class Config(object):
"""

class _HTTPServerConfig(object):
_error_statuses = "500-599" # type: str
_error_statuses = os.getenv("DD_TRACE_HTTP_SERVER_ERROR_STATUSES", "500-599") # type: str
mabdinur marked this conversation as resolved.
Show resolved Hide resolved
_error_ranges = get_error_ranges(_error_statuses) # type: List[Tuple[int, int]]

@property
Expand Down
8 changes: 8 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,14 @@ 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_HTTP_SERVER_ERROR_STATUSES:
type: String
default: "500-599"
description: |
Comma-separated list of HTTP status codes that should be considered errors when returned by an HTTP request.
Multiple comma separated error ranges can be set (ex: ``200,400-404,500-599``).
The status codes are used to set the ``error`` field on the span.
mabdinur marked this conversation as resolved.
Show resolved Hide resolved

DD_TRACE_METHODS:
type: String
default: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
tracing: Adds ``DD_TRACE_HTTP_CLIENT_ERROR_STATUSES`` environment variable to configure the list of HTTP status codes that should be considered errors when instrumenting HTTP severs.
20 changes: 20 additions & 0 deletions tests/tracer/test_trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,26 @@ def test_set_http_meta_custom_errors(mock_log, span, int_config, error_codes, st
mock_log.exception.assert_not_called()


@pytest.mark.subprocess(env={"DD_TRACE_HTTP_SERVER_ERROR_STATUSES": "404-412"})
def test_set_http_meta_custom_errors_via_env():
from ddtrace import config
from ddtrace import tracer
from ddtrace.contrib.trace_utils import set_http_meta

config._add("myint", dict())
with tracer.trace("error") as span1:
set_http_meta(span1, config.myint, status_code=405)
assert span1.error == 1

with tracer.trace("noterror") as span2:
set_http_meta(span2, config.myint, status_code=403)
assert span2.error == 0
mabdinur marked this conversation as resolved.
Show resolved Hide resolved

with tracer.trace("noterror2") as span3:
set_http_meta(span3, config.myint, status_code=413)
assert span3.error == 0


@mock.patch("ddtrace.contrib.trace_utils._store_headers")
def test_set_http_meta_no_headers(mock_store_headers, span, int_config):
assert int_config.myint.is_header_tracing_configured is False
Expand Down
Loading