Skip to content

Commit bded75d

Browse files
committed
Added Request tracing and case for snapshot reference is registered for refresh by not called in select
1 parent cdf559b commit bded75d

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationProvider.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ private async Task<Dictionary<string, string>> PrepareData(Dictionary<string, Co
630630
if (_requestTracingEnabled && _requestTracingOptions != null)
631631
{
632632
_requestTracingOptions.ResetAiConfigurationTracing();
633+
_requestTracingOptions.ResetSnapshotReferenceTracing();
633634
}
634635

635636
foreach (KeyValuePair<string, ConfigurationSetting> kvp in data)
@@ -877,6 +878,12 @@ await CallWithRequestTracing(async () =>
877878
{
878879
if (setting.ContentType == SnapshotReferenceConstants.ContentType)
879880
{
881+
// Track snapshot reference usage for telemetry
882+
if (_requestTracingEnabled && _requestTracingOptions != null)
883+
{
884+
_requestTracingOptions.UpdateSnapshotReferenceTracing(setting.ContentType);
885+
}
886+
880887
var snapshotReference = new SnapshotReference { SnapshotName = SnapshotReferenceParser.Parse(setting) };
881888

882889
Dictionary<string, ConfigurationSetting> resolvedSettings = await Resolve(snapshotReference, client, cancellationToken).ConfigureAwait(false);
@@ -945,11 +952,11 @@ private async Task<Dictionary<string, ConfigurationSetting>> Resolve(SnapshotRef
945952
return resolvedSettings;
946953
}
947954

948-
ConfigurationSnapshot snapshot;
955+
ConfigurationSnapshot snapshot = null;
949956

950957
try
951958
{
952-
snapshot = await client.GetSnapshotAsync(snapshotReference.SnapshotName, cancellationToken: cancellationToken).ConfigureAwait(false);
959+
await CallWithRequestTracing(async () => snapshot = await client.GetSnapshotAsync(snapshotReference.SnapshotName, cancellationToken: cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
953960
}
954961
catch (RequestFailedException rfe) when (rfe.Status == (int)HttpStatusCode.NotFound)
955962
{
@@ -1013,8 +1020,31 @@ private async Task<Dictionary<KeyValueIdentifier, ConfigurationSetting>> LoadKey
10131020
// If the key-value was found, store it for updating the settings
10141021
if (watchedKv != null)
10151022
{
1016-
watchedIndividualKvs[watchedKeyLabel] = new ConfigurationSetting(watchedKv.Key, watchedKv.Value, watchedKv.Label, watchedKv.ETag);
1017-
existingSettings[watchedKey] = watchedKv;
1023+
if (watchedKv.ContentType == SnapshotReferenceConstants.ContentType)
1024+
{
1025+
// Track snapshot reference usage for telemetry
1026+
if (_requestTracingEnabled && _requestTracingOptions != null)
1027+
{
1028+
_requestTracingOptions.UpdateSnapshotReferenceTracing(watchedKv.ContentType);
1029+
}
1030+
1031+
var snapshotReference = new SnapshotReference { SnapshotName = SnapshotReferenceParser.Parse(watchedKv) };
1032+
1033+
Dictionary<string, ConfigurationSetting> resolvedSettings = await Resolve(snapshotReference, client, cancellationToken).ConfigureAwait(false);
1034+
1035+
foreach (KeyValuePair<string, ConfigurationSetting> resolvedSetting in resolvedSettings)
1036+
{
1037+
existingSettings[resolvedSetting.Key] = resolvedSetting.Value;
1038+
}
1039+
1040+
// Only track the snapshot reference itself for refresh monitoring, since snapshots are immutable
1041+
watchedIndividualKvs[watchedKeyLabel] = new ConfigurationSetting(watchedKv.Key, watchedKv.Value, watchedKv.Label, watchedKv.ETag);
1042+
}
1043+
else
1044+
{
1045+
watchedIndividualKvs[watchedKeyLabel] = new ConfigurationSetting(watchedKv.Key, watchedKv.Value, watchedKv.Label, watchedKv.ETag);
1046+
existingSettings[watchedKey] = watchedKv;
1047+
}
10181048
}
10191049
}
10201050

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Constants/RequestTracingConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ internal class RequestTracingConstants
2727
public const string DevEnvironmentValue = "Dev";
2828
public const string KeyVaultConfiguredTag = "UsesKeyVault";
2929
public const string KeyVaultRefreshConfiguredTag = "RefreshesKeyVault";
30+
public const string SnapshotReferenceTag = "UsesSnapshotRef";
31+
public const string SnapshotReferenceCountKey = "SnapRefCount";
3032
public const string ReplicaCountKey = "ReplicaCount";
3133
public const string FeaturesKey = "Features";
3234
public const string LoadBalancingEnabledTag = "LB";

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/RequestTracingOptions.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ internal class RequestTracingOptions
8282
/// </summary>
8383
public bool UsesAIChatCompletionConfiguration { get; set; } = false;
8484

85+
/// <summary>
86+
/// Flag to indicate whether any key-value uses snapshot references.
87+
/// </summary>
88+
public bool UsesSnapshotReferences { get; set; } = false;
89+
90+
/// <summary>
91+
/// Count of snapshot references that have been resolved during configuration loading.
92+
/// </summary>
93+
public int SnapshotReferenceCount { get; set; } = 0;
94+
8595
/// <summary>
8696
/// Resets the AI configuration tracing flags.
8797
/// </summary>
@@ -91,6 +101,15 @@ public void ResetAiConfigurationTracing()
91101
UsesAIChatCompletionConfiguration = false;
92102
}
93103

104+
/// <summary>
105+
/// Resets the snapshot reference tracing counters and flags.
106+
/// </summary>
107+
public void ResetSnapshotReferenceTracing()
108+
{
109+
UsesSnapshotReferences = false;
110+
SnapshotReferenceCount = 0;
111+
}
112+
94113
/// <summary>
95114
/// Updates AI configuration tracing flags based on the provided content type.
96115
/// </summary>
@@ -111,6 +130,21 @@ public void UpdateAiConfigurationTracing(string contentTypeString)
111130
}
112131
}
113132

133+
/// <summary>
134+
/// Updates snapshot reference tracing when a snapshot reference is encountered.
135+
/// </summary>
136+
/// <param name="contentTypeString">The content type to analyze.</param>
137+
public void UpdateSnapshotReferenceTracing(string contentTypeString)
138+
{
139+
if (!string.IsNullOrWhiteSpace(contentTypeString) &&
140+
contentTypeString.TryParseContentType(out ContentType contentType) &&
141+
contentType.IsSnapshotReference())
142+
{
143+
UsesSnapshotReferences = true;
144+
SnapshotReferenceCount++;
145+
}
146+
}
147+
114148
/// <summary>
115149
/// Checks whether any tracing feature is used.
116150
/// </summary>
@@ -120,7 +154,8 @@ public bool UsesAnyTracingFeature()
120154
return IsLoadBalancingEnabled ||
121155
IsSignalRUsed ||
122156
UsesAIConfiguration ||
123-
UsesAIChatCompletionConfiguration;
157+
UsesAIChatCompletionConfiguration ||
158+
UsesSnapshotReferences;
124159
}
125160

126161
/// <summary>
@@ -171,6 +206,16 @@ public string CreateFeaturesString()
171206
sb.Append(RequestTracingConstants.AIChatCompletionConfigurationTag);
172207
}
173208

209+
if (UsesSnapshotReferences)
210+
{
211+
if (sb.Length > 0)
212+
{
213+
sb.Append(RequestTracingConstants.Delimiter);
214+
}
215+
216+
sb.Append(RequestTracingConstants.SnapshotReferenceTag);
217+
}
218+
174219
return sb.ToString();
175220
}
176221
}

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ private static string CreateCorrelationContextHeader(RequestType requestType, Re
196196
correlationContextTags.Add(RequestTracingConstants.KeyVaultRefreshConfiguredTag);
197197
}
198198

199+
if (requestTracingOptions.UsesSnapshotReferences)
200+
{
201+
correlationContextTags.Add(RequestTracingConstants.SnapshotReferenceTag);
202+
}
203+
204+
if (requestTracingOptions.SnapshotReferenceCount > 0)
205+
{
206+
correlationContextKeyValues.Add(new KeyValuePair<string, string>(RequestTracingConstants.SnapshotReferenceCountKey, requestTracingOptions.SnapshotReferenceCount.ToString()));
207+
}
208+
199209
if (requestTracingOptions.IsFailoverRequest)
200210
{
201211
correlationContextTags.Add(RequestTracingConstants.FailoverRequestTag);

0 commit comments

Comments
 (0)