Skip to content

Commit 115a8ab

Browse files
authored
Merge pull request #15 from bufferapp/task/do-stop-with-exception
Handle DDTrace\GlobalTracer class missing exception
2 parents 464290e + 9eb3798 commit 115a8ab

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bufferapp/php-bufflog",
33
"description": "PHP log libraries for Buffer services",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"require": {
66
"php": "^7.1",
77
"monolog/monolog": "^1.20",

src/BuffLog/BuffLog.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,21 @@ private static function enrichLog()
103103
// );
104104

105105
try {
106+
107+
if (class_exists("\DDTrace\GlobalTracer", false) === false) {
108+
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?');
109+
}
110+
106111
// Add traces information to be able to correlate logs with APM
107112
$ddTraceSpan = \DDTrace\GlobalTracer::get()->getActiveSpan();
108113
$record['context']['dd'] = [
109114
"trace_id" => $ddTraceSpan->getTraceId(),
110115
"span_id" => $ddTraceSpan->getSpanId()
111116
];
112117

113-
} catch (Exception $e) {
114-
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?");
118+
} catch (\Exception $e) {
119+
// we probably will want to make an no-op or it will be too verbose
120+
error_log($e->getMessage() . " Traces will not be added in the logs");
115121
}
116122

117123
return $record;

0 commit comments

Comments
 (0)