---
schema_version: "1"
id: 2a1f5edac4f47da2eeab96da6c174bb0142d32a2d632d26237a72a6c6af53e79
title: Tracing Module を使用したフロー実行中の相関 ID の変更
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/tracing-module/1.1/tracing-module-with-correlationid.md
canonical_url: https://docs.mulesoft.com/jp/tracing-module/1.1/tracing-module-with-correlationid
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 7c45d1491782c8db8b4c833037c5794cbdb4418f381f8c2b28484570b111dd30
description: MuleSoft Documentation Site
release: "1.1"
latest: false
---
# Tracing Module を使用したフロー実行中の相関 ID の変更

次のような場合は、特定のスコープまたは一連の操作でイベントの相関 ID を変更することが必要になることがあります。

- **For Each**​ スコープ内でデータベースクエリの結果を処理しており、イベントを、処理中のレジスターと相関する必要がある。
- JMS メッセージキューをコンシュームしており、トレーサビリティの目的で JMS 相関 ID を使用して続行する必要がある。

これらのシナリオでは、Tracing Module ​**With CorrelationID**​ スコープを使用して、そのスコープの実行中に相関 ID を変更することができます。

## [](#with-correlationid-スコープを設定する)With CorrelationID スコープを設定する

次の Mule アプリケーションの例では、Studio で ​**With CorrelationID**​ スコープを設定します。

![With CorrelationID スコープフローが表示されているフロー](/mulesoft/current/ja-jp/tracing-module/1.1/_images/tracing-module-scope-flow.png)

1. Studio の ​**\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[HTTP\] > \[Listener\]**​ を選択します。
2. **\[Listener\]**​ を Studio キャンバスにドラッグします。
3. **\[Path (パス)\]**​ を ​`/test`​ に設定します。
4. **\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (​**+**​) をクリックして、アプリケーション内のすべてのソースのインスタンスで使用できるグローバル要素を設定します。
5. HTTP リスナーのグローバル要素を設定して、​**\[OK\]**​ をクリックします。
6. **\[Set Payload\]**​ コンポーネントを \[HTTP\] の \[Listener\] の右にドラッグします。
7. **\[Value (値)\]**​ を「​`some`​」に設定します。
8. Studio の ​**\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[Logger\]**​ を選択します。
9. **\[Logger\]**​ を \[Set Payload\] の右にドラッグします。
10. **\[Message (メッセージ)\]**​ を ​`#[payload]`​ に設定します。
11. **\[Level (レベル)\]**​ を ​`WARN`​ に設定します。
12. **\[With CorrelationID\]**​ スコープを Studio キャンバスにドラッグします。
13. **\[Correlation id (相関 ID)\]**​ を ​`#[correlationId ++ '-EXAMPLE']`​ に設定します。
    
    ![\[Correlation ID (相関 ID)\] 項目がある With CorrelationID スコープの設定ウィンドウ](_images/tracing-module-with-correlationid.png)
14. 別の ​**\[Logger\]**​ コンポーネントを ​**\[With CorrelationID\]**​ スコープにドラッグします。
15. **\[Message (メッセージ)\]**​ を ​`#[payload]`​ に設定します。
16. **\[Level (レベル)\]**​ を ​`WARN`​ に設定します。
17. Mule アプリケーションを保存して実行します。
18. コマンドラインで ​`curl localhost:8081/test`​ を実行して、アプリケーションをテストします。

アプリケーションの出力ログは次のようになります。

```xml
WARN  2021-03-30 16:46:11,269 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/1; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
WARN  2021-03-30 16:46:11,271 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/2/processors/0; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee-EXAMPLE] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
WARN  2021-03-30 16:46:11,274 [[MuleRuntime].uber.05: [test-project-app].example.CPU_LITE @6d3b5ad] [processor: example/processors/3; event: bad0e5b0-9191-11eb-a0b3-36548d51aeee] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: some
```

## [](#with-correlationid-スコープを設定する-xml)With CorrelationID スコープを設定する XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracing="http://www.mulesoft.org/schema/mule/tracing"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/tracing http://www.mulesoft.org/schema/mule/tracing/current/mule-tracing.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
	<http:listener-config name="HTTP_Listener_config" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<flow name="tracingmodule2Flow"  >
		<http:listener config-ref="HTTP_Listener_config" path="/test"/>
		<set-payload value="some" />
		<logger level="WARN" message="#[payload]"/>
		<tracing:with-correlation-id correlationId="#[correlationId ++ '-EXAMPLE']">
			<logger level="WARN"  message="#[payload]"/>
		</tracing:with-correlation-id>
	</flow>
</mule>
```

## [](#関連情報)関連情報

- [Tracing Module の例](https://docs.mulesoft.com/jp/tracing-module/1.1/tracing-module-examples)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)