diff --git a/PowerSync/PowerSync.Common/CHANGELOG.md b/PowerSync/PowerSync.Common/CHANGELOG.md index 3aa1159..05f2937 100644 --- a/PowerSync/PowerSync.Common/CHANGELOG.md +++ b/PowerSync/PowerSync.Common/CHANGELOG.md @@ -9,6 +9,20 @@ - Reporting progress information about downloaded rows. Sync progress is available through `SyncStatus.DownloadProgress()`. - Support bucket priorities. - Report `PriorityStatusEntries` on `SyncStatus`. +- 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 version (0.4.9) 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 1a7e233..2511112 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs @@ -50,8 +50,13 @@ public class StreamingSyncImplementationOptions : AdditionalConnectionOptions public ILogger? Logger { get; init; } } -public class BaseConnectionOptions(Dictionary? parameters = null) +public class BaseConnectionOptions(Dictionary? parameters = 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. /// @@ -60,6 +65,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(); } @@ -97,6 +105,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, }; @@ -550,7 +560,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 20aa5b1..3d7a7a7 100644 --- a/PowerSync/PowerSync.Maui/CHANGELOG.md +++ b/PowerSync/PowerSync.Maui/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.0.4-alpha.1 - Upstream PowerSync.Common version bump (See Powersync.Common changelog for more information) +- Added ability to specify `AppMetadata` sync/stream requests (see Common changelog). ## 0.0.3-alpha.1 - Upstream PowerSync.Common version bump diff --git a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs index 9e6e367..7a615f8 100644 --- a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs +++ b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs @@ -43,6 +43,14 @@ public async Task InitializeAsync() Console.WriteLine($"Using User ID: {userId}"); try { + await db.Connect(connector, new PowerSyncConnectionOptions + { + AppMetadata = new Dictionary + { + { "app_version", "1.0.0-integration-tests" }, + { "environment", "integration-tests" } + } + }); await db.Connect(connector); 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..2dff5c8 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,14 @@ 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 +136,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