diff --git a/samples/Samples.sln b/samples/Samples.sln index 00cac48f5..79c979342 100644 --- a/samples/Samples.sln +++ b/samples/Samples.sln @@ -35,6 +35,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStore.Client.Projectio EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "projection-management", "projection-management\projection-management.csproj", "{9DEA2684-C38B-465C-91A6-ED2AB67A4338}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "diagnostics", "diagnostics\diagnostics.csproj", "{546496AD-E355-4C20-930C-30D0FC76D26F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "user-certificates", "user-certificates\user-certificates.csproj", "{28112410-D02D-427A-9D36-3FE3A6DC6B0D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.Client.Extensions.OpenTelemetry", "..\src\EventStore.Client.Extensions.OpenTelemetry\EventStore.Client.Extensions.OpenTelemetry.csproj", "{29E3F07A-6676-45C1-805C-46BDF6CF325B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,6 +107,18 @@ Global {9DEA2684-C38B-465C-91A6-ED2AB67A4338}.Debug|Any CPU.Build.0 = Debug|Any CPU {9DEA2684-C38B-465C-91A6-ED2AB67A4338}.Release|Any CPU.ActiveCfg = Release|Any CPU {9DEA2684-C38B-465C-91A6-ED2AB67A4338}.Release|Any CPU.Build.0 = Release|Any CPU + {546496AD-E355-4C20-930C-30D0FC76D26F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {546496AD-E355-4C20-930C-30D0FC76D26F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {546496AD-E355-4C20-930C-30D0FC76D26F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {546496AD-E355-4C20-930C-30D0FC76D26F}.Release|Any CPU.Build.0 = Release|Any CPU + {28112410-D02D-427A-9D36-3FE3A6DC6B0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28112410-D02D-427A-9D36-3FE3A6DC6B0D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28112410-D02D-427A-9D36-3FE3A6DC6B0D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28112410-D02D-427A-9D36-3FE3A6DC6B0D}.Release|Any CPU.Build.0 = Release|Any CPU + {29E3F07A-6676-45C1-805C-46BDF6CF325B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {29E3F07A-6676-45C1-805C-46BDF6CF325B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {29E3F07A-6676-45C1-805C-46BDF6CF325B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {29E3F07A-6676-45C1-805C-46BDF6CF325B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -110,6 +128,7 @@ Global {A71A13F7-8480-4E48-B88D-A2364F7C95B6} = {EBB93BBC-42A7-48E4-B1EA-0EA3953D347C} {7200BB01-A405-45D5-A6E8-A8FA8DE39DA0} = {EBB93BBC-42A7-48E4-B1EA-0EA3953D347C} {79992D7B-C311-4E8A-856F-896C1EA61042} = {EBB93BBC-42A7-48E4-B1EA-0EA3953D347C} + {29E3F07A-6676-45C1-805C-46BDF6CF325B} = {EBB93BBC-42A7-48E4-B1EA-0EA3953D347C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2E7E3A6C-21DA-4DBD-9EB3-68DFC5CDE48F} diff --git a/samples/diagnostics/Program.cs b/samples/diagnostics/Program.cs new file mode 100644 index 000000000..e9cf761b0 --- /dev/null +++ b/samples/diagnostics/Program.cs @@ -0,0 +1,96 @@ +using System.Diagnostics; +using EventStore.Client.Extensions.OpenTelemetry; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using OpenTelemetry.Exporter; +using OpenTelemetry.Trace; +using OpenTelemetry.Resources; + +#pragma warning disable CS8321 // Local function is declared but never used +#pragma warning disable CS1587 // XML comment is not placed on a valid language element + +/** +# region import-required-packages +// required +dotnet add package EventStore.Client.Extensions.OpenTelemetry + +// recommended +dotnet add package OpenTelemetry.Exporter.Jaeger +dotnet add package OpenTelemetry.Exporter.Console +dotnet add package OpenTelemetry +dotnet add package Microsoft.Extensions.Hosting +dotnet add package OpenTelemetry.Extensions.Hosting +# endregion import-required-packages +**/ + +var settings = EventStoreClientSettings.Create("esdb://localhost:2113?tls=false"); + +settings.OperationOptions.ThrowOnAppendFailure = false; + +await using var client = new EventStoreClient(settings); + +await TraceAppendToStream(client); + +return; + +static async Task TraceAppendToStream(EventStoreClient client) { + const string serviceName = "sample"; + + var host = Host.CreateDefaultBuilder() + .ConfigureServices( + (_, services) => { + services.AddSingleton(new ActivitySource(serviceName)); + services + .AddOpenTelemetry() + .ConfigureResource(builder => builder.AddService(serviceName)) + .WithTracing(ConfigureTracerProviderBuilder); + } + ) + .Build(); + + using (host) { + # region setup-client-for-tracing + + host.Start(); + + var eventData = new EventData( + Uuid.NewUuid(), + "some-event", + "{\"id\": \"1\" \"value\": \"some value\"}"u8.ToArray() + ); + + await client.AppendToStreamAsync( + Uuid.NewUuid().ToString(), + StreamState.Any, + new List { + eventData + } + ); + + # endregion setup-client-for-tracing + } + + return; + + static void ConfigureTracerProviderBuilder(TracerProviderBuilder tracerProviderBuilder) { + #region register-instrumentation + + tracerProviderBuilder + .AddEventStoreClientInstrumentation(); + + #endregion register-instrumentation + + #region setup-exporter + + tracerProviderBuilder + .AddConsoleExporter() + .AddJaegerExporter( + options => { + options.Endpoint = new Uri("http://localhost:4317"); + options.Protocol = JaegerExportProtocol.UdpCompactThrift; + } + ); + + #endregion + } +} diff --git a/samples/diagnostics/diagnostics.csproj b/samples/diagnostics/diagnostics.csproj new file mode 100644 index 000000000..1763a9d9e --- /dev/null +++ b/samples/diagnostics/diagnostics.csproj @@ -0,0 +1,22 @@ + + + Exe + connecting_to_a_cluster + + + + + + + + + + + + + + + + + + diff --git a/samples/user-certificates/Program.cs b/samples/user-certificates/Program.cs new file mode 100644 index 000000000..1c9ceae44 --- /dev/null +++ b/samples/user-certificates/Program.cs @@ -0,0 +1,18 @@ +await ClientWithUserCertificates(); + +return; + +static async Task ClientWithUserCertificates() { + # region client-with-user-certificates + + const string userCertFile = "/path/to/user.crt"; + const string userKeyFile = "/path/to/user.key"; + + var settings = EventStoreClientSettings.Create( + $"esdb://localhost:2113/?tls=true&tlsVerifyCert=true&userCertFile={userCertFile}&userKeyFile={userKeyFile}" + ); + + await using var client = new EventStoreClient(settings); + + # endregion client-with-user-certificates +} diff --git a/samples/user-certificates/user-certificates.csproj b/samples/user-certificates/user-certificates.csproj new file mode 100644 index 000000000..7eaa70127 --- /dev/null +++ b/samples/user-certificates/user-certificates.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + user_certificates + enable + enable + + + + + + + +