Skip to content

Commit 0283f9f

Browse files
committed
Added section about correlating messages in Durable Functions
1 parent 01a9ade commit 0283f9f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/how-to-correlate-messages-across-services.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,41 @@ log.Info("A log message");
228228

229229
Please notice that `correlationid` in both examples must be in all lowercase.
230230

231+
### Durable Azure Functions
232+
233+
Both the in-process and out-of-process (Isolated) models for developing Azure Functions come with the option of Durable Functions. By default, each activity function (functions initiated by the orchestrator) starts its own `Activity` meaning that log messages sent across multiple functions will not be correlated. To make this work, Durable Functions support *Distributed Tracing*, which can be enabled in the `host.json` file:
234+
235+
```json
236+
{
237+
"extensions": {
238+
"durableTask": {
239+
"tracing": {
240+
"distributedTracingEnabled": true,
241+
"version": "V2"
242+
}
243+
}
244+
}
245+
}
246+
```
247+
248+
Once enabled, you will need to install the `Elmah.Io.Client.Extensions.Correlation` NuGet package and call `WithCorrelationIdFromActivity` as shown previously:
249+
250+
```csharp
251+
app.Services.AddLogging(logging =>
252+
{
253+
logging.AddElmahIo(o =>
254+
{
255+
// ...
256+
o.OnMessage = msg =>
257+
{
258+
msg.WithCorrelationIdFromActivity();
259+
};
260+
});
261+
});
262+
```
263+
264+
Please note that when enabling Distributed Tracing without having configured Application Insights, the functions runtime will show a warning when launching the function app. We are trying to convince Microsoft to either remove this or change it to an information message, since *Distributed Tracing* doesn't require Application Insights.
265+
231266
## W3C Trace Context
232267

233268
The class `Activity` has been mentioned a couple of times already. Let's take a look at what that is and how it relates to W3C Trace Context. Trace Context is a specification by W3C for implementing distributed tracing across multiple processes which are already widely adopted. If you generate a trace identifier in a client initiating a chain of events, different Microsoft technologies like ASP.NET Core already pick up the extended set of headers and include those as part of log messages logged through Microsoft.Extensions.Logging.

0 commit comments

Comments
 (0)