Skip to content

Commit 7943dd3

Browse files
Jade Wangclaude
andcommitted
Fix telemetry HttpClient to use full auth/proxy handler chain
CreateTelemetryHttpClient was creating a plain HttpClient without auth, causing 401 Unauthorized on /telemetry-ext. Now uses the same handler pipeline as feature flag client (PAT, OAuth, WIF, proxy support). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fa49977 commit 7943dd3

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

csharp/src/DatabricksConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ private async Task InitializeTelemetryAsync(Activity? activity = null)
633633
bool isAuthenticated = IsAuthenticated();
634634

635635
// Create HTTP client for telemetry export
636-
HttpClient telemetryHttpClient = HttpClientFactory.CreateTelemetryHttpClient(Properties);
636+
HttpClient telemetryHttpClient = HttpClientFactory.CreateTelemetryHttpClient(Properties, _host, s_assemblyVersion);
637637

638638
// Get or create telemetry client from manager (per-host singleton)
639639
_telemetryClient = TelemetryClientManager.GetInstance().GetOrCreateClient(

csharp/src/Http/HttpClientFactory.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,30 @@ public static HttpClient CreateFeatureFlagHttpClient(
116116
/// <summary>
117117
/// Creates an HttpClient for telemetry export.
118118
/// Includes TLS, proxy settings, and full authentication handler chain.
119-
/// Similar to feature flag client but optimized for telemetry endpoint.
119+
/// Uses the same auth/proxy pipeline as feature flag client.
120120
/// </summary>
121121
/// <param name="properties">Connection properties.</param>
122+
/// <param name="host">The Databricks host (without protocol).</param>
123+
/// <param name="assemblyVersion">The driver version for the User-Agent.</param>
122124
/// <returns>Configured HttpClient for telemetry.</returns>
123-
public static HttpClient CreateTelemetryHttpClient(IReadOnlyDictionary<string, string> properties)
125+
public static HttpClient CreateTelemetryHttpClient(
126+
IReadOnlyDictionary<string, string> properties,
127+
string host,
128+
string assemblyVersion)
124129
{
125130
const int DefaultTelemetryTimeoutSeconds = 10;
126131

127-
// Create basic HTTP client with timeout
128-
// Telemetry doesn't need full auth chain - it uses separate endpoint
129-
var httpClient = CreateBasicHttpClient(properties, TimeSpan.FromSeconds(DefaultTelemetryTimeoutSeconds));
132+
// Use the same auth handler chain as feature flags (PAT, OAuth, WIF, proxy)
133+
var handler = HttpHandlerFactory.CreateFeatureFlagHandler(properties, host, DefaultTelemetryTimeoutSeconds);
134+
135+
var httpClient = new HttpClient(handler)
136+
{
137+
BaseAddress = new Uri($"https://{host}"),
138+
Timeout = TimeSpan.FromSeconds(DefaultTelemetryTimeoutSeconds)
139+
};
140+
141+
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(
142+
UserAgentHelper.GetUserAgent(assemblyVersion, properties));
130143

131144
return httpClient;
132145
}

0 commit comments

Comments
 (0)