protected override void OnInitializeTelemetry(
HttpContext platformContext,
RequestTelemetry requestTelemetry,
ITelemetry telemetry)
{
OperationContext parentContext = requestTelemetry.Context.Operation;
// Make sure that RequestTelemetry is initialized.
if (string.IsNullOrEmpty(parentContext.ParentId))
{
if (!string.IsNullOrWhiteSpace(this.ParentOperationIdHeaderName))
{
var parentId = platformContext.Request.UnvalidatedGetHeader(this.ParentOperationIdHeaderName);
if (!string.IsNullOrEmpty(parentId))
{
parentContext.ParentId = parentId;
}
}
}
if (string.IsNullOrEmpty(parentContext.Id))
{
if (!string.IsNullOrWhiteSpace(this.RootOperationIdHeaderName))
{
var rootId = platformContext.Request.UnvalidatedGetHeader(this.RootOperationIdHeaderName);
if (!string.IsNullOrEmpty(rootId))
{
parentContext.Id = rootId;
}
}
if (string.IsNullOrEmpty(parentContext.Id))
{
parentContext.Id = requestTelemetry.Id;
}
}
if (telemetry != requestTelemetry)
{
if (string.IsNullOrEmpty(telemetry.Context.Operation.ParentId))
{
telemetry.Context.Operation.ParentId = requestTelemetry.Id;
}
if (string.IsNullOrEmpty(telemetry.Context.Operation.Id))
{
telemetry.Context.Operation.Id = parentContext.Id;
}
}
}