I am able to examine Request Headers at my Service Fabric Controller entry point by specifying the following method signature:
public async Task<IActionResult> Copy([FromHeader] TelemetryHeaders headers)
where TelemetryHeaders
is defined as:
public class TelemetryHeaders
{
// the following properties are my guesses as to what the headers might be named
[FromHeader]
[JsonProperty(PropertyName = "OperationId")]
public string OperationId {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "ParentId ")]
public string ParentId {get; set;}
// the following properties are defined by the W3C standard for telemetry headers
[FromHeader]
[JsonProperty(PropertyName = "parent-id")]
public string W3C_ParentId {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "trace-id")]
public string W3C_TraceId {get; set;}
// the following properties are defined by the HTTP Request standard for telemetry headers
[FromHeader]
[JsonProperty(PropertyName = "Request-Id")]
public string HTTP_RequestId {get; set;}
// the following properties are defined in
// Microsoft.ApplicationInsights.ServiceFabric/RequestResponseHeaders.cs and/or
// Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/RequestResponseHeaders.cs
[FromHeader]
[JsonProperty(PropertyName = "Request-Context")]
public string RequestContextHeader {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "appId")]
public string RequestContextCorrelationSourceKey {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "appId")]
public string RequestContextCorrelationTargetKey {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "roleName")]
public string RequestContextSourceRoleNameKey {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "Microsoft.ApplicationInsights.ServiceFabric.ParentId")]
public string ParentIdHeaderName {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "Microsoft.ApplicationInsights.ServiceFabric.CorrelationContext")]
public string CorrelationContextHeaderName {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "appId")]
public string RequestContextSourceKey {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "appId")]
public string RequestContextTargetKey {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "Request-Id")]
public string RequestIdHeader {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "Correlation-Context")]
public string CorrelationContextHeader {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "traceparent")]
public string TraceParentHeader {get; set;}
[FromHeader]
[JsonProperty(PropertyName = "tracestate")]
public string TraceStateHeader {get; set;}
}
In addition, my Startup.cs contains the following configuration code.
var appInsightsConnection = this.Configuration["ClientGatewayOptions:ClientGateway_AppInsightsConnection"];
var options = new ApplicationInsightsServiceOptions
{
ConnectionString = appInsightsConnection,
EnablePerformanceCounterCollectionModule = true,
EnableRequestTrackingTelemetryModule = true,
EnableEventCounterCollectionModule = true,
EnableDependencyTrackingTelemetryModule = true,
EnableAppServicesHeartbeatTelemetryModule = true,
EnableAzureInstanceMetadataTelemetryModule = true,
EnableQuickPulseMetricStream = true,
EnableAdaptiveSampling = true,
EnableHeartbeat = true,
AddAutoCollectedMetricExtractor = true,
EnableDiagnosticsTelemetryModule = true,
};
options.RequestCollectionOptions.InjectResponseHeaders = true;
options.RequestCollectionOptions.TrackExceptions = true;
services.AddApplicationInsightsTelemetry(options);
I generate my request using Postman and specify values for OperationId and ParentId. When I hit a breakpoint at the top of the controller, I see the values I explicitly set in my Postman script, but I do not see any headers that I expect the Azure Service Fabric infrastructure to set.
In addition,
var currentActivity = Activity.Current;
which works fine in Azure Functions, is always null
in Service Fabric.
And finally,
var context = _telemetryClient.Context;
while context is not null
, all of its values are either empty
or null
.
So, how do I access the telemetry headers I'm looking for?
Thanks for your assistance.