Added support for the Telemetry feature.#634
Conversation
waltjones
left a comment
There was a problem hiding this comment.
@danielmorell Looks good. In other SDKs there are typically wrappers for the standard logging, network access, etc. so those are enabled without the user needing to implement them. This PR is still relevant, as those wrappers can call the captureX methods provided here.
|
Is 4.1 will be released? Regards |
|
We should have 4.1 out by the end of the month. |
|
This is extremely useful, especially when getting fatal errors that don't have stack traces which can be very hard to decode! Would it be possible to add the link to PHP docs here? https://docs.rollbar.com/docs/telemetry There are docs here it seems: https://docs.rollbar.com/docs/php-telemetry For those who end up here looking for how to use this outside of the automatic telemetry events, this is the full captureTelemetryEvent signature as of 4.1.4 as a usage example: <?php
use MyApp;
use Rollbar\Rollbar;
use Rollbar\Telemetry\EventType;
use Rollbar\Telemetry\EventLevel;
use Rollbar\Payload\TelemetryBody;
$start = microtime(true) * 1000;
$result = MyApp::someProcess($userInputString);
$end = microtime(true) * 1000;
/**
* Creates the telemetry body.
*
* The `element` property is not included in the constructor because it intended for browser DOM events.
*
* @param string $message This should be included for errors and log events.
* @param string $method This should be included for network events. The HTTP method. E.g. GET,
* POST, etc.
* @param string $url This should be included for network events. The URL of the request.
* @param string $status_code This should be included for network events. The HTTP status code.
* @param string $subtype This can be used to further classify the event. Internally, we use this to
* distinguish between errors and exceptions for error events.
* @param string|null $stack The stack trace of the error or exception. This should be included for
* error events.
* @param string $from This should be included for navigation events. The URL of the previous
* page.
* @param string $to This should be included for navigation events. The URL of the next page.
* @param int|null $start_timestamp_ms The start time of the event in milliseconds since the Unix epoch.
* @param int|null $end_timestamp_ms The end time of the event in milliseconds since the Unix epoch.
* @param mixed ...$extra Any extra data to include in the telemetry body.
*/
Rollbar::captureTelemetryEvent(
type: EventType::Log,
level: EventLevel::Info,
uuid: guid(),
timestamp: $start,
metadata: new TelemetryBody(
message = 'MyApp::someProcess called with ' . ((string) $userInputString),
method = '',
url = '',
status_code = '',
subtype = '',
stack = null,
from = '',
to = '',
start_timestamp_ms = $start,
end_timestamp_ms = $end,
extra = ['result' => $result]
),
);We use PHP as a worker outside of web requests so being able to include telemetry is a massive gain! |
Description of the change
This is adds support for the Telemetry feature.
Design decisions and overview of the change.
Note: some of our other programing language SDKs capture things like log messages and other items in the telemetry data as part of an auto instrumentation setup. Trying to do this in PHP would require messing with things that could break logging for end user applications. Since most projects will have some sort of logging built in this could easily be wired to the telemeter to capture debug logs etc.
TelemetryStrategytruncation strategy has been included. This is not enabled by default but can be added if large telemetry sets are reducing the quality of the stack frame data.Telemeterinstance is statically attached to theRollbarclass so that the telemetry data is preserved on reconfiguration of the SDK.nullorfalseor callingRollbar::destroy()will remove the telemeter and all the events in the queue.There are probably more details that are important. Feel free to ask questions in the comments.
New configs
The
telemetrykey is now supported in the configs array. It can have any of the following values:nullorfalsewill disable capturing and reporting of telemetry events.trueor[]will result in telemetry being enabled with the default settings.'maxTelemetryEvents'intShould be the most events that will be retained or reported at any given time. If more events are captured they will be removed in a FIFO order. This defaults to100.'filter'null|stringThis is a custom filter FQCN for a telemetry filter class that implements theRollbar\Telemetry\TelemetryFilterInterfaceinterface. See the extensive comments onTelemetryFilterInterfacefor implementation details. This defaults tonull.'includeItemsInTelemetry'boolSet totrueto include errors, logs, and other items captured/reported to the SDK in the telemetry data of subsequent reports. Iffalsethey will not be included. This defaults totrue.'includeIgnoredItemsInTelemetry'boolSet totrueto include items that have been ignored by the SDK in the telemetry data. This defaults tofalse.Type of change
Related issues
Checklists
Development
Code review