Skip to content

Commit

Permalink
SDK(C#): add OpenTelemetry.Instrumentation.Http as a dependency, and …
Browse files Browse the repository at this point in the history
…autoinstrument

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 <[email protected]>
  • Loading branch information
edwintorok committed Apr 9, 2024
1 parent 302c39e commit 2f5b1f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ocaml/sdk-gen/csharp/autogen/src/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
using System.Net.Security;
using Newtonsoft.Json;

using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace XenAPI
{
Expand All @@ -57,6 +60,12 @@ public partial class Session : XenObject<Session>

private List<Role> roles = new List<Role>();

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)
Expand Down
2 changes: 2 additions & 0 deletions ocaml/sdk-gen/csharp/autogen/src/XenServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OpenTelemetry" Version="1.8.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 2f5b1f1

Please sign in to comment.