MessageExtensions.ExtractActivity(Message, String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
public static System.Diagnostics.Activity ExtractActivity (this Microsoft.Azure.ServiceBus.Message message, string activityName = default);
static member ExtractActivity : Microsoft.Azure.ServiceBus.Message * string -> System.Diagnostics.Activity
<Extension()>
Public Function ExtractActivity (message As Message, Optional activityName As String = Nothing) As Activity
Parameters
- message
- Message
- activityName
- String
Returns
Examples
async Task ProcessAsync()
{
var message = await messageReceiver.ReceiveAsync();
var activity = message.ExtractActivity();
activity.Start();
Logger.LogInformation($"Message received, Id = {Activity.Current.Id}")
try
{
// process message
}
catch (Exception ex)
{
Logger.LogError($"Exception {ex}, Id = {Activity.Current.Id}")
}
finally
{
activity.Stop();
// Activity is stopped, we no longer have it in Activity.Current, let's user activity now
Logger.LogInformation($"Message processed, Id = {activity.Id}, Duration = {activity.Duration}")
}
}
Note that every log is stamped with Current.Id, that could be used within any nested method call (sync or async) - Current is an ambient context that flows with async method calls.
Remarks
Tracing context is used to correlate telemetry between producer and consumer and represented by 'Diagnostic-Id' and 'Correlation-Context' properties in UserProperties.
.NET SDK automatically injects context when sending message to the ServiceBus (if diagnostics is enabled by tracing system).
'Diagnostic-Id' uniquely identifies operation that enqueued message
'Correlation-Context' is comma separated list of sting key value pairs represeting optional context for the operation.
If there is no tracing context in the message, this method returns Activity without parent.
Returned Activity needs to be started before it can be used (see example below)
Applies to
Azure SDK for .NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기