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

SyncEmitter produce output in debug mode #271

Closed
1 task done
cadic opened this issue May 12, 2022 · 5 comments · Fixed by #272 or #274
Closed
1 task done

SyncEmitter produce output in debug mode #271

cadic opened this issue May 12, 2022 · 5 comments · Fixed by #272 or #274
Assignees
Milestone

Comments

@cadic
Copy link
Contributor

cadic commented May 12, 2022

Describe the bug

Initially reported in Mather-Sophi/sp-debug-bar-for-sophi#13

Happens when

sophi_tracker_emitter_debug is true (f.e. using Debug Bar for Sophi plugin)
AND
The directory vendor/snowplow/snowplow-tracker/debug isn't writable

When the SyncEmitter being created with $debug = true attribute, it will also try to write logs in the hardcoded path:

https://github.com/snowplow/snowplow-php-tracker/blob/32a08e9a7c25d1c51621751e1cdfcffcdef6cfe5/src/Emitter.php#L377-L379

If the path is not writable, Emitter will print the debug information

https://github.com/snowplow/snowplow-php-tracker/blob/32a08e9a7c25d1c51621751e1cdfcffcdef6cfe5/src/Emitter.php#L60-L65

Steps to Reproduce

Refer to the initial report: Mather-Sophi/sp-debug-bar-for-sophi#13

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@cadic cadic added this to the 1.1.1 milestone May 12, 2022
@cadic cadic self-assigned this May 12, 2022
@cadic
Copy link
Contributor Author

cadic commented May 12, 2022

I see 2 possible solutions:

1. Extend SyncEmitter

class SophiEmitter extends Snowplow\Tracker\Emitters\SyncEmitter {
    const DEBUG_LOG_FILES = false;
}

then replace SyncEmitter with SophiEmitter here:

https://github.com/globeandmail/sophi-for-wordpress/blob/93e5495bae6b0222ef0034c3af18e761f39680ca/includes/functions/content-sync.php#L214

2. Suppress all output in debug mode

Add a conditional ob_start / ob_end_clean wrapper for $tracker->trackUnstructEvent in:

https://github.com/globeandmail/sophi-for-wordpress/blob/93e5495bae6b0222ef0034c3af18e761f39680ca/includes/functions/content-sync.php#L148

@cadic
Copy link
Contributor Author

cadic commented May 12, 2022

Solution 1 will not work: the Snowplow\Tracker\Emitter is using self::DEBUG_LOG_FILES to read the const, in this case it always be true, as it was initially set in the parent class declaration

if (self::DEBUG_LOG_FILES) {
	if ($this->initDebug($type) !== true) {
		$this->write_perms = false;
		print_r("Unable to create debug log files: invalid write permissions.");
	}
}

@cadic
Copy link
Contributor Author

cadic commented May 12, 2022

Looks like it's still possible to extend SyncEmitter and overload it's makeDir and other file methods to fake write failure since we don't want any uncontrolled logging from the 3rd party.

@cadic
Copy link
Contributor Author

cadic commented May 12, 2022

So, as the result, we need to combine both solutions:

  1. Extending SyncEmitter with overloaded file methods will suppress writing log files if the vendor/snowplow/snowplow-tracker/debug is writable
  2. Adding ob_start / ob_end_clean wrapper for $tracker->trackUnstructEvent() will suppress stdout if the directory is not writable.

@jeffpaul
Copy link
Contributor

@cadic great triage on this, similarly confirming this also impacts publishing (not just updating as Mather-Sophi/sp-debug-bar-for-sophi#13 notes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants