-
Notifications
You must be signed in to change notification settings - Fork 284
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
CP-44752: propagate System.Diagnostics tracing information using W3C traceparent header #5929
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.
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 <edwin.torok@cloud.com>
…s a dependency This only exists on .Net 4.6+, so add it conditionally only when target >Netstandard 2.0 (which includes .Net 4.6). On the newer .Net versions this is already included. This allows creating activity spans, independently of the tracing framework used. We use version 8.0.1, because version 9.0.0 doesn't support .Net 6.0 anymore. Signed-off-by: Edwin Török <edwin.torok@cloud.com>
To avoid someone injecting a malicious binary with the same version in the future, lock all dependencies. Signed-off-by: Edwin Török <edwin.torok@cloud.com>
This is not available on .Net 4.5 Signed-off-by: Edwin Török <edwin.torok@cloud.com>
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. |
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 <edwin.torok@cloud.com>
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
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: