change to allow nullable IApplicationIdProvider
This commit is contained in:
Родитель
5a4bbfb90d
Коммит
1c2fe70175
|
@ -37,11 +37,11 @@
|
|||
/// Initializes a new instance of the <see cref="T:HostingDiagnosticListener"/> class.
|
||||
/// </summary>
|
||||
/// <param name="client"><see cref="TelemetryClient"/> to post traces to.</param>
|
||||
/// <param name="applicationIdProvider">Provider for resolving application Id to be used by Correlation.</param>
|
||||
/// <param name="applicationIdProvider">Nullable Provider for resolving application Id to be used by Correlation.</param>
|
||||
public HostingDiagnosticListener(TelemetryClient client, IApplicationIdProvider applicationIdProvider)
|
||||
{
|
||||
this.client = client ?? throw new ArgumentNullException(nameof(client));
|
||||
this.applicationIdProvider = applicationIdProvider ?? throw new ArgumentNullException(nameof(applicationIdProvider));
|
||||
this.applicationIdProvider = applicationIdProvider;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
@ -236,7 +236,8 @@
|
|||
!string.IsNullOrEmpty(requestTelemetry.Context.InstrumentationKey) &&
|
||||
(!responseHeaders.ContainsKey(RequestResponseHeaders.RequestContextHeader) || HttpHeadersUtilities.ContainsRequestContextKeyValue(responseHeaders, RequestResponseHeaders.RequestContextTargetKey)))
|
||||
{
|
||||
if (this.applicationIdProvider.TryGetApplicationId(requestTelemetry.Context.InstrumentationKey, out string applicationId))
|
||||
string applicationId = null;
|
||||
if (this.applicationIdProvider?.TryGetApplicationId(requestTelemetry.Context.InstrumentationKey, out applicationId) ?? false)
|
||||
{
|
||||
HttpHeadersUtilities.SetRequestContextKeyValue(responseHeaders, RequestResponseHeaders.RequestContextTargetKey, applicationId);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
/// Initializes a new instance of the <see cref="OperationCorrelationTelemetryInitializer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpContextAccessor">Accessor for retrieving the current HTTP context.</param>
|
||||
/// <param name="applicationIdProvider">Provider for resolving application Id to be used by Correlation.</param>
|
||||
/// <param name="applicationIdProvider">Nullable Provider for resolving application Id to be used by Correlation.</param>
|
||||
public OperationCorrelationTelemetryInitializer(IHttpContextAccessor httpContextAccessor, IApplicationIdProvider applicationIdProvider) : base(httpContextAccessor)
|
||||
{
|
||||
this.applicationIdProvider = applicationIdProvider ?? throw new ArgumentNullException(nameof(applicationIdProvider));
|
||||
this.applicationIdProvider = applicationIdProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -38,6 +38,7 @@
|
|||
{
|
||||
string headerCorrelationId = HttpHeadersUtilities.GetRequestContextKeyValue(currentRequest.Headers, RequestResponseHeaders.RequestContextSourceKey);
|
||||
|
||||
string applicationId = null;
|
||||
// If the source header is present on the incoming request, and it is an external component (not the same ikey as the one used by the current component), populate the source field.
|
||||
if (!string.IsNullOrEmpty(headerCorrelationId))
|
||||
{
|
||||
|
@ -46,7 +47,8 @@
|
|||
{
|
||||
requestTelemetry.Source = headerCorrelationId;
|
||||
}
|
||||
else if (this.applicationIdProvider.TryGetApplicationId(requestTelemetry.Context.InstrumentationKey, out string applicationId) && applicationId != headerCorrelationId)
|
||||
else if ((this.applicationIdProvider?.TryGetApplicationId(requestTelemetry.Context.InstrumentationKey, out applicationId) ?? false)
|
||||
&& applicationId != headerCorrelationId)
|
||||
{
|
||||
requestTelemetry.Source = headerCorrelationId;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче