Skip to content

Commit 610fb2b

Browse files
committed
Add test for DD_TRACE_LOG_FILE
Signed-off-by: Bob Weinand <[email protected]>
1 parent 33d7046 commit 610fb2b

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

appsec/tests/integration/src/main/groovy/com/datadog/appsec/php/docker/AppSecContainer.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class AppSecContainer<SELF extends AppSecContainer<SELF>> extends GenericContain
7070
withEnv 'DD_TRACE_ENABLED', '1'
7171
withEnv 'DD_SERVICE', 'appsec_int_tests'
7272
withEnv 'DD_ENV', 'integration'
73+
withEnv 'DD_TRACE_LOG_LEVEL', 'info,startup=off'
7374
withEnv 'DD_TRACE_AGENT_FLUSH_AFTER_N_REQUESTS', '0'
7475
withEnv 'DD_TRACE_AGENT_FLUSH_INTERVAL', '0'
7576
withEnv 'DD_TRACE_DEBUG', '1'

ext/logging.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ int ddtrace_get_fd_path(int fd, char *buf) {
7575
#else
7676
char pathbuf[PATH_MAX];
7777
snprintf(pathbuf, PATH_MAX, "/proc/self/fd/%d", fd);
78-
return readlink(pathbuf, buf, PATH_MAX);
78+
int len = readlink(pathbuf, buf, PATH_MAX);
79+
if (len >= 0) {
80+
buf[len] = 0;
81+
}
82+
return len;
7983
#endif
8084
}
8185

@@ -109,7 +113,7 @@ int ddtrace_log_with_time(int fd, const char *msg, int msg_len) {
109113

110114
uintmax_t last_check = atomic_exchange(&dd_error_log_fd_rotated, (uintmax_t) now);
111115
if (last_check < (uintmax_t)now - 60) { // 1x/min
112-
char pathbuf[PATH_MAX];
116+
char pathbuf[PATH_MAX + 1];
113117
if (ddtrace_get_fd_path(fd, pathbuf) >= 0) {
114118
int new_fd = VCWD_OPEN_MODE(pathbuf, O_CREAT | O_RDWR | O_APPEND, 0666);
115119
dup2(new_fd, fd); // atomic replace

ext/sidecar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void ddtrace_set_sidecar_globals(void) {
2020
}
2121

2222
static bool dd_sidecar_connection_init(void) {
23-
char logpath[PATH_MAX];
23+
char logpath[PATH_MAX + 1];
2424
int error_fd = atomic_load(&ddtrace_error_log_fd);
2525
if (error_fd == -1 || ddtrace_get_fd_path(error_fd, logpath) < 0) {
2626
*logpath = 0;

libdatadog

tests/ext/dd_trace_log_file.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Using DD_TRACE_LOG_FILE
3+
--SKIPIF--
4+
<?php
5+
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}");
6+
?>
7+
--INI--
8+
datadog.trace.log_file={PWD}/dd_trace_log_file.log
9+
datadog.trace.log_level="Off,span=Trace"
10+
datadog.trace.generate_root_span=0
11+
--FILE--
12+
<?php
13+
14+
readfile(__DIR__ . "/dd_trace_log_file.log");
15+
16+
?>
17+
--EXPECTF--
18+
[%s] [ddtrace] [span] Creating new root SpanStack: %d, parent_stack: 0
19+
--CLEAN--
20+
<?php @unlink(__DIR__ . "/dd_trace_log_file.log"); ?>

0 commit comments

Comments
 (0)