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

Support Tag Keys for DD_TRACE_HEADER_TAGS #2922

Merged
merged 8 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ static void dd_add_header_to_meta(zend_array *meta, const char *type, zend_strin
if (header_config != NULL && Z_TYPE_P(header_config) == IS_STRING) {
zend_string *header_config_str = Z_STR_P(header_config);
zend_string *headertag;
if (zend_string_equals(header_config_str, lowerheader)) {
for (char *ptr = ZSTR_VAL(header_config_str); *ptr; ++ptr) {
if (ZSTR_LEN(header_config_str) == 0) {
for (char *ptr = ZSTR_VAL(lowerheader); *ptr; ++ptr) {
if ((*ptr < 'a' || *ptr > 'z') && *ptr != '-' && (*ptr < '0' || *ptr > '9')) {
*ptr = '_';
}
}
headertag = zend_strpprintf(0, "http.%s.headers.%s", type, ZSTR_VAL(header_config_str));
headertag = zend_strpprintf(0, "http.%s.headers.%s", type, ZSTR_VAL(lowerheader));
} else {
headertag = zend_string_copy(header_config_str);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testGlobalTags()
public function testGlobalTagsWrongValueJustResultsInNoTags()
{
$this->putEnvAndReloadConfig(['DD_TAGS=wrong_key_value']);
$this->assertEquals(['wrong_key_value' => 'wrong_key_value'], \dd_trace_env_config("DD_TAGS"));
$this->assertEquals([], \dd_trace_env_config("DD_TAGS"));
}

public function testHttpHeadersDefaultsToEmpty()
Expand All @@ -284,6 +284,6 @@ public function testHttpHeadersCanSetMultiple()
// Same behavior as python tracer:
// https://github.com/DataDog/dd-trace-py/blob/f1298cb8100f146059f978b58c88641bd7424af8/ddtrace/http/headers.py
$this->assertSame(['a-header', 'any-name', 'con7aining-!spe_cial?', 'some-heather'], array_keys(\dd_trace_env_config("DD_TRACE_HEADER_TAGS")));
$this->assertEquals(['a-header' => 'a-header', 'any-name' => 'any-name', 'con7aining-!spe_cial?' => 'ch/ars', 'some-heather' => 'with-colon-Key'], \dd_trace_env_config("DD_TRACE_HEADER_TAGS"));
$this->assertEquals(['a-header' => '', 'any-name' => '', 'con7aining-!spe_cial?' => 'ch/ars', 'some-heather' => 'with-colon-Key'], \dd_trace_env_config("DD_TRACE_HEADER_TAGS"));
}
}
6 changes: 3 additions & 3 deletions zend_abstract_interface/config/config_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ static bool zai_config_decode_map(zai_str value, zval *decoded_value, bool persi
data++;
}

// Handle case without a colon (standalone key)
if (!has_colon && key_end) {
// Handle case without a colon (standalone key) only when lowercase is true which is current use case
if (lowercase && !has_colon && key_end) {
size_t key_len = key_end - key_start + 1;
zend_string *key = zend_string_init(key_start, key_len, persistent);
if (lowercase) {
zend_str_tolower(ZSTR_VAL(key), ZSTR_LEN(key));
}

zval val;
ZVAL_NEW_STR(&val, zend_string_copy(key));
ZVAL_EMPTY_STRING(&val);
zend_hash_update(Z_ARRVAL(tmp), key, &val);
zend_string_release(key);
}
Expand Down
Loading