Enable Access to Dependency Request Objects in DependencyCollector #900
Description
Opening this item per comments on the pull request -- consolidating discussions referenced items.
Please reference the issues and pull request for additional details and\or discussion.
Consumers of the dependency collection package would like to be able to populate additional data in the tracked telemetry through implementing ITelemetryInitializer classes. At present, this is not possible given only the data passed in the call to Initialize() is the dependency telemetry item itself with pre-defined fields populated from within the dependency collector.
The ask is to track key data in the dependency collection and provide access to it as part of the ITelemetry item passed to the initializers.
Here is a sample of intended use -- reporting a debug-id value from an http response:
public class SampleTelemetryInitializer : ITelemetryInitializer
{
private const string DebugHeaderName = "debug-id";
public void Initialize(ITelemetry telemetry)
{
var dependencyTelemetry = telemetry as DependencyTelemetry;
if (dependencyTelemetry != null && dependencyTelemetry.TryGetOperationDetail("HttpResponse", out var reponseObject))
{
IEnumerable<string> debugData = null;
var response = reponseObject as HttpResponseMessage;
if (response?.Headers?.TryGetValues(DebugHeaderName, out debugData) ?? false)
{
if (debugData != null)
{
dependencyTelemetry.Properties.Add(DebugHeaderName, string.Join(",", debugData));
}
}
}
}
}