Skip to content

Commit 3d186db

Browse files
lucas-zimermanJosh DeGrawbruno-garcia
authored
Update X-Sentry-Auth header to include correct sdk name and version (#1333)
* Update X-Sentry-Auth header to include correct SDK name and version Co-authored-by: Josh DeGraw <[email protected]> Co-authored-by: Bruno Garcia <[email protected]>
1 parent 93e17cc commit 3d186db

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Move to stable v6 for `Microsoft.Extensions.*` packages ([#1347](https://github.com/getsentry/sentry-dotnet/pull/1347))
88

9+
### Fixes
10+
11+
- Update X-Sentry-Auth header to include correct sdk name and version ([#1333](https://github.com/getsentry/sentry-dotnet/pull/1333))
12+
913
## 3.12.0
1014

1115
### Features

src/Sentry/Internal/Http/HttpTransport.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,9 @@ internal HttpRequestMessage CreateRequest(Envelope envelope)
267267
}
268268

269269
var dsn = Dsn.Parse(_options.Dsn);
270-
271270
var authHeader =
272271
$"Sentry sentry_version={_options.SentryVersion}," +
273-
$"sentry_client={_options.ClientVersion}," +
272+
$"sentry_client={SdkVersion.Instance.Name}/{SdkVersion.Instance.Version}," +
274273
$"sentry_key={dsn.PublicKey}," +
275274
(dsn.SecretKey is { } secretKey ? $"sentry_secret={secretKey}," : null) +
276275
$"sentry_timestamp={_clock.GetUtcNow().ToUnixTimeSeconds()}";

test/Sentry.DiagnosticSource.Tests/ApiApprovalTests.Run.DotNet3_1.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ namespace Sentry
379379
public void WriteTo(System.Text.Json.Utf8JsonWriter writer) { }
380380
public static Sentry.SentryEvent FromJson(System.Text.Json.JsonElement json) { }
381381
}
382-
public static class SentryEventExtensions { }
383382
public class SentryHttpMessageHandler : System.Net.Http.DelegatingHandler
384383
{
385384
public SentryHttpMessageHandler() { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet3_1.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ namespace Sentry
379379
public void WriteTo(System.Text.Json.Utf8JsonWriter writer) { }
380380
public static Sentry.SentryEvent FromJson(System.Text.Json.JsonElement json) { }
381381
}
382-
public static class SentryEventExtensions { }
383382
public class SentryHttpMessageHandler : System.Net.Http.DelegatingHandler
384383
{
385384
public SentryHttpMessageHandler() { }

test/Sentry.Tests/Internals/Http/HttpTransportTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net;
22
using System.Net.Http;
3+
using System.Text.RegularExpressions;
34
using Sentry.Internal.Http;
45
using Sentry.Testing;
56
using Sentry.Tests.Helpers;
@@ -479,6 +480,25 @@ public void CreateRequest_AuthHeader_IsSet()
479480
authHeader.Should().NotBeNullOrWhiteSpace();
480481
}
481482

483+
[Fact]
484+
public void CreateRequest_AuthHeader_IncludesVersion()
485+
{
486+
// Arrange
487+
var httpTransport = new HttpTransport(
488+
new SentryOptions { Dsn = DsnSamples.ValidDsnWithSecret },
489+
new HttpClient());
490+
491+
var envelope = Envelope.FromEvent(new SentryEvent());
492+
493+
// Act
494+
using var request = httpTransport.CreateRequest(envelope);
495+
var authHeader = request.Headers.GetValues("X-Sentry-Auth").FirstOrDefault();
496+
497+
// Assert
498+
var versionString = Regex.Match(authHeader, @"sentry_client=(\S+),sentry_key").Groups[1].Value;
499+
Assert.Contains(versionString, $"{SdkVersion.Instance.Name}/{SdkVersion.Instance.Version}");
500+
}
501+
482502
[Fact]
483503
public void CreateRequest_RequestMethod_Post()
484504
{

0 commit comments

Comments
 (0)