From 2f5b1f1fdd62f7eb592d71df472f7ff1ee5682c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 9 Apr 2024 18:08:33 +0100 Subject: [PATCH] SDK(C#): add OpenTelemetry.Instrumentation.Http as a dependency, and autoinstrument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will automatically create activity spans and metrics around http calls, and propagate traceparent in HTTP Headers. We are not required to use this (e.g. could manually fetch the activity and create the headers), but it is a quick-start for using OpenTelemetry. Eventually we might want to fetch and add the headers ourselves, because this SDK may not be the only user of HttpClient in an application, and it should really be the application deciding to instrument all http calls, rather than this SDK. We do want to always propagate any traceparents we get from the application, even if we don't have any tracing enabled ourselves. Signed-off-by: Edwin Török --- ocaml/sdk-gen/csharp/autogen/src/Session.cs | 9 +++++++++ ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj | 2 ++ 2 files changed, 11 insertions(+) diff --git a/ocaml/sdk-gen/csharp/autogen/src/Session.cs b/ocaml/sdk-gen/csharp/autogen/src/Session.cs index a2aef1d672e..e0eac831eb1 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/Session.cs +++ b/ocaml/sdk-gen/csharp/autogen/src/Session.cs @@ -34,6 +34,9 @@ using System.Net.Security; using Newtonsoft.Json; +using OpenTelemetry; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; namespace XenAPI { @@ -57,6 +60,12 @@ public partial class Session : XenObject private List roles = new List(); + private static TracerProvider tracerProvider = Sdk.CreateTracerProviderBuilder() + .AddHttpClientInstrumentation() + .ConfigureResource(r => r.AddService("XenAPI-C#-SDK")) + .AddSource("XenAPI-C#-SDK") + .Build(); + #region Constructors public Session(JsonRpcClient client) diff --git a/ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj b/ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj index a6323ccd95e..930b0ab5691 100644 --- a/ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj +++ b/ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj @@ -29,6 +29,8 @@ + +