Add http.query.string tag when enabled

Disabled by default.

Enable for http servers with:
* System Property: `dd.http.server.tag.query-string=true`
* Environment Variable: `DD_HTTP_SERVER_TAG_QUERY_STRING=true`

Enable for http clients with:
* System Property: `dd.http.client.tag.query-string=true`
* Environment Variable: `DD_HTTP_CLIENT_TAG_QUERY_STRING=true`
This commit is contained in:
Tyler Benson 2019-05-28 18:28:55 -07:00
parent e260b1d044
commit 71101ac8d0
6 changed files with 85 additions and 23 deletions

View File

@ -61,6 +61,11 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
}
Tags.HTTP_URL.set(span, urlNoParams.toString());
if (Config.get().isHttpClientTagQueryString()) {
span.setTag("http.query.string", url.getQuery());
span.setTag("http.fragment.string", url.getFragment());
}
}
} catch (final Exception e) {
log.debug("Error tagging url", e);

View File

@ -67,6 +67,11 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
}
Tags.HTTP_URL.set(span, urlNoParams.toString());
if (Config.get().isHttpServerTagQueryString()) {
span.setTag("http.query.string", url.getQuery());
span.setTag("http.fragment.string", url.getFragment());
}
}
} catch (final Exception e) {
log.debug("Error tagging url", e);

View File

@ -44,16 +44,22 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
true | [method: "test-method", url: testUrl, host: "test-host", port: 555]
}
def "test url handling"() {
def "test url handling for #url"() {
setup:
def decorator = newDecorator()
when:
decorator.onRequest(span, req)
withConfigOverride(Config.HTTP_CLIENT_TAG_QUERY_STRING, "$tagQueryString") {
decorator.onRequest(span, req)
}
then:
if (expected) {
1 * span.setTag(Tags.HTTP_URL.key, expected)
if (expectedUrl) {
1 * span.setTag(Tags.HTTP_URL.key, expectedUrl)
}
if (expectedUrl && tagQueryString) {
1 * span.setTag("http.query.string", expectedQuery)
1 * span.setTag("http.fragment.string", expectedFragment)
}
1 * span.setTag(Tags.HTTP_METHOD.key, null)
1 * span.setTag(Tags.PEER_HOSTNAME.key, null)
@ -61,13 +67,19 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
0 * _
where:
url | expected
null | null
"" | "/"
"/path?query" | "/path"
"https://host:0" | "https://host/"
"https://host/path" | "https://host/path"
"http://host:99/path?query#fragment" | "http://host:99/path"
tagQueryString | url | expectedUrl | expectedQuery | expectedFragment
false | null | null | null | null
false | "" | "/" | "" | null
false | "/path?query" | "/path" | "" | null
false | "https://host:0" | "https://host/" | "" | null
false | "https://host/path" | "https://host/path" | "" | null
false | "http://host:99/path?query#fragment" | "http://host:99/path" | "" | null
true | null | null | null | null
true | "" | "/" | null | null
true | "/path?encoded+%28query%29%3F" | "/path" | "encoded+(query)?" | null
true | "https://host:0" | "https://host/" | null | null
true | "https://host/path" | "https://host/path" | null | null
true | "http://host:99/path?query#encoded+%28fragment%29%3F" | "http://host:99/path" | "query" | "encoded+(fragment)?"
req = [url: url == null ? null : new URI(url)]
}

View File

@ -34,28 +34,40 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
[method: "test-method", url: URI.create("http://123:8080/some/path")] | "http://123:8080/some/path"
}
def "test url handling"() {
def "test url handling for #url"() {
setup:
def decorator = newDecorator()
when:
decorator.onRequest(span, req)
withConfigOverride(Config.HTTP_SERVER_TAG_QUERY_STRING, "$tagQueryString") {
decorator.onRequest(span, req)
}
then:
if (expected) {
1 * span.setTag(Tags.HTTP_URL.key, expected)
if (expectedUrl) {
1 * span.setTag(Tags.HTTP_URL.key, expectedUrl)
}
if (expectedUrl && tagQueryString) {
1 * span.setTag("http.query.string", expectedQuery)
1 * span.setTag("http.fragment.string", expectedFragment)
}
1 * span.setTag(Tags.HTTP_METHOD.key, null)
0 * _
where:
url | expected
null | null
"" | "/"
"/path?query" | "/path"
"https://host:0" | "https://host/"
"https://host/path" | "https://host/path"
"http://host:99/path?query#fragment" | "http://host:99/path"
tagQueryString | url | expectedUrl | expectedQuery | expectedFragment
false | null | null | null | null
false | "" | "/" | "" | null
false | "/path?query" | "/path" | "" | null
false | "https://host:0" | "https://host/" | "" | null
false | "https://host/path" | "https://host/path" | "" | null
false | "http://host:99/path?query#fragment" | "http://host:99/path" | "" | null
true | null | null | null | null
true | "" | "/" | null | null
true | "/path?encoded+%28query%29%3F" | "/path" | "encoded+(query)?" | null
true | "https://host:0" | "https://host/" | null | null
true | "https://host/path" | "https://host/path" | null | null
true | "http://host:99/path?query#encoded+%28fragment%29%3F" | "http://host:99/path" | "query" | "encoded+(fragment)?"
req = [url: url == null ? null : new URI(url)]
}

View File

@ -70,7 +70,9 @@ abstract class HttpClientTest<T extends HttpClientDecorator> extends AgentTestRu
@Unroll
def "basic #method request #url"() {
when:
def status = doRequest(method, server.address.resolve(url))
def status = withConfigOverride(Config.HTTP_CLIENT_TAG_QUERY_STRING, "$tagQueryString") {
doRequest(method, url)
}
then:
status == 200
@ -350,6 +352,10 @@ abstract class HttpClientTest<T extends HttpClientDecorator> extends AgentTestRu
"$Tags.HTTP_STATUS.key" status
}
"$Tags.HTTP_URL.key" "${uri.resolve(uri.path)}"
if (tagQueryString) {
"http.query.string" uri.query
"http.fragment.string" { it == null || it == uri.fragment } // Optional
}
"$Tags.PEER_HOSTNAME.key" "localhost"
"$Tags.PEER_PORT.key" uri.port
"$Tags.PEER_HOST_IPV4.key" { it == null || it == "127.0.0.1" } // Optional

View File

@ -57,6 +57,8 @@ public class Config {
public static final String HEADER_TAGS = "trace.header.tags";
public static final String HTTP_SERVER_ERROR_STATUSES = "http.server.error.statuses";
public static final String HTTP_CLIENT_ERROR_STATUSES = "http.client.error.statuses";
public static final String HTTP_SERVER_TAG_QUERY_STRING = "http.server.tag.query-string";
public static final String HTTP_CLIENT_TAG_QUERY_STRING = "http.client.tag.query-string";
public static final String HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN = "trace.http.client.split-by-domain";
public static final String PARTIAL_FLUSH_MIN_SPANS = "trace.partial.flush.min.spans";
public static final String RUNTIME_CONTEXT_FIELD_INJECTION =
@ -98,6 +100,8 @@ public class Config {
parseIntegerRangeSet("500-599", "default");
private static final Set<Integer> DEFAULT_HTTP_CLIENT_ERROR_STATUSES =
parseIntegerRangeSet("400-499", "default");
private static final boolean DEFAULT_HTTP_SERVER_TAG_QUERY_STRING = true;
private static final boolean DEFAULT_HTTP_CLIENT_TAG_QUERY_STRING = true;
private static final boolean DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN = false;
private static final int DEFAULT_PARTIAL_FLUSH_MIN_SPANS = 1000;
private static final String DEFAULT_PROPAGATION_STYLE_EXTRACT = PropagationStyle.DATADOG.name();
@ -142,6 +146,8 @@ public class Config {
@Getter private final Map<String, String> headerTags;
@Getter private final Set<Integer> httpServerErrorStatuses;
@Getter private final Set<Integer> httpClientErrorStatuses;
@Getter private final boolean httpServerTagQueryString;
@Getter private final boolean httpClientTagQueryString;
@Getter private final boolean httpClientSplitByDomain;
@Getter private final Integer partialFlushMinSpans;
@Getter private final boolean runtimeContextFieldInjection;
@ -198,6 +204,14 @@ public class Config {
getIntegerRangeSettingFromEnvironment(
HTTP_CLIENT_ERROR_STATUSES, DEFAULT_HTTP_CLIENT_ERROR_STATUSES);
httpServerTagQueryString =
getBooleanSettingFromEnvironment(
HTTP_SERVER_TAG_QUERY_STRING, DEFAULT_HTTP_SERVER_TAG_QUERY_STRING);
httpClientTagQueryString =
getBooleanSettingFromEnvironment(
HTTP_CLIENT_TAG_QUERY_STRING, DEFAULT_HTTP_CLIENT_TAG_QUERY_STRING);
httpClientSplitByDomain =
getBooleanSettingFromEnvironment(
HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN);
@ -280,6 +294,14 @@ public class Config {
getPropertyIntegerRangeValue(
properties, HTTP_CLIENT_ERROR_STATUSES, parent.httpClientErrorStatuses);
httpServerTagQueryString =
getPropertyBooleanValue(
properties, HTTP_SERVER_TAG_QUERY_STRING, parent.httpServerTagQueryString);
httpClientTagQueryString =
getPropertyBooleanValue(
properties, HTTP_CLIENT_TAG_QUERY_STRING, parent.httpClientTagQueryString);
httpClientSplitByDomain =
getPropertyBooleanValue(
properties, HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, parent.httpClientSplitByDomain);