Skip to content

Commit

Permalink
Refactor deferred loading setup
Browse files Browse the repository at this point in the history
Remove elasticsearch.h as it no longer is large enough to merit its
own file; likewise test_integration.h.
  • Loading branch information
morrisonlevi committed Sep 21, 2020
1 parent 89b0346 commit cb540f7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 121 deletions.
18 changes: 0 additions & 18 deletions src/ext/integrations/elasticsearch.h

This file was deleted.

112 changes: 54 additions & 58 deletions src/ext/integrations/integrations.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
#include "integrations.h"

#include "configuration.h"
#include "ddtrace_string.h"
#include "elasticsearch.h"
#include "test_integration.h"

#define DDTRACE_DEFERRED_INTEGRATION_LOADER(class, fname, integration_name) \
ddtrace_hook_callable(DDTRACE_STRING_LITERAL(class), DDTRACE_STRING_LITERAL(fname), \
DDTRACE_STRING_LITERAL(integration_name), DDTRACE_DISPATCH_DEFERRED_LOADER TSRMLS_CC)

#define DD_SET_UP_DEFERRED_LOADING_BY_METHOD(name, Class, fname, integration) \
dd_set_up_deferred_loading_by_method(name, DDTRACE_STRING_LITERAL(Class), DDTRACE_STRING_LITERAL(fname), \
DDTRACE_STRING_LITERAL(integration))
/**
* DDTRACE_INTEGRATION_TRACE(class, fname, callable, options)
*
* This macro can be used to assign a tracing callable to Class, Method/Function name combination
* the callable can be any callable string thats recognized by PHP. It needs to have the signature
* expected by normal DDTrace.
*
* function tracing_function(SpanData $span, array $args) { }
*
* options need to specify either DDTRACE_DISPATCH_POSTHOOK or DDTRACE_DISPATCH_PREHOOK
* in order for the callable to be called by the hooks
**/
#define DDTRACE_INTEGRATION_TRACE(class, fname, callable, options) \
ddtrace_hook_callable(DDTRACE_STRING_LITERAL(class), DDTRACE_STRING_LITERAL(fname), \
DDTRACE_STRING_LITERAL(callable), options TSRMLS_CC)

ddtrace_integration ddtrace_integrations[] = {
{DDTRACE_INTEGRATION_CAKEPHP, "CAKEPHP", ZEND_STRL("cakephp")},
Expand Down Expand Up @@ -61,79 +83,53 @@ static void dd_register_known_calls(TSRMLS_D) {
DDTRACE_KNOWN_INTEGRATION("illuminate\\events\\dispatcher", "fire");
}

#if PHP_VERSION_ID >= 70000
static void dd_set_up_deferred_loading_memcached(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_MEMCACHED)) {
static void dd_load_test_integrations(TSRMLS_D) {
char* test_deferred = getenv("_DD_LOAD_TEST_INTEGRATIONS");
if (!test_deferred) {
return;
}

DDTRACE_DEFERRED_INTEGRATION_LOADER("Memcached", "__construct",
"DDTrace\\Integrations\\Memcached\\MemcachedIntegration");
DDTRACE_DEFERRED_INTEGRATION_LOADER("test", "public_static_method", "ddtrace\\test\\testsandboxedintegration");
DDTRACE_INTEGRATION_TRACE("test", "automaticaly_traced_method", "tracing_function", DDTRACE_DISPATCH_POSTHOOK);
}

static void dd_set_up_deferred_loading_pdo(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_PDO)) {
return;
}

DDTRACE_DEFERRED_INTEGRATION_LOADER("PDO", "__construct", "DDTrace\\Integrations\\PDO\\PDOIntegration");
}

static void dd_set_up_deferred_loading_phpredis(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_PHPREDIS)) {
#if PHP_VERSION_ID >= 70000
static void dd_set_up_deferred_loading_by_method(ddtrace_integration_name name, ddtrace_string Class,
ddtrace_string method, ddtrace_string integration) {
if (!ddtrace_config_integration_enabled_ex(name)) {
return;
}

DDTRACE_DEFERRED_INTEGRATION_LOADER("Redis", "__construct", "DDTrace\\Integrations\\PHPRedis\\PHPRedisIntegration");
ddtrace_hook_callable(Class, method, integration, DDTRACE_DISPATCH_DEFERRED_LOADER);
}

static void dd_set_up_deferred_loading_predis(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_PREDIS)) {
return;
}

DDTRACE_DEFERRED_INTEGRATION_LOADER("Predis\\Client", "__construct",
"DDTrace\\Integrations\\Predis\\PredisIntegration");
}
void ddtrace_integrations_rinit(TSRMLS_D) {
dd_register_known_calls();
dd_load_test_integrations(TSRMLS_C);

static void dd_set_up_deferred_loading_slim(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_SLIM)) {
return;
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_ELASTICSEARCH, "elasticsearch\\client", "__construct",
"DDTrace\\Integrations\\ElasticSearch\\V1\\ElasticSearchIntegration");

DDTRACE_DEFERRED_INTEGRATION_LOADER("Slim\\App", "__construct", "DDTrace\\Integrations\\Slim\\SlimIntegration");
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_MEMCACHED, "Memcached", "__construct",
"DDTrace\\Integrations\\Memcached\\MemcachedIntegration");

static void dd_set_up_deferred_loading_wordpress(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_WORDPRESS)) {
return;
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_PDO, "PDO", "__construct",
"DDTrace\\Integrations\\PDO\\PDOIntegration");

DDTRACE_DEFERRED_INTEGRATION_LOADER("Requests", "set_certificate_path",
"DDTrace\\Integrations\\WordPress\\WordPressIntegration");
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_PHPREDIS, "Redis", "__construct",
"DDTrace\\Integrations\\PHPRedis\\PHPRedisIntegration");

static void dd_set_up_deferred_loading_yii(void) {
if (!ddtrace_config_integration_enabled_ex(DDTRACE_INTEGRATION_YII)) {
return;
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_PREDIS, "Predis\\Client", "__construct",
"DDTrace\\Integrations\\Predis\\PredisIntegration");

DDTRACE_DEFERRED_INTEGRATION_LOADER("yii\\di\\Container", "__construct",
"DDTrace\\Integrations\\Yii\\YiiIntegration");
}
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_SLIM, "Slim\\App", "__construct",
"DDTrace\\Integrations\\Slim\\SlimIntegration");

void ddtrace_integrations_rinit(TSRMLS_D) {
dd_register_known_calls();
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_WORDPRESS, "Requests", "set_certificate_path",
"DDTrace\\Integrations\\WordPress\\WordPressIntegration");

_dd_es_initialize_deferred_integration(TSRMLS_C);
_dd_load_test_integrations(TSRMLS_C);
dd_set_up_deferred_loading_memcached();
dd_set_up_deferred_loading_pdo();
dd_set_up_deferred_loading_phpredis();
dd_set_up_deferred_loading_predis();
dd_set_up_deferred_loading_slim();
dd_set_up_deferred_loading_wordpress();
dd_set_up_deferred_loading_yii();
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_YII, "yii\\di\\Container", "__construct",
"DDTrace\\Integrations\\Yii\\YiiIntegration");
}

ddtrace_integration* ddtrace_get_integration_from_string(ddtrace_string integration) {
Expand All @@ -151,7 +147,7 @@ void ddtrace_integrations_rinit(TSRMLS_D) {
* size - even though the memory usage is below the limit. We still can trigger memory
* allocation error to be issued
*/
_dd_load_test_integrations(TSRMLS_C);
dd_load_test_integrations(TSRMLS_C);

dd_register_known_calls(TSRMLS_C);
}
Expand Down
28 changes: 0 additions & 28 deletions src/ext/integrations/integrations.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,6 @@ typedef struct ddtrace_integration ddtrace_integration;
extern ddtrace_integration ddtrace_integrations[];
extern size_t ddtrace_integrations_len;

/**
* DDTRACE_DEFERRED_INTEGRATION_LOADER(class, fname, integration_name)
* This macro will assign a fully qualified Integration name for each
* Class, Method/Function combination.
*
* The integration_name will be constructed and `init()` method called when the
* deferred dispatch loader code is triggered.
*/
#define DDTRACE_DEFERRED_INTEGRATION_LOADER(class, fname, integration_name) \
ddtrace_hook_callable(DDTRACE_STRING_LITERAL(class), DDTRACE_STRING_LITERAL(fname), \
DDTRACE_STRING_LITERAL(integration_name), DDTRACE_DISPATCH_DEFERRED_LOADER TSRMLS_CC)

/**
* DDTRACE_INTEGRATION_TRACE(class, fname, callable, options)
*
* This macro can be used to assign a tracing callable to Class, Method/Function name combination
* the callable can be any callable string thats recognized by PHP. It needs to have the signature
* expected by normal DDTrace.
*
* function tracing_function(SpanData $span, array $args) { }
*
* options need to specify either DDTRACE_DISPATCH_POSTHOOK or DDTRACE_DISPATCH_PREHOOK
* in order for the callable to be called by the hooks
**/
#define DDTRACE_INTEGRATION_TRACE(class, fname, callable, options) \
ddtrace_hook_callable(DDTRACE_STRING_LITERAL(class), DDTRACE_STRING_LITERAL(fname), \
DDTRACE_STRING_LITERAL(callable), options TSRMLS_CC)

void ddtrace_integrations_minit(void);
void ddtrace_integrations_mshutdown(void);
void ddtrace_integrations_rinit(TSRMLS_D);
Expand Down
17 changes: 0 additions & 17 deletions src/ext/integrations/test_integration.h

This file was deleted.

0 comments on commit cb540f7

Please sign in to comment.