Skip to content

Commit e72a778

Browse files
committed
upgrade dd-trace
1 parent 5a63fde commit e72a778

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "bufferapp/php-bufflog",
33
"description": "PHP log libraries for Buffer services",
4-
"version": "0.3.3",
4+
"version": "0.4.0",
55
"require": {
66
"php": ">=8.1",
77
"monolog/monolog": "^3.2",
88
"psr/log": "^2.0 || ^3.0"
99
},
1010
"require-dev": {
11-
"datadog/dd-trace": "0.82.*"
11+
"datadog/dd-trace": "^1.13.0"
1212
},
1313
"autoload": {
1414
"psr-4": {

src/BuffLog/BuffLog.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class BuffLog {
1616
// verbosity can be changed with setting this env var
1717
public static $logLevelEnvVar = "LOG_LEVEL";
1818

19-
// Global Tracer comes with the datadog tracing extension
20-
private static $hasGlobalTracer = false;
21-
2219
// we can use strtolower(Logger::getLevels()) instead
2320
private static $logOutputMethods = ['debug', 'info', 'notice', 'warning', 'error', 'critical'];
2421

@@ -41,13 +38,12 @@ static public function getLogger()
4138
protected static function configureInstance()
4239
{
4340

44-
if (class_exists("\DDTrace\GlobalTracer")) {
45-
self::$hasGlobalTracer = true;
46-
} else {
41+
// Check if DDTrace functions are available and warn if not
42+
if (!function_exists("\DDTrace\logs_correlation_trace_id")) {
4743
// local envs don't need tracing
4844
if (getenv("ENVIRONMENT") !== "local") {
4945
echo json_encode([
50-
"message" => "Can't find \DDTrace\GlobalTracer class. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier. If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?",
46+
"message" => "Can't find DDTrace functions. Did you install the Datadog APM tracer extension? It will allow you to have logs enriched with traces making troubleshooting easier. If you run a cli mode service (such as a worker), did you set the DD_TRACE_CLI_ENABLED env variable?",
5147
"level" => 300,
5248
"level_name" => "WARNING",
5349
"context" => ["bufflog_error" => "no_tracer"]
@@ -87,15 +83,13 @@ protected static function configureInstance()
8783
// 'profileID' => $user->getProfileID()
8884
// );
8985

90-
if (self::$hasGlobalTracer) {
86+
// Add traces information to correlate logs with APM
87+
if (function_exists('\DDTrace\logs_correlation_trace_id') && function_exists('\dd_trace_peek_span_id')) {
9188
try {
92-
// Add traces information to be able to correlate logs with APM
93-
$ddTraceSpan = \DDTrace\GlobalTracer::get()->getActiveSpan();
94-
$record['context']['dd'] = [
95-
"trace_id" => $ddTraceSpan->getTraceId(),
96-
"span_id" => $ddTraceSpan->getSpanId()
89+
$record->extra['dd'] = [
90+
'trace_id' => \DDTrace\logs_correlation_trace_id(),
91+
'span_id' => \dd_trace_peek_span_id()
9792
];
98-
9993
} catch (\Exception $e) {
10094
// no-op
10195
}

0 commit comments

Comments
 (0)