Skip to content

Commit 9caf27b

Browse files
authored
Merge pull request #854 from newrelic/dev
Release 10.19
2 parents 51c1140 + c9c6fba commit 9caf27b

File tree

930 files changed

+1286
-295567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

930 files changed

+1286
-295567
lines changed

Makefile

+20-61
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# The top level Makefile
88
#
99
GCOV ?= gcov
10-
GO ?= go
1110
SHELL = /bin/bash
1211
GCOVR ?= gcovr
1312
GIT ?= git
@@ -20,17 +19,6 @@ include make/php_versions.mk
2019
# Include the secrets file if it exists, but if it doesn't, that's OK too.
2120
-include make/secrets.mk
2221

23-
# Configure an isolated workspace for the Go daemon.
24-
export GOPATH=$(CURDIR)
25-
export GO15VENDOREXPERIMENT=1
26-
# Needed for Go > 1.11 to avoid building with modules by default
27-
export GO111MODULE=auto
28-
29-
# GOBIN affects the behavior of go install, ensure it is unset.
30-
unexport GOBIN
31-
32-
GOFLAGS := -ldflags '-X newrelic/version.Number=$(AGENT_VERSION) -X newrelic/version.Commit=$(GIT_COMMIT) -X newrelic/secrets.NewrelicCollectorHost=$(NEWRELIC_COLLECTOR_HOST) -X newrelic/secrets.NewrelicLicenseKey=$(NEWRELIC_LICENSE_KEY) -X newrelic/secrets.NewrelicCollectorKeys=$(NEWRELIC_COLLECTOR_KEYS) -X newrelic/secrets.NewrelicAccountId=$(ACCOUNT_supportability) -X newrelic/secrets.NewrelicAppId=$(APP_supportability)' $(GO_TAGS)
33-
3422
GCOVRFLAGS += -e "agent/tests/*" -e "axiom/tests/*" -e ".*\.h" -o
3523

3624
#
@@ -170,68 +158,39 @@ agent-valgrind: agent/Makefile
170158
$(MAKE) -C agent valgrind
171159

172160
#
173-
# Build the daemon and related utilities
174-
#
175-
176-
#
177-
# Minimum required version of Go is 1.5.
161+
# Daemon rules
162+
# defers to behavior defined in daemon/Makefile once $GOBIN has been set
178163
#
179-
# This is defined as a rule that other rules that require Go can depend upon.
180-
# We don't want to require Go for a general build primarily to make the PHP
181-
# agent easier to use as a component within the C agent.
182-
#
183-
.PHONY: go-minimum-version
184-
go-minimum-version:
185-
@if $(GO) version | awk '/go1.[012345678][\. ]/ { exit 1 }'; then \
186-
true; \
187-
else \
188-
echo -n 'Go 1.9 or newer required; found '; $(GO) version; false; \
189-
fi
190164

191-
DAEMON_TARGETS := $(addprefix bin/,client daemon integration_runner stressor)
165+
# Configure the target directory for go install
166+
export GOBIN=$(CURDIR)/bin
192167

193-
# Delete Go binaries before each build to force them to be re-linked. This
194-
# ensures the version and commit variables are set correctly by the linker.
195-
#
196-
# The bin directory is also the target directory for the installer,
197-
# which we need to be careful to leave in place. Therefore, the names of the
198-
# Go binaries are made explicit. If we used a conventional `cmd` subdirectory
199-
# for commands, we could use `go list` to determine the names.
200168
.PHONY: daemon
201-
daemon: go-minimum-version daemon-protobuf Makefile | bin/
202-
@rm -rf $(DAEMON_TARGETS)
203-
@$(GO) install $(GOFLAGS) ./...
169+
daemon:
170+
$(MAKE) -C daemon
204171

205-
# The -race flag enables the inegrated Go race detector. Output to stderr
206172
.PHONY: daemon_race
207-
daemon_race: go-minimum-version daemon-protobuf Makefile | bin/
208-
@rm -rf $(DAEMON_TARGETS)
209-
@$(GO) install -race $(GOFLAGS) ./...
173+
daemon_race:
174+
$(MAKE) -C daemon race
210175

211176
.PHONY: daemon_test
212-
daemon_test: go-minimum-version daemon-protobuf
213-
@$(GO) test $(GOFLAGS) ./...
177+
daemon_test:
178+
$(MAKE) -C daemon test
214179

215180
.PHONY: daemon_bench
216-
daemon_bench: go-minimum-version daemon-protobuf
217-
@$(GO) test $(GOFLAGS) -bench=. ./...
181+
daemon_bench:
182+
$(MAKE) -C daemon bench
218183

219184
.PHONY: daemon_integration
220-
daemon_integration: go-minimum-version daemon-protobuf
221-
$(MAKE) INTEGRATION_TAGS=1 go-minimum-version
222-
@$(GO) test $(GOFLAGS) ./...
185+
daemon_integration:
186+
$(MAKE) -C daemon integration
223187

224-
DAEMON_COV_FILE = daemon_coverage.out
225188
.PHONY: daemon_cover
226-
daemon_cover: go-minimum-version daemon-protobuf
227-
@rm -f $(DAEMON_COV_FILE)
228-
@$(GO) test -coverprofile=$(DAEMON_COV_FILE) $(GOFLAGS) ./...
229-
$(GO) tool cover -html=$(DAEMON_COV_FILE)
230-
@rm -f $(DAEMON_COV_FILE)
189+
daemon_cover:
190+
$(MAKE) -C daemon cover
231191

232192
bin/integration_runner:
233-
@echo "Building bin/integration_runner"
234-
@$(GO) install $(GOFLAGS) integration_runner
193+
$(MAKE) -C daemon integration_runner
235194

236195
# Note that this rule does not require the Go binary, and therefore doesn't
237196
# depend on go-minimum-version.
@@ -317,14 +276,14 @@ axiom-clean:
317276
# Before running this script, make sure the location of protoc-gen-go is in
318277
# your $PATH.
319278
.PHONY: daemon-protobuf
320-
daemon-protobuf: src/newrelic/infinite_tracing/com_newrelic_trace_v1/v1.pb.go
279+
daemon-protobuf: daemon/internal/newrelic/infinite_tracing/com_newrelic_trace_v1/v1.pb.go
321280

322-
src/newrelic/infinite_tracing/com_newrelic_trace_v1/v1.pb.go: protocol/infinite_tracing/v1.proto
281+
daemon/internal/newrelic/infinite_tracing/com_newrelic_trace_v1/v1.pb.go: protocol/infinite_tracing/v1.proto
323282
$(MAKE) vendor # Only build vendor stuff if v1.proto has changed. Otherwise
324283
# this rule will be triggered every time the daemon is built.
325284
$(VENDOR_PREFIX)/bin/protoc \
326285
-I=./protocol/infinite_tracing \
327-
--go_out="paths=source_relative,plugins=grpc:src/newrelic/infinite_tracing/com_newrelic_trace_v1" \
286+
--go_out="paths=source_relative,plugins=grpc:daemon/internal/newrelic/infinite_tracing/com_newrelic_trace_v1" \
328287
protocol/infinite_tracing/v1.proto
329288

330289
#

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10.18.0
1+
10.19.0

agent/Makefile.frag

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ TEST_BINARIES = \
9797
tests/test_pdo_mysql \
9898
tests/test_pdo_pgsql \
9999
tests/test_pgsql \
100+
tests/test_php_error \
100101
tests/test_php_execute \
101102
tests/test_php_minit \
102103
tests/test_php_stack \

agent/php_api_internal.c

+52
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "php_api_internal.h"
88
#include "php_call.h"
99
#include "php_hash.h"
10+
#include "nr_commands_private.h"
1011
#include "nr_datastore_instance.h"
1112
#include "nr_header.h"
1213
#include "nr_limits.h"
@@ -381,6 +382,57 @@ PHP_FUNCTION(newrelic_get_trace_json) {
381382
nr_set_destroy(&fas_metadata.active_segments);
382383
}
383384

385+
PHP_FUNCTION(newrelic_get_error_json) {
386+
nrtxn_t* txn = NRPRG(txn);
387+
char* json;
388+
389+
NR_UNUSED_HT;
390+
NR_UNUSED_RETURN_VALUE_PTR;
391+
NR_UNUSED_RETURN_VALUE_USED;
392+
NR_UNUSED_THIS_PTR;
393+
394+
if (!nr_php_recording(TSRMLS_C)) {
395+
RETURN_FALSE;
396+
}
397+
398+
if (FAILURE == zend_parse_parameters_none()) {
399+
RETURN_FALSE;
400+
}
401+
402+
json = nr_txndata_error_to_json(txn);
403+
if (NULL == json) {
404+
RETURN_FALSE;
405+
}
406+
407+
nr_php_zval_str(return_value, json);
408+
nr_free(json);
409+
}
410+
411+
PHP_FUNCTION(newrelic_get_transaction_guid) {
412+
nrtxn_t* txn = NRPRG(txn);
413+
const char* guid;
414+
415+
NR_UNUSED_HT;
416+
NR_UNUSED_RETURN_VALUE_PTR;
417+
NR_UNUSED_RETURN_VALUE_USED;
418+
NR_UNUSED_THIS_PTR;
419+
420+
if (!nr_php_recording(TSRMLS_C)) {
421+
RETURN_FALSE;
422+
}
423+
424+
if (FAILURE == zend_parse_parameters_none()) {
425+
RETURN_FALSE;
426+
}
427+
428+
guid = nr_txn_get_guid(txn);
429+
if (NULL == guid) {
430+
RETURN_FALSE;
431+
}
432+
433+
nr_php_zval_str(return_value, guid);
434+
}
435+
384436
PHP_FUNCTION(newrelic_is_localhost) {
385437
char* host = NULL;
386438
nr_string_len_t host_len = 0;

agent/php_api_internal.h

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ extern PHP_FUNCTION(newrelic_get_slowsqls);
5252
*/
5353
extern PHP_FUNCTION(newrelic_get_trace_json);
5454

55+
/*
56+
* Proto : string newrelic_get_error_json ()
57+
*
58+
* Returns : The error trace JSON that would be sent to the daemon if the
59+
* transaction ended at the point the function is called. This string
60+
* is owned by the caller.
61+
*/
62+
extern PHP_FUNCTION(newrelic_get_error_json);
63+
64+
/*
65+
* Proto : string newrelic_get_transaction_guid ()
66+
*
67+
* Returns : The transaction guid.
68+
*/
69+
extern PHP_FUNCTION(newrelic_get_transaction_guid);
70+
5571
/*
5672
* Proto : bool newrelic_is_localhost (string $host)
5773
*

agent/php_error.c

+50-25
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ PHP_FUNCTION(newrelic_exception_handler) {
287287
#endif /* PHP7 */
288288
}
289289

290+
/* PHP Fatal errors: E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
291+
* E_COMPILE_ERROR | E_RECOVERABLE_ERROR */
292+
290293
int nr_php_error_get_priority(int type) {
291294
switch (type) {
292295
case E_PARSE:
@@ -299,6 +302,8 @@ int nr_php_error_get_priority(int type) {
299302
return 50;
300303
case E_ERROR:
301304
return 50;
305+
case E_RECOVERABLE_ERROR:
306+
return 50;
302307
case E_COMPILE_WARNING:
303308
return 40;
304309
case E_CORE_WARNING:
@@ -307,6 +312,12 @@ int nr_php_error_get_priority(int type) {
307312
return 40;
308313
case E_WARNING:
309314
return 40;
315+
case E_DEPRECATED:
316+
return 30;
317+
case E_USER_DEPRECATED:
318+
return 30;
319+
case E_STRICT: /* Included for backward compatibility */
320+
return 10;
310321
case E_USER_NOTICE:
311322
return 0;
312323
case E_NOTICE:
@@ -466,30 +477,51 @@ static char* nr_php_error_exception_message(zval* exception TSRMLS_DC) {
466477
return message;
467478
}
468479

469-
static const char* get_error_type_string(int type) {
480+
const char* nr_php_error_get_type_string(int type) {
481+
/* NOTE: PHP 7 makes E_STRICT irrelevant, reclassifying most of the errors as
482+
* proper warnings, notices or E_DEPRECATED:
483+
* https://wiki.php.net/rfc/reclassify_e_strict The E_STRICT constant will be
484+
* retained for better compatibility, it will simply no longer have meaning in
485+
* PHP 7. While PHP 7 was backward compatible, PHP 8 does not use E_STRICT.
486+
*/
487+
488+
/* Note:
489+
* With PHP7.4+ we should never actually be getting E_ERROR, or
490+
* E_RECOVERABLE_ERROR here. Both are fatal errors and are handled by the
491+
* agent's uncaught exceptions logic (unless E_RECOVERABLE_ERROR in which case
492+
* there is no error to see)
493+
*/
470494
switch (type) {
471-
case E_ERROR:
495+
case E_ERROR: /* 1 */
472496
return "E_ERROR";
473-
case E_WARNING:
497+
case E_WARNING: /* 2 */
474498
return "E_WARNING";
475-
case E_PARSE:
499+
case E_PARSE: /* 4 */
476500
return "E_PARSE";
477-
case E_NOTICE:
501+
case E_NOTICE: /* 8 */
478502
return "E_NOTICE";
479-
case E_CORE_ERROR:
503+
case E_CORE_ERROR: /* 16 */
480504
return "E_CORE_ERROR";
481-
case E_CORE_WARNING:
505+
case E_CORE_WARNING: /* 32 */
482506
return "E_CORE_WARNING";
483-
case E_COMPILE_ERROR:
507+
case E_COMPILE_ERROR: /* 64 */
484508
return "E_COMPILE_ERROR";
485-
case E_COMPILE_WARNING:
509+
case E_COMPILE_WARNING: /* 128 */
486510
return "E_COMPILE_WARNING";
487-
case E_USER_ERROR:
511+
case E_USER_ERROR: /* 256 */
488512
return "E_USER_ERROR";
489-
case E_USER_WARNING:
513+
case E_USER_WARNING: /* 512 */
490514
return "E_USER_WARNING";
491-
case E_USER_NOTICE:
515+
case E_USER_NOTICE: /* 1024 */
492516
return "E_USER_NOTICE";
517+
case E_STRICT: /* 2048 */
518+
return "E_STRICT";
519+
case E_RECOVERABLE_ERROR: /* 4096 */
520+
return "E_RECOVERABLE_ERROR";
521+
case E_DEPRECATED: /* 8192 */
522+
return "E_DEPRECATED";
523+
case E_USER_DEPRECATED: /* 16348 */
524+
return "E_USER_DEPRECATED";
493525
default:
494526
return "Error";
495527
}
@@ -563,11 +595,6 @@ void nr_php_error_cb(int type,
563595
const char* format,
564596
va_list args) {
565597
#endif /* PHP >= 8.1 */
566-
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
567-
&& !defined OVERWRITE_ZEND_EXECUTE_DATA /* PHP 8.0+ and OAPI */
568-
(void)error_filename;
569-
(void)error_lineno;
570-
#endif
571598
TSRMLS_FETCH();
572599
char* stack_json = NULL;
573600
const char* errclass = NULL;
@@ -597,7 +624,7 @@ void nr_php_error_cb(int type,
597624
#endif /* PHP < 8.0 */
598625

599626
stack_json = nr_php_backtrace_to_json(0 TSRMLS_CC);
600-
errclass = get_error_type_string(type);
627+
errclass = nr_php_error_get_type_string(type);
601628

602629
nr_txn_record_error(NRPRG(txn), nr_php_error_get_priority(type), true,
603630
msg, errclass, stack_json);
@@ -622,20 +649,18 @@ void nr_php_error_cb(int type,
622649
nr_free(msg);
623650
nr_free(stack_json);
624651
}
625-
/*
626-
* Call through to the actual error handler for PHP 7.4 and below.
627-
* For PHP 8+ we have registered our error handler with the Observer
628-
* API so there is no need to callback to the original.
629-
*/
630652
/*
631653
* Call through to the actual error handler.
632654
*/
633-
#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO
634655
if (0 != NR_PHP_PROCESS_GLOBALS(orig_error_cb)) {
656+
#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO
635657
NR_PHP_PROCESS_GLOBALS(orig_error_cb)
636658
(type, error_filename, error_lineno, format, args);
637-
}
659+
#else
660+
NR_PHP_PROCESS_GLOBALS(orig_error_cb)
661+
(type, error_filename, error_lineno, message);
638662
#endif /* PHP < 8.0 */
663+
}
639664
}
640665

641666
nr_status_t nr_php_error_record_exception(nrtxn_t* txn,

agent/php_error.h

+9
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ extern PHP_FUNCTION(newrelic_exception_handler);
112112
*/
113113
extern int nr_php_error_get_priority(int type);
114114

115+
/*
116+
* Purpose : Converts a PHP error type into a readable string.
117+
*
118+
* Params : 1. The error type.
119+
*
120+
* Returns : The PHP error type as constant, static string (must not be freed).
121+
*/
122+
extern const char* nr_php_error_get_type_string(int type);
123+
115124
/*
116125
* Purpose : Install newrelic_exception_handler as the user exception handler
117126
* in PHP.

agent/php_execute.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static const nr_framework_table_t all_frameworks[] = {
387387

388388
{"Magento", "magento", NR_PSTR("app/mage.php"), 0, nr_magento1_enable,
389389
NR_FW_MAGENTO1},
390-
{"Magento2", "magento2", NR_PSTR("magento/framework/app/bootstrap.php"), 0,
390+
{"Magento2", "magento2", NR_PSTR("magento/framework/registration.php"), 0,
391391
nr_magento2_enable, NR_FW_MAGENTO2},
392392

393393
{"MediaWiki", "mediawiki", NR_PSTR("includes/webstart.php"), 0, nr_mediawiki_enable,

0 commit comments

Comments
 (0)