本番対応機能
Spring Modulith は、Spring Boot アクチュエーターエンドポイントとしてシステムに関するアーキテクチャ情報を公開するサポートを提供するだけでなく、メトリクスとトレースをキャプチャーすることでアプリケーションモジュール間の相互作用を監視します。本番環境に対応したアプリケーションには両方が必要になる可能性が高いため、これらの機能をアクティブ化する最も便利な方法は、次のように Spring Modulith Insight スターターを使用することです。
これには、アクチュエーターと可観測性のサポートに加え、アクチュエーターの一般的なサポートのための Spring Boot のアクチュエーターの起動が含まれます。アプリケーションを Zipkin (英語) 、Wavefront (英語) などの監視ツールに接続するには、通常 OpenTelemetry (英語) または Brave [GitHub] (英語) を介してさらに依存関係を追加する必要があることに注意してください。詳細については、Spring Boot のリファレンスドキュメントの対応するセクションを参照してください。
アプリケーションモジュールアクチュエーター
アプリケーションモジュール構造は Spring Boot アクチュエーターとして公開できます。アクチュエーターを有効にするには、spring-modulith-actuator
依存関係をプロジェクトに追加します。
Maven
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-actuator</artifactId>
<version>1.2.1</version>
<scope>runtime</scope>
</dependency>
<!-- Spring Boot actuator starter required to enable actuators in general -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>…</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-actuator:1.2.1'
}
<!-- Spring Boot actuator starter required to enable actuators in general -->
dependencies {
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
}
アプリケーションを実行すると、modulith
アクチュエーターリソースが公開されます。
GET http://localhost:8080/actuator
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"health-path": {
"href": "http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
},
"modulith": { (1)
"href": "http://localhost:8080/actuator/modulith",
"templated": false
}
}
}
1 | modulith アクチュエーターリソースがアドバタイズされます。 |
modulith
リソースは次の構造に従います。
JSONPath | 説明 |
---|---|
| アプリケーションモジュールの技術名。 |
| 人間が判読できるアプリケーションモジュールの名前。 |
| アプリケーションモジュールの基本パッケージ。 |
| アプリケーションモジュールのすべての送信依存関係 |
| 依存するアプリケーションモジュールの名前。 |
| ターゲットモジュールに対する依存関係の型。 |
モジュールの配置例は次のようになります。
{
"a": {
"basePackage": "example.a",
"displayName": "A",
"dependencies": []
},
"b": {
"basePackage": "example.b",
"displayName": "B",
"dependencies": [ {
"target": "a",
"types": [ "EVENT_LISTENER", "USES_COMPONENT" ]
} ]
}
}
アプリケーションモジュールの観察
アプリケーションモジュール間の対話をインターセプトして Micrometer スパンを作成し、最終的に Zipkin (英語) などのツールで視覚化できるトレースに至ることができます。インストルメンテーションをアクティブにするには、次のランタイム依存関係をプロジェクトに追加します。
Maven
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-observability</artifactId>
<version>1.2.1</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-observability:1.2.1'
}
可観測性メタデータをパイプするツールに応じて、追加のインフラストラクチャ依存関係を構成する必要があります。詳細については、セットアップにどの依存関係を含めるかについて、対応する Spring Boot ドキュメントを確認してください。 |
これにより、アプリケーションモジュールの API の一部であるすべての Spring コンポーネントが、呼び出しをインターセプトしてそれらの Micrometer スパンを作成するアスペクトで修飾されます。呼び出しトレースのサンプルを以下に示します。
この特定のケースでは、支払いをトリガーするとオーダーの状態が変更され、オーダー完了イベントがトリガーされます。これは、オーダーの別の状態変更をトリガーするエンジンによって非同期的に取得され、数秒間動作し、順番にオーダーの最終的な状態変更をトリガーします。