-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
834 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM mysql:5.6 | ||
COPY mysql /docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
create table users ( | ||
id integer not null primary key auto_increment, | ||
email varchar(100) not null unique, | ||
name varchar(100), | ||
password varchar(100), | ||
remember_token varchar(100), | ||
updated_at timestamp, | ||
created_at timestamp | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/DDTrace/Integrations/Eloquent/EloquentSandboxedIntegration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace DDTrace\Integrations\Eloquent; | ||
|
||
use DDTrace\Integrations\Integration; | ||
use DDTrace\Integrations\SandboxedIntegration; | ||
use DDTrace\SpanData; | ||
use DDTrace\Tag; | ||
use DDTrace\Type; | ||
|
||
class EloquentSandboxedIntegration extends SandboxedIntegration | ||
{ | ||
const NAME = 'eloquent'; | ||
|
||
/** | ||
* @return string The integration name. | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* Add instrumentation to PDO requests | ||
*/ | ||
public function init() | ||
{ | ||
dd_trace_method('Illuminate\Database\Eloquent\Builder', 'getModels', function (SpanData $span, array $args) { | ||
$span->name = 'eloquent.get'; | ||
$sql = $this->getQuery()->toSql(); | ||
$span->type = Type::SQL; | ||
$span->resource = $sql; | ||
$span->meta[Tag::DB_STATEMENT] = $sql; | ||
}); | ||
|
||
dd_trace_method('Illuminate\Database\Eloquent\Model', 'performInsert', function (SpanData $span, array $args) { | ||
$span->name = 'eloquent.insert'; | ||
$span->type = Type::SQL; | ||
$span->resource = get_class($this); | ||
}); | ||
|
||
dd_trace_method('Illuminate\Database\Eloquent\Model', 'performUpdate', function (SpanData $span, array $args) { | ||
$span->name = 'eloquent.update'; | ||
$span->type = Type::SQL; | ||
$span->resource = get_class($this); | ||
}); | ||
|
||
dd_trace_method('Illuminate\Database\Eloquent\Model', 'delete', function (SpanData $span, array $args) { | ||
$span->name = 'eloquent.delete'; | ||
$span->type = Type::SQL; | ||
$span->resource = get_class($this); | ||
}); | ||
|
||
dd_trace_method('Illuminate\Database\Eloquent\Model', 'destroy', function (SpanData $span) { | ||
$span->name = 'eloquent.destroy'; | ||
$span->type = Type::SQL; | ||
$span->resource = get_called_class(); | ||
}); | ||
|
||
dd_trace_method('Illuminate\Database\Eloquent\Model', 'refresh', function (SpanData $span) { | ||
$span->name = 'eloquent.refresh'; | ||
$span->type = Type::SQL; | ||
$span->resource = get_class($this); | ||
}); | ||
|
||
return Integration::LOADED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
#include "compat_string.h" | ||
|
||
#include <Zend/zend_API.h> | ||
#include <php.h> | ||
#include <php_version.h> | ||
|
||
#if PHP_VERSION_ID < 70000 | ||
int ddtrace_spprintf(char **message, size_t max_len, char *format, ...) { | ||
va_list arg; | ||
int len; | ||
|
||
va_start(arg, format); | ||
len = vspprintf(message, max_len, format, arg); | ||
va_end(arg); | ||
return len; | ||
} | ||
#else | ||
size_t ddtrace_spprintf(char **message, size_t max_len, char *format, ...) { | ||
va_list arg; | ||
size_t len; | ||
|
||
va_start(arg, format); | ||
len = vspprintf(message, max_len, format, arg); | ||
va_end(arg); | ||
return len; | ||
} | ||
#endif | ||
|
||
#if PHP_VERSION_ID < 70000 | ||
void ddtrace_downcase_zval(zval *src) { | ||
if (!src || Z_TYPE_P(src) != IS_STRING) { | ||
return; | ||
} | ||
|
||
zend_str_tolower(Z_STRVAL_P(src), Z_STRLEN_P(src)); | ||
} | ||
|
||
#else | ||
void ddtrace_downcase_zval(zval *src) { | ||
if (!src || Z_TYPE_P(src) != IS_STRING) { | ||
return; | ||
} | ||
zend_string *str = Z_STR_P(src); | ||
|
||
ZVAL_STR(src, zend_string_tolower(str)); | ||
zend_string_release(str); | ||
} | ||
#endif | ||
|
||
#if PHP_VERSION_ID < 70000 | ||
void ddtrace_try_get_string(zval *dst, zval *src ZEND_FILE_LINE_DC TSRMLS_DC) { | ||
switch (Z_TYPE_P(src)) { | ||
case IS_BOOL: | ||
if (Z_LVAL_P(src)) { | ||
Z_STRVAL_P(src) = estrndup_rel("1", 1); | ||
Z_STRLEN_P(src) = 1; | ||
break; | ||
} | ||
/* fall through */ | ||
|
||
case IS_NULL: | ||
Z_STRVAL_P(dst) = STR_EMPTY_ALLOC(); | ||
Z_STRLEN_P(dst) = 0; | ||
break; | ||
|
||
case IS_RESOURCE: | ||
Z_STRLEN_P(dst) = ddtrace_spprintf(&Z_STRVAL_P(dst), 0, "Resource id #%ld", Z_LVAL_P(src)); | ||
break; | ||
|
||
case IS_LONG: | ||
Z_STRLEN_P(dst) = ddtrace_spprintf(&Z_STRVAL_P(dst), 0, "%ld", Z_LVAL_P(src)); | ||
break; | ||
|
||
case IS_DOUBLE: | ||
Z_STRLEN_P(dst) = ddtrace_spprintf(&Z_STRVAL_P(dst), 0, "%.*G", (int)EG(precision), Z_DVAL_P(src)); | ||
break; | ||
|
||
case IS_ARRAY: | ||
Z_STRVAL_P(dst) = estrndup_rel("Array", sizeof("Array") - 1); | ||
Z_STRLEN_P(dst) = sizeof("Array") - 1; | ||
break; | ||
|
||
case IS_OBJECT: { | ||
if (Z_OBJ_HANDLER_P(src, cast_object)) { | ||
if (Z_OBJ_HANDLER_P(src, cast_object)(src, dst, IS_STRING TSRMLS_CC) == SUCCESS) { | ||
return; | ||
} | ||
} else if (Z_OBJ_HANDLER_P(src, get)) { | ||
zval *newop = Z_OBJ_HANDLER_P(src, get)(src TSRMLS_CC); | ||
if (Z_TYPE_P(newop) != IS_OBJECT) { | ||
/* for safety - avoid loop */ | ||
ddtrace_try_get_string(dst, newop ZEND_FILE_LINE_CC TSRMLS_CC); | ||
|
||
// I think? | ||
zval_dtor(newop); | ||
return; | ||
} | ||
} | ||
ZVAL_NULL(dst); | ||
return; | ||
} | ||
|
||
case IS_CONSTANT: | ||
case IS_STRING: | ||
ZVAL_COPY_VALUE(dst, src); | ||
_zval_copy_ctor_func(dst ZEND_FILE_LINE_CC); | ||
return; | ||
|
||
EMPTY_SWITCH_DEFAULT_CASE() | ||
} | ||
Z_TYPE_P(src) = IS_STRING; | ||
} | ||
|
||
#else | ||
static zend_string *_try_get_string(zval *op) { | ||
try_again: | ||
switch (Z_TYPE_P(op)) { | ||
case IS_UNDEF: | ||
case IS_NULL: | ||
case IS_FALSE: | ||
return ZSTR_EMPTY_ALLOC(); | ||
|
||
case IS_TRUE: | ||
#if PHP_VERSION_ID < 70200 | ||
return CG(one_char_string)['1'] ? CG(one_char_string)['1'] : zend_string_init("1", 1, 0); | ||
#else | ||
return ZSTR_CHAR('1'); | ||
#endif | ||
|
||
case IS_RESOURCE: | ||
return strpprintf(0, "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op)); | ||
|
||
case IS_LONG: | ||
return zend_long_to_str(Z_LVAL_P(op)); | ||
|
||
case IS_DOUBLE: | ||
return strpprintf(0, "%.*G", (int)EG(precision), Z_DVAL_P(op)); | ||
|
||
case IS_ARRAY: | ||
#if PHP_VERSION_ID < 70400 | ||
return zend_string_init("Array", sizeof("Array") - 1, 0); | ||
#else | ||
return ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED); | ||
#endif | ||
|
||
case IS_OBJECT: { | ||
zval tmp; | ||
if (Z_OBJ_HT_P(op)->cast_object) { | ||
if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING) == SUCCESS) { | ||
return Z_STR(tmp); | ||
} | ||
} else if (Z_OBJ_HT_P(op)->get) { | ||
zval *z = Z_OBJ_HT_P(op)->get(op, &tmp); | ||
if (Z_TYPE_P(z) != IS_OBJECT) { | ||
zend_string *str = _try_get_string(z); | ||
zval_ptr_dtor(z); | ||
return str; | ||
} | ||
} | ||
return NULL; | ||
} | ||
|
||
case IS_REFERENCE: | ||
op = Z_REFVAL_P(op); | ||
goto try_again; | ||
|
||
case IS_STRING: | ||
return zend_string_copy(Z_STR_P(op)); | ||
|
||
EMPTY_SWITCH_DEFAULT_CASE() | ||
} | ||
} | ||
|
||
void ddtrace_try_get_string(zval *dst, zval *src) { | ||
zend_string *str = _try_get_string(src); | ||
if (str) { | ||
ZVAL_STR(dst, str); | ||
} else { | ||
ZVAL_NULL(dst); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef COMPAT_STRING_H | ||
#define COMPAT_STRING_H | ||
#include <Zend/zend.h> | ||
#include <Zend/zend_types.h> | ||
#include <php_version.h> | ||
|
||
#include "compatibility.h" | ||
|
||
void ddtrace_downcase_zval(zval *src); | ||
|
||
// ddtrace_spprintf is a replacement for zend_spprintf, since it is not exported in many versions | ||
#if PHP_VERSION_ID < 70000 | ||
int ddtrace_spprintf(char **message, size_t max_len, char *format, ...); | ||
#else | ||
size_t ddtrace_spprintf(char **message, size_t max_len, char *format, ...); | ||
#endif | ||
|
||
/* dst will either be IS_STRING or IS_NULL; caller must dtor */ | ||
#if PHP_VERSION_ID < 70000 | ||
void ddtrace_try_get_string(zval *dst, zval *src ZEND_FILE_LINE_DC TSRMLS_DC); | ||
#else | ||
void ddtrace_try_get_string(zval *dst, zval *src); | ||
#endif | ||
|
||
#endif // COMPAT_STRING_H |
Oops, something went wrong.