From edb1f959380fc201b2028669e96fd5118bab8b21 Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Tue, 9 Dec 2025 15:19:21 +0200 Subject: [PATCH 1/3] Added AppMetadata option when calling `Connect()`. --- PowerSync/PowerSync.Common/CHANGELOG.md | 17 +++++++++++++++++ .../Sync/Stream/StreamingSyncImplementation.cs | 14 ++++++++++++-- .../Client/Sync/Stream/StreamingSyncTypes.cs | 3 +++ PowerSync/PowerSync.Maui/CHANGELOG.md | 4 ++++ .../SyncIntegrationTests.cs | 5 +++++ demos/CommandLine/CommandLine.csproj | 1 + demos/CommandLine/Demo.cs | 17 ++++++++++++++++- 7 files changed, 58 insertions(+), 3 deletions(-) diff --git a/PowerSync/PowerSync.Common/CHANGELOG.md b/PowerSync/PowerSync.Common/CHANGELOG.md index 4fc0f47..07edade 100644 --- a/PowerSync/PowerSync.Common/CHANGELOG.md +++ b/PowerSync/PowerSync.Common/CHANGELOG.md @@ -1,5 +1,22 @@ # PowerSync.Common Changelog +## 0.0.6-alpha.1 +- Added ability to specify `AppMetadata` for sync/stream requests. + +Note: This requires a PowerSync service version `>=1.17.0` in order for logs to display metadata. + +```csharp +db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions +{ + // This will be included in PowerSync service logs + AppMetadata = new Dictionary + { + { "app_version", myAppVersion }, + + } +}); +``` + ## 0.0.5-alpha.1 - Using the latest (0.4.9) version of the core extension, it introduces support for the Rust Sync implementation and also makes it the default - users can still opt out and use the legacy C# sync implementation as option when calling `connect()`. diff --git a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs index 62466cc..3d25ea9 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs @@ -74,8 +74,13 @@ public class StreamingSyncImplementationOptions : AdditionalConnectionOptions public ILogger? Logger { get; init; } } -public class BaseConnectionOptions(Dictionary? parameters = null, SyncClientImplementation? clientImplementation = null) +public class BaseConnectionOptions(Dictionary? parameters = null, SyncClientImplementation? clientImplementation = null, Dictionary? appMetadata = null) { + /// + /// A set of metadata to be included in service logs. + /// + public Dictionary? AppMetadata { get; set; } = appMetadata; + /// /// These parameters are passed to the sync rules and will be available under the `user_parameters` object. /// @@ -89,6 +94,9 @@ public class BaseConnectionOptions(Dictionary? parameters = null public class RequiredPowerSyncConnectionOptions : BaseConnectionOptions { + + public new Dictionary AppMetadata { get; set; } = new(); + public new Dictionary Params { get; set; } = new(); public new SyncClientImplementation ClientImplementation { get; set; } = new(); @@ -128,6 +136,7 @@ public class StreamingSyncImplementation : EventStream StreamingSyncIteration(Cancel { var resolvedOptions = new RequiredPowerSyncConnectionOptions { + AppMetadata = options?.AppMetadata ?? DEFAULT_STREAM_CONNECTION_OPTIONS.AppMetadata, Params = options?.Params ?? DEFAULT_STREAM_CONNECTION_OPTIONS.Params, ClientImplementation = options?.ClientImplementation ?? DEFAULT_STREAM_CONNECTION_OPTIONS.ClientImplementation }; @@ -611,7 +621,7 @@ async Task HandleInstruction(Instruction instruction) try { - await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params })); + await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params, app_metadata = resolvedOptions.AppMetadata })); notifyCompletedUploads = () => { diff --git a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs index 6f78059..5502c8d 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs @@ -66,6 +66,9 @@ public class StreamingSyncRequest [JsonProperty("raw_data")] public bool RawData { get; set; } + [JsonProperty("app_metadata")] + public Dictionary? AppMetadata { get; set; } + [JsonProperty("parameters")] public Dictionary? Parameters { get; set; } diff --git a/PowerSync/PowerSync.Maui/CHANGELOG.md b/PowerSync/PowerSync.Maui/CHANGELOG.md index ee6b964..7144d9c 100644 --- a/PowerSync/PowerSync.Maui/CHANGELOG.md +++ b/PowerSync/PowerSync.Maui/CHANGELOG.md @@ -1,5 +1,9 @@ # PowerSync.Maui Changelog +## 0.0.4-alpha.1 +- Upstream PowerSync.Common version bump +- Added ability to specify `AppMetadata` sync/stream requests (see Common changelog). + ## 0.0.3-alpha.1 - Upstream PowerSync.Common version bump - Using the latest (0.4.9) version of the core extension, it introduces support for the Rust Sync implementation and also makes it the default - users can still opt out and use the legacy C# sync implementation as option when calling `connect()`. diff --git a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs index 6e2da0e..1316a7c 100644 --- a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs +++ b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs @@ -50,6 +50,11 @@ public async Task InitializeAsync() await db.Connect(connector, new PowerSyncConnectionOptions { ClientImplementation = SyncClientImplementation.RUST, + AppMetadata = new Dictionary + { + { "app_version", "1.0.0-integration-tests" }, + { "environment", "integration-tests" } + } }); await db.WaitForFirstSync(); } diff --git a/demos/CommandLine/CommandLine.csproj b/demos/CommandLine/CommandLine.csproj index 28c7d9a..b5e0281 100644 --- a/demos/CommandLine/CommandLine.csproj +++ b/demos/CommandLine/CommandLine.csproj @@ -2,6 +2,7 @@ Exe + 0.0.1 net8.0 12 enable diff --git a/demos/CommandLine/Demo.cs b/demos/CommandLine/Demo.cs index 347edd3..31ee57d 100644 --- a/demos/CommandLine/Demo.cs +++ b/demos/CommandLine/Demo.cs @@ -1,5 +1,6 @@ namespace CommandLine; +using System.Reflection; using CommandLine.Utils; using PowerSync.Common.Client; using PowerSync.Common.Client.Connection; @@ -96,7 +97,15 @@ static async Task Main() } }); - await db.Connect(connector); + await db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions + { + ClientImplementation = PowerSync.Common.Client.Sync.Stream.SyncClientImplementation.RUST, + AppMetadata = new Dictionary + { + { "app_version", GetAppVersion() }, + + } + }); await db.WaitForFirstSync(); var panel = new Panel(table) @@ -128,4 +137,10 @@ await AnsiConsole.Live(panel) Console.WriteLine("\nExited live table. Press any key to exit."); } + + private static string GetAppVersion() + { + var version = Assembly.GetExecutingAssembly().GetName().Version; + return version?.ToString() ?? "unknown"; + } } \ No newline at end of file From cd724c7627b2a93cb030dedcf72e5c4a48f214b7 Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Tue, 9 Dec 2025 15:24:00 +0200 Subject: [PATCH 2/3] Formatting. --- PowerSync/PowerSync.Common/CHANGELOG.md | 1 - demos/CommandLine/Demo.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/PowerSync/PowerSync.Common/CHANGELOG.md b/PowerSync/PowerSync.Common/CHANGELOG.md index 07edade..990830e 100644 --- a/PowerSync/PowerSync.Common/CHANGELOG.md +++ b/PowerSync/PowerSync.Common/CHANGELOG.md @@ -12,7 +12,6 @@ db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectio AppMetadata = new Dictionary { { "app_version", myAppVersion }, - } }); ``` diff --git a/demos/CommandLine/Demo.cs b/demos/CommandLine/Demo.cs index 31ee57d..2dff5c8 100644 --- a/demos/CommandLine/Demo.cs +++ b/demos/CommandLine/Demo.cs @@ -103,7 +103,6 @@ static async Task Main() AppMetadata = new Dictionary { { "app_version", GetAppVersion() }, - } }); await db.WaitForFirstSync(); From 0fa49cc9bc1461a7049c2038e5676def7047a48b Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Fri, 12 Dec 2025 15:07:45 +0200 Subject: [PATCH 3/3] Added app_metadata to legacy sync implementation stream. --- .../Client/Sync/Stream/StreamingSyncImplementation.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs index 3d25ea9..34d9132 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs @@ -692,6 +692,7 @@ protected async Task LegacyStreamingSyncIteration( IncludeChecksum = true, RawData = true, Parameters = resolvedOptions.Params, + AppMetadata = resolvedOptions.AppMetadata, ClientId = clientId } };