本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
記錄標註、中繼資料及使用者 ID
注意
End-of-support通知 – 在 2027 年 2 月 25 日, AWS X-Ray 將停止支援 AWS X-Ray SDKs 和協助程式。2027 年 2 月 25 日之後,您將不再收到更新或版本。如需支援時間軸的詳細資訊,請參閱 X-Ray SDK 和協助程式終止支援時間表。建議您遷移至 OpenTelemetry。如需遷移至 OpenTelemetry 的詳細資訊,請參閱從 X-Ray 檢測遷移至 OpenTelemetry 檢測。
在遊戲模型類別中,每次在 DynamoDB 中儲存遊戲時,應用程式都會記錄中繼資料區塊中的Game
物件。應用程式還會另外在標註中記錄遊戲 ID,用於篩選條件表達式。
範例 src/main/java/scorekeep/GameModel.java
– 註釋和中繼資料
import com.amazonaws.xray.AWSXRay;
import com.amazonaws.xray.entities.Segment;
import com.amazonaws.xray.entities.Subsegment;
...
public void saveGame(Game game) throws SessionNotFoundException {
// wrap in subsegment
Subsegment subsegment = AWSXRay.beginSubsegment("## GameModel.saveGame");
try {
// check session
String sessionId = game.getSession();
if (sessionModel.loadSession(sessionId) == null ) {
throw new SessionNotFoundException(sessionId);
}
Segment segment = AWSXRay.getCurrentSegment();
subsegment.putMetadata("resources", "game", game);
segment.putAnnotation("gameid", game.getId());
mapper.save(game);
} catch (Exception e) {
subsegment.addException(e);
throw e;
} finally {
AWSXRay.endSubsegment();
}
}
在移動控制器中,應用程式會使用 記錄使用者 IDssetUser
。區段會將使用者 ID 記錄在單獨的欄位中,並建立索引以用於搜尋。
範例 src/main/java/scorekeep/MoveController.java – 使用者 ID
import com.amazonaws.xray.AWSXRay;
...
@RequestMapping(value="/{userId}", method=RequestMethod.POST)
public Move newMove(@PathVariable String sessionId, @PathVariable String gameId, @PathVariable String userId, @RequestBody String move) throws SessionNotFoundException, GameNotFoundException, StateNotFoundException, RulesException {
AWSXRay.getCurrentSegment().setUser(userId);
return moveFactory.newMove(sessionId, gameId, userId, move);
}