Skip to content

Commit

Permalink
Merge branch 'master' into levi-and-florian/fix-generator-create-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonlevi committed Nov 20, 2023
2 parents 3ac16f6 + dc23b0c commit ea2e364
Show file tree
Hide file tree
Showing 260 changed files with 9,566 additions and 663 deletions.
9 changes: 8 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Default owners
* @DataDog/apm-php
Cargo.lock @DataDog/apm-php @DataDog/profiling-php

# Profiling team
/profiling/ @DataDog/profiling-php

# ASM Team
/appsec/ @DataDog/asm-php

# Release files
Cargo.lock @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
package.xml @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
profiling/Cargo.toml @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
src/DDTrace/Tracer.php @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
appsec/CMakeLists.txt @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
ext/version.h @DataDog/apm-php @DataDog/profiling-php @Datadog/asm-php
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ TEST_INTEGRATIONS_74 := \
test_integrations_monolog1 \
test_integrations_monolog2 \
test_integrations_mysqli \
test_opentelemetry_1 \
test_integrations_pdo \
test_integrations_elasticsearch7 \
test_integrations_elasticsearch8 \
Expand Down Expand Up @@ -755,6 +756,7 @@ TEST_INTEGRATIONS_80 := \
test_integrations_monolog1 \
test_integrations_monolog2 \
test_integrations_mysqli \
test_opentelemetry_1 \
test_integrations_pdo \
test_integrations_elasticsearch7 \
test_integrations_guzzle5 \
Expand Down Expand Up @@ -802,6 +804,7 @@ TEST_INTEGRATIONS_81 := \
test_integrations_monolog2 \
test_integrations_monolog3 \
test_integrations_mysqli \
test_opentelemetry_1 \
test_integrations_guzzle7 \
test_integrations_pcntl \
test_integrations_pdo \
Expand Down Expand Up @@ -847,6 +850,7 @@ TEST_INTEGRATIONS_82 := \
test_integrations_monolog2 \
test_integrations_monolog3 \
test_integrations_mysqli \
test_opentelemetry_1 \
test_integrations_guzzle7 \
test_integrations_pcntl \
test_integrations_pdo \
Expand Down Expand Up @@ -950,6 +954,11 @@ test_distributed_tracing: global_test_run_dependencies
test_metrics: global_test_run_dependencies
$(call run_tests,--testsuite=metrics $(TESTS))

test_opentelemetry_1: global_test_run_dependencies
rm -f tests/.scenarios.lock/opentelemetry1/composer.lock
$(MAKE) test_scenario_opentelemetry1
$(shell [ $(PHP_MAJOR_MINOR) -ge 81 ] && echo "OTEL_PHP_FIBERS_ENABLED=1" || echo "") DD_TRACE_OTEL_ENABLED=1 DD_TRACE_GENERATE_ROOT_SPAN=0 $(call run_tests,--testsuite=opentelemetry1 $(TESTS))

test_opentracing_beta5: global_test_run_dependencies
$(MAKE) test_scenario_opentracing_beta5
$(call run_tests,tests/OpenTracerUnit)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![CircleCI](https://circleci.com/gh/DataDog/dd-trace-php/tree/master.svg?style=svg)](https://circleci.com/gh/DataDog/dd-trace-php/tree/master)
[![CodeCov](https://codecov.io/gh/DataDog/dd-trace-php/branch/master/graph/badge.svg?token=eXio8H7vwF)](https://codecov.io/gh/DataDog/dd-trace-php)
[![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
[![OpenTelemetry Badge](https://img.shields.io/badge/OpenTelemetry-enabled-blue.svg)](https://opentelemetry.io)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.4-8892BF.svg)](https://php.net/)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](LICENSE)
[![Packagist Version](https://img.shields.io/packagist/v/datadog/dd-trace.svg)](https://packagist.org/packages/datadog/dd-trace)
Expand Down
2 changes: 1 addition & 1 deletion appsec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ HunterGate(

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hunter-cache.id.in ${CMAKE_CURRENT_SOURCE_DIR}/hunter-cache.id)

project(ddappsec VERSION 0.93.0)
project(ddappsec VERSION 0.94.0)

include(CheckCXXCompilerFlag)

Expand Down
5 changes: 3 additions & 2 deletions appsec/tests/extension/client_init_record_span_tags.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ tags:
Array
(
[_dd.appsec.json] => {"triggers":[{"found":"attack"},{"another":"attack"},{"yet another":"attack"}]}
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
[_dd.runtime_family] => php
[appsec.event] => true
[http.method] => GET
Expand All @@ -105,7 +106,7 @@ Array
[metric_1] => 2
[metric_2] => 10
[_dd.appsec.enabled] => 1
[_dd.rule_psr] => 1
[_dd.agent_psr] => 1
[_sampling_priority_v1] => 1
[php.compilation.total_time_ms] => %f
)
7 changes: 4 additions & 3 deletions appsec/tests/extension/ddtrace_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ echo 'number of commands: ', count($c), "\n";

DDTrace\start_span();

// Compatibility with pre 0.81.0
// Compatibility with pre 0.81.0
$root_span = \DDTrace\root_span();
var_dump($root_span->name);
var_dump($root_span->service);
Expand All @@ -53,7 +53,7 @@ var_dump($root_span->id);
var_dump($root_span->meta);
var_dump($root_span->metrics);

$trace_id = \DDTrace\trace_id();
$trace_id = \DDTrace\root_span()->id;
echo 'trace id: ', $trace_id, "\n";

echo "ddtrace_rshutdown\n";
Expand Down Expand Up @@ -103,5 +103,6 @@ Array
(
[runtime-id] => %s
[ddappsec] => true
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
)
26 changes: 26 additions & 0 deletions appsec/tests/extension/extension_no_static_tls.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Extension is not compiled with STATIC_TLS
--SKIPIF--
<?php
exec('command -v readelf', $garbage, $r);
if ($r != 0) { die('skip: no readelf command'); }
if (!file_exists('/proc/self/maps')) { die('skip: no /proc/self/maps'); }
?>
--FILE--
<?php

$maps = file_get_contents('/proc/self/maps');
if (preg_match('@(?<=\\s)\\S*/ddappsec\\.so$@m', $maps, $m) != 1) {
die('cannot find loaded ddappsec.so');
}

$ddappsec_so = $m[0];
exec('readelf -d ' . escapeshellarg($ddappsec_so) . ' | grep STATIC_TLS', $garbage, $r);

if ($r == 0) {
echo "Found STATIC_TLS\n";
} else {
echo "STATIC_TLS not found (OK)\n";
}
--EXPECT--
STATIC_TLS not found (OK)
5 changes: 3 additions & 2 deletions appsec/tests/extension/rinit_record_span_tags.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ tags:
Array
(
[_dd.appsec.json] => {"triggers":[{"found":"attack"},{"another":"attack"},{"yet another":"attack"}]}
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
[_dd.runtime_family] => php
[appsec.event] => true
[http.method] => GET
Expand All @@ -98,7 +99,7 @@ Array
[%s] => %d
[rshutdown_metric] => 2.1
[_dd.appsec.enabled] => 1
[_dd.rule_psr] => 1
[_dd.agent_psr] => 1
[_sampling_priority_v1] => 1
[php.compilation.total_time_ms] => %f
)
3 changes: 2 additions & 1 deletion appsec/tests/extension/rinit_record_span_tags_fail.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ tags:
Array
(
[runtime-id] => %s
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
)
3 changes: 2 additions & 1 deletion appsec/tests/extension/rinit_root_span_add_tag.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ bool(true)
tags:
Array
(
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
[ddappsec] => true
[env] => staging
[http.method] => GET
Expand Down
8 changes: 5 additions & 3 deletions appsec/tests/extension/root_span_add_tag.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ array(1) {
["type"]=>
string(3) "cli"
["meta"]=>
array(3) {
array(4) {
["runtime-id"]=>
string(%d) %s
["after"]=>
string(9) "root_span"
["_dd.p.dm"]=>
string(2) "-1"
string(2) "-0"
["_dd.p.tid"]=>
string(16) "%s"
}
["metrics"]=>
array(4) {
[%s"]=>
float(%d)
["_dd.rule_psr"]=>
["_dd.agent_psr"]=>
float(1)
["_sampling_priority_v1"]=>
float(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ int(2)
tags:
Array
(
[_dd.p.dm] => -1
[_dd.p.dm] => -0
[_dd.p.tid] => %s
[_dd.runtime_family] => php
[after] => root_span
[before] => root_span
Expand All @@ -80,7 +81,7 @@ Array
(
[process_id] => %d
[_dd.appsec.enabled] => 1
[_dd.rule_psr] => 1
[_dd.agent_psr] => 1
[_sampling_priority_v1] => 1
[php.compilation.total_time_ms] => %s
)
1 change: 1 addition & 0 deletions bridge/_files_integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
__DIR__ . '/../src/Integrations/Integrations/WordPress/V1/WordPressIntegrationLoader.php',
__DIR__ . '/../src/Integrations/Integrations/WordPress/V2/WordPressIntegrationLoader.php',
__DIR__ . '/../src/Integrations/Integrations/ZendFramework/ZendFrameworkIntegration.php',
__DIR__ . '/../src/Integrations/Util/Convention.php',
__DIR__ . '/../src/Integrations/Util/Runtime.php',
__DIR__ . '/../src/Integrations/Util/Versions.php',
__DIR__ . '/../src/Integrations/Util/ObjectKVStore.php',
Expand Down
30 changes: 27 additions & 3 deletions bridge/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// internal userland classes and loaded by composer;
// - automatic instrumentation runs before it is known that composer exists, and after any `opcache.preload` script;


// Do not trigger the autoloading mechanism if the class is not defined, so 'terminal' autoloaders - that trigger
// errors if a class was not found - are supported.
// - Class `DDTrace\ComposerBootstrap` is declared in `src/api/ComposerBootstrap.php` and it is loaded when the
Expand All @@ -36,8 +35,10 @@
spl_autoload_register(function ($class) use ($apiLoadedViaComposerClass) {
// If $class is not a DDTrace class, move quickly to the next autoloader
$prefix = 'DDTrace\\';
$openTelemetry = 'OpenTelemetry\\';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
$otelLen = strlen($openTelemetry);
if (strncmp($prefix, $class, $len) !== 0 && strncmp($openTelemetry, $class, $otelLen) !== 0) {
// move to the next registered autoloader
return;
}
Expand Down Expand Up @@ -96,8 +97,10 @@
spl_autoload_register(function ($class) use ($tracerFiles, $tracerFilesWithComposerLoaded, $apiLoadedViaComposerClass) {
// If $class is not a DDTrace class, move quickly to the next autoloader
$prefix = 'DDTrace\\';
$openTelemetry = 'OpenTelemetry\\';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
$otelLen = strlen($openTelemetry);
if (strncmp($prefix, $class, $len) !== 0 && strncmp($openTelemetry, $class, $otelLen) !== 0) {
// move to the next registered autoloader
return;
}
Expand All @@ -116,6 +119,27 @@
}
});

if (function_exists('DDTrace\\install_hook')) {
\DDTrace\install_hook(
'Composer\Autoload\ClassLoader::register',
null,
function (\DDTrace\HookData $hook) {
$args = $hook->args;
if (!empty($args)) {
$prepend = $args[0];
if ($prepend) {
// We need to unregister and register dd's autoload, prepending it to the list of autoloaders.
// This is needed because composer's autoloader is prepended to the list of autoloaders, and we need to
// make sure that dd's autoloader is prepended to composer's autoloader.
spl_autoload_unregister('DDTrace\Bridge\OptionalDepsAutoloader::load');
spl_autoload_register('DDTrace\Bridge\OptionalDepsAutoloader::load', true, true);
}
}
}
);
}


function ddtrace_legacy_tracer_autoloading_possible()
{
}
11 changes: 11 additions & 0 deletions bridge/dd_register_optional_deps_autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class OptionalDepsAutoloader
private static $autoloaderMapping = [
"DDTrace\\Integrations\\ZendFramework\\V1\\TraceRequest" => 'DDTrace/Integrations/ZendFramework/V1/TraceRequest.php',
"DDTrace\\Log\\PsrLogger" => 'api/Log/PsrLogger.php',
"DDTrace\\OpenTelemetry\\API\\Trace\\SpanContext" => 'DDTrace/OpenTelemetry/SpanContext.php',
"DDTrace\\OpenTracer\\Tracer" => 'DDTrace/OpenTracer/Tracer.php',
"DDTrace\\OpenTracer\\Span" => 'DDTrace/OpenTracer/Span.php',
"DDTrace\\OpenTracer\\Scope" => 'DDTrace/OpenTracer/Scope.php',
Expand All @@ -35,6 +36,12 @@ class OptionalDepsAutoloader
"DDTrace\\NoopSpanContext" => 'api/NoopSpanContext.php',
];

private static $otelAutoloaderMapping = [
"OpenTelemetry\\SDK\\Trace\\Span" => 'DDTrace/OpenTelemetry/Span.php',
"OpenTelemetry\\SDK\\Trace\\SpanBuilder" => 'DDTrace/OpenTelemetry/SpanBuilder.php',
"OpenTelemetry\\Context\\Context" => 'DDTrace/OpenTelemetry/Context.php',
];

/**
* @param string $class
*/
Expand All @@ -43,6 +50,10 @@ public static function load($class)
if (array_key_exists($class, self::$autoloaderMapping)) {
require __DIR__ . '/../src/' . self::$autoloaderMapping[$class];
}

if (function_exists('dd_trace_env_config') && dd_trace_env_config('DD_TRACE_OTEL_ENABLED') && array_key_exists($class, self::$otelAutoloaderMapping)) {
require __DIR__ . '/../src/' . self::$otelAutoloaderMapping[$class];
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@
},
"extra": {
"scenarios": {
"opentelemetry1": {
"require": {
"open-telemetry/sdk": "@stable",
"open-telemetry/extension-propagator-b3": "@stable",
"open-telemetry/opentelemetry-logger-monolog": "@stable"
},
"scenario-options": {
"create-lockfile": false
}
},
"opentracing_beta5": {
"require": {
"opentracing/opentracing": "1.0.0-beta5"
Expand Down
7 changes: 7 additions & 0 deletions datadog-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ function install($options)
$tmpArchiveAppsecEtc = "{$tmpArchiveAppsecRoot}/etc";
$tmpArchiveProfilingRoot = $tmpDir . '/dd-library-php/profiling';
$tmpBridgeDir = $tmpArchiveTraceRoot . '/bridge';
$tmpSrcDir = $tmpArchiveTraceRoot . '/src';
execute_or_exit("Cannot create directory '$tmpDir'", "mkdir -p " . escapeshellarg($tmpDir));
register_shutdown_function(function () use ($tmpDir) {
execute_or_exit("Cannot remove temporary directory '$tmpDir'", "rm -rf " . escapeshellarg($tmpDir));
Expand Down Expand Up @@ -498,6 +499,12 @@ function install($options)
"Cannot copy files from '$tmpBridgeDir' to '$installDirSourcesDir'",
"cp -r " . escapeshellarg("$tmpBridgeDir") . ' ' . escapeshellarg($installDirSourcesDir)
);
if (file_exists($tmpSrcDir)) {
execute_or_exit(
"Cannot copy files from '$tmpSrcDir' to '$installDirSourcesDir'",
"cp -r " . escapeshellarg("$tmpSrcDir") . ' ' . escapeshellarg($installDirSourcesDir)
);
}
echo "Installed required source files to '$installDir'\n";

// Appsec helper and rules
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/ci/xfail_tests/8.3.list
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Zend/tests/list_keyed_conversions.phpt
Zend/tests/multibyte/multibyte_encoding_004.phpt
Zend/tests/object_gc_in_shutdown.phpt
Zend/tests/offset_array.phpt
Zend/tests/stack_limit/stack_limit_013.phpt
Zend/tests/strict_001.phpt
Zend/tests/type_declarations/scalar_return_basic_64bit.phpt
Zend/tests/type_declarations/scalar_strict_64bit.phpt
Expand Down
4 changes: 4 additions & 0 deletions dockerfiles/ci/xfail_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ ddtrace request init hook consumes more than 2 MB of memory and fails too early

ddtrace affects the order of destructor execution due to creating span stacks etc.

## `Zend/tests/stack_limit/stack_limit_013.phpt`

This particular test is very close to the stack limit, and thus sometimes fails to actually exceed the stack limit with ddtrace.

## `ext/zend_test/tests/`, `Zend/tests/gh10346.phpt`

Observer tests trace all functions, including dd setup. Exclude these from being observed.
Expand Down
Loading

0 comments on commit ea2e364

Please sign in to comment.