Skip to content

Commit

Permalink
Improved supportability (#941)
Browse files Browse the repository at this point in the history
* Reverted references of ELASTIC_APM_EMPTY_STRING_VIEW back to makeEmptyStringView()

since ELASTIC_APM_EMPTY_STRING_VIEW is added in a later PR

* Fixed incorrect merge

* Added INTERNAL_CHECKS_LEVEL to OptionNames.php

* Added maxNumberOfStackFrames as parameter to 

LoggableStackTrace::buildForCurrent instead having hardcoded

* Removed static from constructConfigManagerMetadata to have on stack trace

* Log stack trace on failed ASSERT in native part

* Set g_elasticApmDirectLogLevel* to default values so that they can be used even before configuration is parsed
  • Loading branch information
SergeyKleyman committed Apr 28, 2023
1 parent d6da34a commit 34a8a11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/ElasticApm/Impl/Config/OptionNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class OptionNames
public const ENABLED = 'enabled';
public const ENVIRONMENT = 'environment';
public const HOSTNAME = 'hostname';
public const INTERNAL_CHECKS_LEVEL = 'internal_checks_level';
public const LOG_LEVEL = 'log_level';
public const LOG_LEVEL_SYSLOG = 'log_level_syslog';
public const LOG_LEVEL_STDERR = 'log_level_stderr';
Expand Down
7 changes: 5 additions & 2 deletions src/ElasticApm/Impl/Log/LoggableStackTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ final class LoggableStackTrace
{
public const STACK_TRACE_KEY = 'stacktrace';

public const MAX_NUMBER_OF_STACK_FRAMES = 100;

/**
* @param int $numberOfStackFramesToSkip
* @param int $maxNumberOfStackFrames
*
* @return ClassicFormatStackTraceFrame[]
*/
public static function buildForCurrent(int $numberOfStackFramesToSkip): array
public static function buildForCurrent(int $numberOfStackFramesToSkip, int $maxNumberOfStackFrames = self::MAX_NUMBER_OF_STACK_FRAMES): array
{
/**
* @param string $key
Expand All @@ -58,7 +61,7 @@ public static function buildForCurrent(int $numberOfStackFramesToSkip): array
null /* <- loggerFactory */,
$numberOfStackFramesToSkip + 1 /* <- offset */,
DEBUG_BACKTRACE_IGNORE_ARGS /* <- options */,
100 /* limit */
$maxNumberOfStackFrames /* <- limit */
);
$result = [];

Expand Down
1 change: 0 additions & 1 deletion src/ext/ConfigManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,6 @@ void destructConfigManagerMetadata( ConfigMetadata* cfgManagerMeta )
ELASTIC_APM_ZERO_STRUCT( cfgManagerMeta );
}

static
ResultCode constructConfigManagerMetadata( ConfigMetadata* cfgManagerMeta )
{
ELASTIC_APM_ASSERT_VALID_PTR( cfgManagerMeta );
Expand Down
9 changes: 9 additions & 0 deletions src/ext/elastic_apm_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ void vElasticApmAssertFailed(
, msgPrintfFmt
, msgPrintfFmtArgs );

void* stackTraceAddresses[ maxCaptureStackTraceDepth ];
size_t stackTraceAddressesCount = 0;
stackTraceAddressesCount = ELASTIC_APM_CAPTURE_STACK_TRACE( &(stackTraceAddresses[ 0 ]), ELASTIC_APM_STATIC_ARRAY_SIZE( stackTraceAddresses ) );

char txtOutStreamBuf[ ELASTIC_APM_TEXT_OUTPUT_STREAM_ON_STACK_BUFFER_SIZE * 10 ];
TextOutputStream txtOutStream = ELASTIC_APM_TEXT_OUTPUT_STREAM_FROM_STATIC_BUFFER( txtOutStreamBuf );

ELASTIC_APM_FORCE_LOG_CRITICAL( "Stack trace:\n%s", streamStackTrace( &( stackTraceAddresses[ 0 ] ), stackTraceAddressesCount, /* linePrefix: */ "\t", &txtOutStream ) );

elasticApmAbort();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ext/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#define ELASTIC_APM_CURRENT_LOG_CATEGORY ELASTIC_APM_LOG_CATEGORY_LOG

#ifndef PHP_WIN32
LogLevel g_elasticApmDirectLogLevelSyslog = logLevel_off;
LogLevel g_elasticApmDirectLogLevelSyslog = logLevel_info;
#endif // #ifndef PHP_WIN32
LogLevel g_elasticApmDirectLogLevelStderr = logLevel_off;
LogLevel g_elasticApmDirectLogLevelStderr = logLevel_error;

String logLevelNames[numberOfLogLevels] =
{
Expand Down

0 comments on commit 34a8a11

Please sign in to comment.