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

[WIP] Handle multi-value tagging for server spans #7977

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,12 @@ public ResponseHeaderTagClassifier(AgentSpan span, Map<String, String> headerTag
public boolean accept(String key, String value) {
String mappedKey = headerTags.get(key.toLowerCase(Locale.ROOT));
if (mappedKey != null) {
span.setTag(mappedKey, value);
Object existing_val = span.getTag(mappedKey);
if (existing_val == null) {
span.setTag(mappedKey, value);
} else {
span.setTag(mappedKey, existing_val.toString() + value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, you might need to ensure the existing value is a String, otherwise you might end up with weird values calling toString().
Then, aren't the multiple header values supposed to be coma-separated? (I honestly don't know but I am curious about just being able to concatenate them 🤔 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,44 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
'GET' | null | 'x-datadog-test-request-header' | 'bar' | [ 'request_header_tag': 'bar' ]
}

def "test response header tag mapping"() {
setup:
assumeTrue(testResponseHeadersMapping() && testEncodedQuery())
def endpoint = QUERY_ENCODED_BOTH
def method = 'GET'
def body = null
def header = 'response_header_tag'
def mapping = 'mapped_response_header_tag'
def tags = ['mapped_response_header_tag': 'response_header_value' ]
def more_tags = ['mapped_response_header_tag': "another_response_header_value" ]

injectSysConfig(HTTP_SERVER_TAG_QUERY_STRING, "true")
injectSysConfig(RESPONSE_HEADER_TAGS, "$header:$mapping")
def request = request(endpoint, method, body)
.build()
def response = client.newCall(request).execute()

expect:
response.code() == endpoint.status
response.body().string() == endpoint.body

and:
assertTraces(1) {
trace(spanCount(endpoint)) {
sortSpansByStart()
serverSpan(it, null, null, method, endpoint, tags)
serverSpan(it, null, null, method, endpoint, more_tags) // ...
if (hasHandlerSpan()) {
handlerSpan(it, endpoint)
}
controllerSpan(it)
if (hasResponseSpan(endpoint)) {
responseSpan(it, endpoint)
}
}
}
}

@Flaky(value = "https://github.com/DataDog/dd-trace-java/issues/4690", suites = ["MuleHttpServerForkedTest"])
def "test QUERY_ENCODED_BOTH with response header x-ig-response-header tag mapping"() {
setup:
Expand Down
Loading