Skip to content

Commit 4ae592b

Browse files
committed
Add OS and framework info to captured events
1 parent d01bcd0 commit 4ae592b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/PostHog/Api/PostHogApiClient.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System.Net.Http.Headers;
22
using System.Net.Http.Json;
3+
using System.Runtime.InteropServices;
34
using Microsoft.Extensions.Logging;
45
using Microsoft.Extensions.Options;
56
using PostHog.Config;
67
using PostHog.Json;
78
using PostHog.Library;
89
using PostHog.Versioning;
910
#if NETSTANDARD2_0 || NETSTANDARD2_1
10-
using PostHog.Library.Polyfills;
1111
#endif
1212

1313
namespace PostHog.Api;
@@ -41,6 +41,10 @@ public PostHogApiClient(
4141
_timeProvider = timeProvider;
4242

4343
_httpClient = httpClient;
44+
var framework = RuntimeInformation.FrameworkDescription;
45+
var os = RuntimeInformation.OSDescription;
46+
var arch = RuntimeInformation.ProcessArchitecture;
47+
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"{LibraryName}/{VersionConstants.Version} ({framework}; {os}; {arch})");
4448

4549
logger.LogTraceApiClientCreated(HostUrl);
4650
}
@@ -157,6 +161,9 @@ void PrepareAndMutatePayload(Dictionary<string, object> payload)
157161

158162
properties["$lib"] = LibraryName;
159163
properties["$lib_version"] = VersionConstants.Version;
164+
properties["$os"] = RuntimeInformation.OSDescription;
165+
properties["$framework"] = RuntimeInformation.FrameworkDescription;
166+
properties["$arch"] = RuntimeInformation.ProcessArchitecture.ToString();
160167
properties["$geoip_disable"] = true;
161168

162169
properties.Merge(_options.Value.SuperProperties);

tests/UnitTests/PostHogClientTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http.Headers;
2+
using System.Runtime.InteropServices;
23
using Microsoft.Extensions.DependencyInjection;
34
using Microsoft.Extensions.Options;
45
using PostHog;
@@ -370,6 +371,9 @@ public async Task SendsCorrectPayload()
370371
"properties": {
371372
"$lib": "posthog-dotnet",
372373
"$lib_version": "{{VersionConstants.Version}}",
374+
"$os": "{{RuntimeInformation.OSDescription}}",
375+
"$framework": "{{RuntimeInformation.FrameworkDescription}}",
376+
"$arch": "{{RuntimeInformation.ProcessArchitecture}}",
373377
"$geoip_disable": true
374378
},
375379
"api_key": "fake-project-api-key",
@@ -411,6 +415,9 @@ public async Task SendsCorrectPayloadWithPersonProperties()
411415
},
412416
"$lib": "posthog-dotnet",
413417
"$lib_version": "{{VersionConstants.Version}}",
418+
"$os": "{{RuntimeInformation.OSDescription}}",
419+
"$framework": "{{RuntimeInformation.FrameworkDescription}}",
420+
"$arch": "{{RuntimeInformation.ProcessArchitecture}}",
414421
"$geoip_disable": true
415422
},
416423
"api_key": "fake-project-api-key",
@@ -445,6 +452,9 @@ public async Task SendsCorrectPayloadWithSuperProperties()
445452
"properties": {
446453
"$lib": "posthog-dotnet",
447454
"$lib_version": "{{VersionConstants.Version}}",
455+
"$os": "{{RuntimeInformation.OSDescription}}",
456+
"$framework": "{{RuntimeInformation.FrameworkDescription}}",
457+
"$arch": "{{RuntimeInformation.ProcessArchitecture}}",
448458
"$geoip_disable": true,
449459
"source": "repo-name"
450460
},
@@ -481,6 +491,9 @@ public async Task SendsCorrectPayload()
481491
},
482492
"$lib": "posthog-dotnet",
483493
"$lib_version": "{{VersionConstants.Version}}",
494+
"$os": "{{RuntimeInformation.OSDescription}}",
495+
"$framework": "{{RuntimeInformation.FrameworkDescription}}",
496+
"$arch": "{{RuntimeInformation.ProcessArchitecture}}",
484497
"$geoip_disable": true
485498
},
486499
"api_key": "fake-project-api-key",

0 commit comments

Comments
 (0)