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:
parent
e260b1d044
commit
71101ac8d0
|
@ -61,6 +61,11 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
||||||
}
|
}
|
||||||
|
|
||||||
Tags.HTTP_URL.set(span, urlNoParams.toString());
|
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) {
|
} catch (final Exception e) {
|
||||||
log.debug("Error tagging url", e);
|
log.debug("Error tagging url", e);
|
||||||
|
|
|
@ -67,6 +67,11 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
||||||
}
|
}
|
||||||
|
|
||||||
Tags.HTTP_URL.set(span, urlNoParams.toString());
|
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) {
|
} catch (final Exception e) {
|
||||||
log.debug("Error tagging url", e);
|
log.debug("Error tagging url", e);
|
||||||
|
|
|
@ -44,16 +44,22 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
||||||
true | [method: "test-method", url: testUrl, host: "test-host", port: 555]
|
true | [method: "test-method", url: testUrl, host: "test-host", port: 555]
|
||||||
}
|
}
|
||||||
|
|
||||||
def "test url handling"() {
|
def "test url handling for #url"() {
|
||||||
setup:
|
setup:
|
||||||
def decorator = newDecorator()
|
def decorator = newDecorator()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
decorator.onRequest(span, req)
|
withConfigOverride(Config.HTTP_CLIENT_TAG_QUERY_STRING, "$tagQueryString") {
|
||||||
|
decorator.onRequest(span, req)
|
||||||
|
}
|
||||||
|
|
||||||
then:
|
then:
|
||||||
if (expected) {
|
if (expectedUrl) {
|
||||||
1 * span.setTag(Tags.HTTP_URL.key, expected)
|
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.HTTP_METHOD.key, null)
|
||||||
1 * span.setTag(Tags.PEER_HOSTNAME.key, null)
|
1 * span.setTag(Tags.PEER_HOSTNAME.key, null)
|
||||||
|
@ -61,13 +67,19 @@ class HttpClientDecoratorTest extends ClientDecoratorTest {
|
||||||
0 * _
|
0 * _
|
||||||
|
|
||||||
where:
|
where:
|
||||||
url | expected
|
tagQueryString | url | expectedUrl | expectedQuery | expectedFragment
|
||||||
null | null
|
false | null | null | null | null
|
||||||
"" | "/"
|
false | "" | "/" | "" | null
|
||||||
"/path?query" | "/path"
|
false | "/path?query" | "/path" | "" | null
|
||||||
"https://host:0" | "https://host/"
|
false | "https://host:0" | "https://host/" | "" | null
|
||||||
"https://host/path" | "https://host/path"
|
false | "https://host/path" | "https://host/path" | "" | null
|
||||||
"http://host:99/path?query#fragment" | "http://host:99/path"
|
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)]
|
req = [url: url == null ? null : new URI(url)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,28 +34,40 @@ class HttpServerDecoratorTest extends ServerDecoratorTest {
|
||||||
[method: "test-method", url: URI.create("http://123:8080/some/path")] | "http://123:8080/some/path"
|
[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:
|
setup:
|
||||||
def decorator = newDecorator()
|
def decorator = newDecorator()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
decorator.onRequest(span, req)
|
withConfigOverride(Config.HTTP_SERVER_TAG_QUERY_STRING, "$tagQueryString") {
|
||||||
|
decorator.onRequest(span, req)
|
||||||
|
}
|
||||||
|
|
||||||
then:
|
then:
|
||||||
if (expected) {
|
if (expectedUrl) {
|
||||||
1 * span.setTag(Tags.HTTP_URL.key, expected)
|
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.HTTP_METHOD.key, null)
|
||||||
0 * _
|
0 * _
|
||||||
|
|
||||||
where:
|
where:
|
||||||
url | expected
|
tagQueryString | url | expectedUrl | expectedQuery | expectedFragment
|
||||||
null | null
|
false | null | null | null | null
|
||||||
"" | "/"
|
false | "" | "/" | "" | null
|
||||||
"/path?query" | "/path"
|
false | "/path?query" | "/path" | "" | null
|
||||||
"https://host:0" | "https://host/"
|
false | "https://host:0" | "https://host/" | "" | null
|
||||||
"https://host/path" | "https://host/path"
|
false | "https://host/path" | "https://host/path" | "" | null
|
||||||
"http://host:99/path?query#fragment" | "http://host:99/path"
|
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)]
|
req = [url: url == null ? null : new URI(url)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,9 @@ abstract class HttpClientTest<T extends HttpClientDecorator> extends AgentTestRu
|
||||||
@Unroll
|
@Unroll
|
||||||
def "basic #method request #url"() {
|
def "basic #method request #url"() {
|
||||||
when:
|
when:
|
||||||
def status = doRequest(method, server.address.resolve(url))
|
def status = withConfigOverride(Config.HTTP_CLIENT_TAG_QUERY_STRING, "$tagQueryString") {
|
||||||
|
doRequest(method, url)
|
||||||
|
}
|
||||||
|
|
||||||
then:
|
then:
|
||||||
status == 200
|
status == 200
|
||||||
|
@ -350,6 +352,10 @@ abstract class HttpClientTest<T extends HttpClientDecorator> extends AgentTestRu
|
||||||
"$Tags.HTTP_STATUS.key" status
|
"$Tags.HTTP_STATUS.key" status
|
||||||
}
|
}
|
||||||
"$Tags.HTTP_URL.key" "${uri.resolve(uri.path)}"
|
"$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_HOSTNAME.key" "localhost"
|
||||||
"$Tags.PEER_PORT.key" uri.port
|
"$Tags.PEER_PORT.key" uri.port
|
||||||
"$Tags.PEER_HOST_IPV4.key" { it == null || it == "127.0.0.1" } // Optional
|
"$Tags.PEER_HOST_IPV4.key" { it == null || it == "127.0.0.1" } // Optional
|
||||||
|
|
|
@ -57,6 +57,8 @@ public class Config {
|
||||||
public static final String HEADER_TAGS = "trace.header.tags";
|
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_SERVER_ERROR_STATUSES = "http.server.error.statuses";
|
||||||
public static final String HTTP_CLIENT_ERROR_STATUSES = "http.client.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 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 PARTIAL_FLUSH_MIN_SPANS = "trace.partial.flush.min.spans";
|
||||||
public static final String RUNTIME_CONTEXT_FIELD_INJECTION =
|
public static final String RUNTIME_CONTEXT_FIELD_INJECTION =
|
||||||
|
@ -98,6 +100,8 @@ public class Config {
|
||||||
parseIntegerRangeSet("500-599", "default");
|
parseIntegerRangeSet("500-599", "default");
|
||||||
private static final Set<Integer> DEFAULT_HTTP_CLIENT_ERROR_STATUSES =
|
private static final Set<Integer> DEFAULT_HTTP_CLIENT_ERROR_STATUSES =
|
||||||
parseIntegerRangeSet("400-499", "default");
|
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 boolean DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN = false;
|
||||||
private static final int DEFAULT_PARTIAL_FLUSH_MIN_SPANS = 1000;
|
private static final int DEFAULT_PARTIAL_FLUSH_MIN_SPANS = 1000;
|
||||||
private static final String DEFAULT_PROPAGATION_STYLE_EXTRACT = PropagationStyle.DATADOG.name();
|
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 Map<String, String> headerTags;
|
||||||
@Getter private final Set<Integer> httpServerErrorStatuses;
|
@Getter private final Set<Integer> httpServerErrorStatuses;
|
||||||
@Getter private final Set<Integer> httpClientErrorStatuses;
|
@Getter private final Set<Integer> httpClientErrorStatuses;
|
||||||
|
@Getter private final boolean httpServerTagQueryString;
|
||||||
|
@Getter private final boolean httpClientTagQueryString;
|
||||||
@Getter private final boolean httpClientSplitByDomain;
|
@Getter private final boolean httpClientSplitByDomain;
|
||||||
@Getter private final Integer partialFlushMinSpans;
|
@Getter private final Integer partialFlushMinSpans;
|
||||||
@Getter private final boolean runtimeContextFieldInjection;
|
@Getter private final boolean runtimeContextFieldInjection;
|
||||||
|
@ -198,6 +204,14 @@ public class Config {
|
||||||
getIntegerRangeSettingFromEnvironment(
|
getIntegerRangeSettingFromEnvironment(
|
||||||
HTTP_CLIENT_ERROR_STATUSES, DEFAULT_HTTP_CLIENT_ERROR_STATUSES);
|
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 =
|
httpClientSplitByDomain =
|
||||||
getBooleanSettingFromEnvironment(
|
getBooleanSettingFromEnvironment(
|
||||||
HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN);
|
HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN);
|
||||||
|
@ -280,6 +294,14 @@ public class Config {
|
||||||
getPropertyIntegerRangeValue(
|
getPropertyIntegerRangeValue(
|
||||||
properties, HTTP_CLIENT_ERROR_STATUSES, parent.httpClientErrorStatuses);
|
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 =
|
httpClientSplitByDomain =
|
||||||
getPropertyBooleanValue(
|
getPropertyBooleanValue(
|
||||||
properties, HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, parent.httpClientSplitByDomain);
|
properties, HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, parent.httpClientSplitByDomain);
|
||||||
|
|
Loading…
Reference in New Issue