Sentry CronsのSTATUS列が Timed Out になってしまう

Sentry Cronsでバッチ処理監視をいれたんだよね

Set Up Crons | Sentry for PHP
Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application.

いいわね

公式サイトのサンプルコードをコピペしたんだけど

// 1つ目の開始通知
// 🟡 Notify Sentry your job is running:
$checkInId = \Sentry\captureCheckIn(
    slug: '<monitor-slug>',
    status: CheckInStatus::inProgress()
);

// Execute your scheduled task here...

// 2つ目の完了通知
// 🟢 Notify Sentry your job has completed successfully:
\Sentry\captureCheckIn(
    slug: '<monitor-slug>',
    status: CheckInStatus::ok(),
    checkInId: $checkInId,
);
Code language: PHP (php)

<monitor-slug> は置き換えたのよね

1つ目の開始通知(CheckInStatus::inProgress())は無事届いたんだけど

2つ目の完了通知(CheckInStatus::ok())が届いていないみたいなんだ

どちらも captureCheckIn なのね

Sentry consoleの STATUS列に Timed Out の履歴がたまってしまったよ

バッチ処理の時間はかかるの?

通常は 0.1秒 もかからないはずなんだ

バッチ処理は正常終了しているのかしら?

cron実行結果のメール通知は届いているよ

完了通知の行を通っているのか確認した?

local環境で xDebug で1行づつステップ実行して、通っていることを確認したよ

興味本位で聞くんだけど、1つ目の captureCheckIn の返値が $checkinId なのよね。2つ目の captureCheckIn の返値って何が返ってくるのかしら?

調べてみるね

1つ目が 0d11****************************
2つ目が 845d****************************

2回とも $checkinId を発行しているように見えるわね

ぼくの Sentry SDK の使い方が悪いのかな?

githubのソースを確認してみるね

sentry-php/src/functions.php at 071576d96eb637152b2a36c60a6cc18a8222cec8 ?? getsentry/sentry-php
The official PHP SDK for Sentry (sentry.io). Contribute to getsentry/sentry-php development by creating an account on Gi...
/**
 * Captures a check-in and sends it to Sentry.
 *
 * @param string             $slug          Identifier of the Monitor
 * @param CheckInStatus      $status        The status of the check-in
 * @param int|float|null     $duration      The duration of the check-in
 * @param MonitorConfig|null $monitorConfig Configuration of the Monitor
 * @param string|null        $checkInId     A check-in ID from the previous check-in
 */
function captureCheckIn(string $slug, CheckInStatus $status, $duration = null, ?MonitorConfig $monitorConfig = null, ?string $checkInId = null): ?stringCode language: PHP (php)

$status は引数の2番目、$checkInId は引数の5番目ね

!!

ぼくのコードは $checkInId は引数の3番目だよ?コピペしただけなんだけど

// ぼくのコード
// 2つ目の完了通知
// 🟢 Notify Sentry your job has completed successfully:
\Sentry\captureCheckIn(
    '<monitor-slug>',
    CheckInStatus::ok(),
    $checkInId,
);Code language: PHP (php)
// 公式サイトのコード
// 2つ目の完了通知
// 🟢 Notify Sentry your job has completed successfully:
\Sentry\captureCheckIn(
    slug: '<monitor-slug>',
    status: CheckInStatus::ok(),
    checkInId: $checkInId,
);Code language: PHP (php)

あなたのコードには「引数の名前」がないわよ

!!

わかった!

Sentryのサンプルコードからコピペしたんだけど

該当のアプリケーションは PHP 7.4 なんだ、名前付き引数を使えないんだ

引数名を削除した

コピペだけじゃないってことね

PhpStormやphpstanの警告はなかったのかしら?

そういえば phpstan に型が違うよと警告されていたんだけど、Sentryのサンプルコードが正しいはずだよねと、脳死で phpstan-ignore-next-line で無視していたんだ

引数名を削除したから、全ての引数を書いたよ

// PHP7.4
// 引数名を削除したら、全ての引数を書かないとね
// 🟢 Notify Sentry your job has completed successfully:
\Sentry\captureCheckIn(
    '<monitor-slug>',
    CheckInStatus::ok(),
    null,
    null,
    $checkInId,
);
Code language: PHP (php)

Sentry console で無事、グリーンの Okay になったよ

PhpStormやphpstanの警告をあまく見てはいけないってことね

タイトルとURLをコピーしました