-
Notifications
You must be signed in to change notification settings - Fork 291
CP-44752: propagate System.Diagnostics tracing information using W3C traceparent header #5929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Internal build succeeded with locked package dependencies too. |
I think I'll also need |
c2723ca
to
3037f81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't tested it yet but I spotted a couple of things on the first run
for SDK PRs also please request reviews manually, because we don't monitor the repo as often as toolstack does, so it helps to see PR reviews under https://github.com/pulls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
3037f81
to
d7468f6
Compare
I've addressed the review comments, and tested a build, the
|
I'll add a small self-contained example here on how the output looks with OpenTelemetry instrumentation enabled. |
d7468f6
to
f6c2641
Compare
// See https://aka.ms/new-console-template for more information
using System.Net;
using System;
using System.Collections.Generic;
using XenAPI;
using System.Runtime.InteropServices;
using System.ComponentModel.DataAnnotations;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using System.Diagnostics;
ActivitySource source = new ActivitySource("Sample.DistributedTracing", "1.0.0");
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MySample"))
.AddSource("*")
.AddConsoleExporter()
.Build();
using (Activity activity = source.StartActivity("SomeWork"))
{
//Trust all certificates. This is a test workaround. DO NOT USE IN PRODUCTION CODE!
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
string hostUrl = args[0], username = args[1], password = args[2];
Session session = new Session(hostUrl);
try
{
session.login_with_password(username, password, "", "XenSdkSample");
var hosts = Host.get_all(session);
System.Console.WriteLine("Got hosts: " + hosts.Count);
}
finally
{
session.logout();
}
} The output looks like this (the application can choose which activity sources to enable, if they want just the XenServer on, they can enable 'XenServer.*'): |
Review comments addressed in new commits. Removing stale review marker, and requested new review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes and output looks good to me, and the joined Client + Server trace in Jaeger shows it's working as intended. Perhaps someone more used to the SDK build system could check the dependency changes @kc284 @danilo-delbusso
It has been discussed that we should switch to .Net 8, so I'll see if I can add an additional build target for that here (that'll ensure that the right DLL gets picked out of the Nuget). |
f6c2641
to
4c2f198
Compare
Looks like I need to tweak the preprocessor defines, because this doesn't cover .Net 8.0: NET462 refers to .Net framework I think, so .Net 8.0 is not covered by it, and .Net Core and regular .Net probably have no overlap either. |
4c2f198
to
249cebb
Compare
The xenserver-samples fail to run:
Maybe the dependencies don't get propagated correctly from the SDK to the app, although I would've expected Nuget to do the right thing. I'll try another build where I only enable tracing when you're on .Net 8.0+ and not in other cases (that means that XenCenter likely won't get it, and we'll also lack tracing in Powershell -- which was an easy way to test that the tracing works). The C# sample fails to run too, but that probably needs the environment updated to have .Net 8.0 available (I switched the sample from 6.0 to 8.0):
|
To allow compile-testing the C# code on Linux reintroduce the 'sdksanity' rule which got dropped accidentally. Also run the tests. Fixes: e6afe15 ("Removed erroneously ported recipe.") Signed-off-by: Edwin Török <[email protected]>
This is not available on .Net 4.5. Could use .Net Standard 2.0, .Net Framework 4.6.2 and .NET 8.0 as target, which matches the availability of the System.Diagnostics.DiagnosticSource builtin (and Nuget package for older versions): ``` NET462_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET8_0_OR_GREATER ``` However there are some bugs in the CI where the xenserver-samples XenSdkSample ends up in a zip, but without its dependency (the DiagnosticSource.dll). So for now just enable this on .Net8, where hopefully this package is part of the runtime already (although of course you'll still need to install the runtime, which for some reason you didn't have to do with .Net6, perhaps .Net6 would come preinstalled on Debian12?). Signed-off-by: Edwin Török <[email protected]>
Doesn't exist on .Net45. Only creates these activity sources if a listener has been created by the caller, otherwise `activity` will be `null`, and the code would be a no-op by default. A listener is created by OpenTelemetry instrumentation for example. Signed-off-by: Edwin Török <[email protected]>
Apparently this has fewer dependencies than netstandard2.0, and some projects would've picked net45 in favour of netstandard2.0. Eventually we may want to drop net45, for now just add the new target. There is also net9.0, but it has an EOL date ahead of net8.0 which is LTS. A quick sanity test that the net80 target includes tracing support: ``` make sdksanity strings -el ./_build/default/ocaml/sdk-gen/csharp/autogen-out/src/bin/Release/net80/XenServer.dll|grep traceparent traceparent ``` Signed-off-by: Edwin Török <[email protected]>
With the latest changes here (enable tracing only for .NET 8.0), and updating the tests to install the .Net 8 runtime when testing the .Net 8 sample -- the tests have passed, so I think this is ready. |
249cebb
to
6c44e4c
Compare
The newer System.Net.Http would propagate this automatically, but the older WebRequest doesn't.
Retrieve the span identifier and add the header ourselves. The WebRequest object is fresh for each request, so setting the headers shouldn't cause race conditions.
This adds a dependency on a library that is part of .Net source repository, but distributed outside of it on NuGet: System.Diagnostics. Lock the dependency to a given hash to avoid accidental/malicious changes.
This dependency is not available on .Net45, so all the code and build dependencies are wrapped with appropriate conditional compilation directives (which may look kind of ugly, they can be dropped once XenServer.dll drops support for .Net45 and switches to .Net462 minimum).
No new instrumentation is created, so if the application using XenServer.dll is not configured/set up to use OpenTelemetry or System.Diagnostics.DiagnosticSource, then this is a no-op.
I've tested this using the Powershell 7 module.
Draft PR because: