Skip to content

Handle DDTrace\GlobalTracer class missing exception #15

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

Merged
merged 1 commit into from
Feb 13, 2020
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bufferapp/php-bufflog",
"description": "PHP log libraries for Buffer services",
"version": "0.1.3",
"version": "0.1.4",
"require": {
"php": "^7.1",
"monolog/monolog": "^1.20",
Expand Down
10 changes: 8 additions & 2 deletions src/BuffLog/BuffLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,21 @@ private static function enrichLog()
// );

try {

if (class_exists("\DDTrace\GlobalTracer", false) === false) {
throw new \Exception('DDTrace\GlobalTracer can\'t be found. Have you setup the Datadog Tracer extension? If you run cli worker, have you added the DD_TRACE_CLI_ENABLED env variable?');
}

// Add traces information to be able to correlate logs with APM
$ddTraceSpan = \DDTrace\GlobalTracer::get()->getActiveSpan();
$record['context']['dd'] = [
"trace_id" => $ddTraceSpan->getTraceId(),
"span_id" => $ddTraceSpan->getSpanId()
];

} catch (Exception $e) {
error_log($e->getMessage() . " Can't add trace to logs. Have you setup the Datadog Tracer extension? If you run a worker have your added the DD_TRACE_CLI_ENABLED env variable?");
} catch (\Exception $e) {
// we probably will want to make an no-op or it will be too verbose
error_log($e->getMessage() . " Traces will not be added in the logs");
}

return $record;
Expand Down