Skip to content

テレメトリ送信をGraphQLのsendLocation/sendLogEvent mutationへ移行 - #6388

Merged
TinyKitten merged 2 commits into
devfrom
feature/telemetry-graphql-migration
Jul 11, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/telemetry-graphql-migration

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

概要

実験的テレメトリの送信を、REST API (/api/location・/api/log) から新テレメトリ基盤の GraphQL mutation (sendLocation・sendLogEvent) へ移行する。既存の駅情報 GraphQL とは別基盤のため、既存の GraphQL クライアントには乗せず従来どおり素の fetch で送信する。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • 位置情報送信を POST {baseUrl}/api/location から sendLocation mutation (POST {baseUrl}/graphql) に置き換え
  • ログ送信を POST {baseUrl}/api/log から sendLogEvent mutation に置き換え
  • 実稼働エンドポイントの introspection で確認したスキーマ差分に対応
    • sessionId(必須): expo-crypto の randomUUID() で初回送信時に生成し、位置情報・ログの両送信で共有
    • coords.speed: サーバ仕様が km/h のため expo-location の m/s から換算(負値=測位不能は null)
    • batteryState: expo-battery の数値 enum を文字列 enum (unknown/unplugged/charging/full) にマッピング
    • appVersion・platform・channel(sendLogEvent の必須項目): expo-application / Platform.OS / isDevApp から取得(useFeedback と同じ慣習)
  • GraphQL のエラーが HTTP 200 + errors 配列で返る形式に合わせてレスポンス処理を変更(実エンドポイントで確認済み)
  • テストを GraphQL 前提に更新(mutation 名でリクエストを判別するヘルパー追加、payload 検証の拡充)

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

  • 改善
    • ログと位置情報の送信処理を刷新し、テレメトリデータの連携精度と安定性を向上しました。
    • 開発版・本番版に応じて適切な送信先を利用するようになりました。
    • 位置情報の速度やバッテリー情報を正しく変換して送信します。
    • ログに含まれるトークン風文字列を引き続き秘匿します。
    • 通信エラーやサーバーからの警告を検知しやすくなりました。

@TinyKitten TinyKitten self-assigned this Jul 11, 2026
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 17 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b1347b7-7134-49f0-a16f-765c4f28eb9a

📥 Commits

Reviewing files that changed from the base of the PR and between 7888f66 and 9b2e640.

📒 Files selected for processing (1)
  • src/hooks/useTelemetrySender.ts
📝 Walkthrough

Walkthrough

useTelemetrySender のログ・位置情報送信をRESTからGraphQL mutationへ移行し、セッションID、プラットフォーム、チャネル、位置情報変換、GraphQLエラー処理を追加しました。関連テストもGraphQL payloadとレスポンス形式に対応しています。

Changes

Telemetry GraphQL migration

Layer / File(s) Summary
GraphQL契約とログ送信
src/hooks/useTelemetrySender.ts
ログ・位置情報用のGraphQLスキーマ、レスポンス検証、セッションID生成、プラットフォーム/チャネル設定を追加し、ログ送信をsendLogEvent mutationへ変更しました。
位置情報mutationと応答処理
src/hooks/useTelemetrySender.ts
位置情報をGraphQL入力へ変換し、速度・バッテリー状態を変換してsendLocation mutationへ送信します。GraphQLエラーと警告の処理も更新しました。
GraphQL送信テスト
src/hooks/useTelemetrySender.enabled.test.tsx
GraphQL mutationの抽出ヘルパーを追加し、ログ・位置情報payload、秘匿処理、Authorization、エラー応答を検証するよう変更しました。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TelemetryHook as useTelemetrySender
  participant Crypto as Crypto.randomUUID
  participant GraphQL as GraphQL endpoint
  participant Tests as telemetry tests
  TelemetryHook->>Crypto: generate and retain sessionId
  TelemetryHook->>GraphQL: sendLogEvent or sendLocation with variables.input
  GraphQL-->>TelemetryHook: return data, errors, and warning
  Tests->>GraphQL: inspect mutation request and response
Loading

Possibly related PRs

  • TrainLCD/MobileApp#6375: useTelemetrySender と関連テストで、Android GNSS購読削除を扱っているため直接関連します。

Poem

ぴょんと跳ねてGraphQLへ、
ログも位置もひとまとめ。
セッションIDは仲良く続き、
速度と電池も姿を変える。
にんじん色のテストが歌う、
「送信成功、ぴょん!」

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 主な変更であるテレメトリ送信のRESTからGraphQL mutationへの移行を簡潔に表しています。
Description check ✅ Passed テンプレートの主要項目が埋まっており、概要・変更内容・テストが具体的に記載されています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/telemetry-graphql-migration

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the react label Jul 11, 2026
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/hooks/useTelemetrySender.enabled.test.tsx (1)

18-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

固定UUIDモックではセッションIDの再利用を検証できません。

毎回同じ値が返るため、送信ごとにUUIDを再生成する回帰でもテストが通ります。呼び出しごとに異なる値を返し、ログと位置情報のID一致、および randomUUID の呼び出し回数を検証してください。

As per coding guidelines, 「挙動を変更する際は、同じ変更セット内でテストも更新または追加すること」です。

Also applies to: 155-165, 357-377

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useTelemetrySender.enabled.test.tsx` around lines 18 - 20, The
fixed randomUUID mock in the telemetry tests cannot detect session ID
regeneration. Update the expo-crypto mock in useTelemetrySender tests to return
distinct IDs per call, then assert that log and location payloads share the same
session ID and verify the expected randomUUID call count across the relevant
test cases.

Source: Coding guidelines

src/hooks/useTelemetrySender.ts (1)

61-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

GraphQL操作名をリポジトリ規約に合わせてください。

SendLocation と SendLogEvent を、例えば TelemetrySendLocationQuery、TelemetrySendLogEventQuery のような規約準拠名へ変更してください。

As per coding guidelines, 「GraphQL 操作名は FeatureVerbQuery 形式にすること」です。

Also applies to: 112-118

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useTelemetrySender.ts` around lines 61 - 68, GraphQL operation
names in the telemetry mutations violate the repository’s naming convention.
Rename the operations in SEND_LOCATION_MUTATION and the corresponding
SEND_LOG_EVENT mutation from SendLocation and SendLogEvent to
FeatureVerbQuery-style names such as TelemetrySendLocationQuery and
TelemetrySendLogEventQuery, updating all references as needed.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useTelemetrySender.ts`:
- Around line 70-82:
SendLocationResponseおよび同ファイル内の対象レスポンススキーマで、data.sendLocation/send*または空でないerrors配列のいずれかを必須にし、空の{}を受理しないようrefine等で検証してください。各safeParse失敗時は黙殺せず、レスポンス内容と解析エラーをconsole.errorへ記録するよう、該当する送信処理も修正してください。

---

Nitpick comments:
In `@src/hooks/useTelemetrySender.enabled.test.tsx`:
- Around line 18-20: The fixed randomUUID mock in the telemetry tests cannot
detect session ID regeneration. Update the expo-crypto mock in
useTelemetrySender tests to return distinct IDs per call, then assert that log
and location payloads share the same session ID and verify the expected
randomUUID call count across the relevant test cases.

In `@src/hooks/useTelemetrySender.ts`:
- Around line 61-68: GraphQL operation names in the telemetry mutations violate
the repository’s naming convention. Rename the operations in
SEND_LOCATION_MUTATION and the corresponding SEND_LOG_EVENT mutation from
SendLocation and SendLogEvent to FeatureVerbQuery-style names such as
TelemetrySendLocationQuery and TelemetrySendLogEventQuery, updating all
references as needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1a955eb-57bf-4381-848a-fa501080682f

📥 Commits

Reviewing files that changed from the base of the PR and between cd9a3aa and 7888f66.

📒 Files selected for processing (2)
  • src/hooks/useTelemetrySender.enabled.test.tsx
  • src/hooks/useTelemetrySender.ts

Comment thread src/hooks/useTelemetrySender.ts Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 1 file(s) based on 1 CodeRabbit feedback item(s).

Files modified:

  • src/hooks/useTelemetrySender.ts

Commit: 9b2e64048

The latest autofix changes are on the feature/telemetry-graphql-migration branch.

@TinyKitten
TinyKitten merged commit 2dcdaf9 into dev Jul 11, 2026
6 checks passed
@TinyKitten
TinyKitten deleted the feature/telemetry-graphql-migration branch July 11, 2026 06:37
@TinyKitten TinyKitten mentioned this pull request Jul 11, 2026
4 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant