Skip to content

Commit bdf5f79

Browse files
Improved build execution order
1 parent 15a5ce7 commit bdf5f79

File tree

5 files changed

+55
-51
lines changed

5 files changed

+55
-51
lines changed

tracer/build/_build/Build.Steps.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,9 @@ string NormalizedPath(AbsolutePath ap)
24842484
File.WriteAllText(descriptorFilePath, sb.ToString());
24852485
Serilog.Log.Information("File saved: {File}", descriptorFilePath);
24862486

2487+
var nativeGeneratedFilesOutputPath = NativeTracerProject.Directory / "Generated";
2488+
CallSitesGenerator.GenerateCallSites(TargetFrameworks, tfm => DatadogTraceDirectory / "bin" / BuildConfiguration / tfm / Projects.DatadogTrace + ".dll", nativeGeneratedFilesOutputPath);
2489+
24872490
static List<(string Assembly, string Type)> GetTypeReferences(string dllPath)
24882491
{
24892492
// We check if the assembly file exists.
@@ -2561,16 +2564,6 @@ string NormalizedPath(AbsolutePath ap)
25612564
}
25622565
});
25632566

2564-
Target GenerateCallSites => _ => _
2565-
.Description("Generate CallSite native files")
2566-
.DependsOn(CompileManagedSrc)
2567-
.Before(CompileTracerNativeSrc)
2568-
.Executes(() =>
2569-
{
2570-
var outputPath = NativeTracerProject.Directory / "Generated";
2571-
CallSitesGenerator.GenerateCallSites(TargetFrameworks, tfm => DatadogTraceDirectory / "bin" / BuildConfiguration / tfm / Projects.DatadogTrace + ".dll", outputPath);
2572-
});
2573-
25742567
Target CheckBuildLogsForErrors => _ => _
25752568
.Unlisted()
25762569
.Description("Reads the logs from build_data and checks for error lines")

tracer/build/_build/CodeGenerators/CallSitesGenerator.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal static class CallSitesGenerator
1515

1616
public static void GenerateCallSites(IEnumerable<TargetFramework> targetFrameworks, Func<string, string> getDllPath, AbsolutePath outputPath)
1717
{
18+
Serilog.Log.Debug("Generating CallSite definitions file ...");
19+
1820
Dictionary<string, AspectClass> aspectClasses = new Dictionary<string, AspectClass>();
1921
foreach(var tfm in targetFrameworks)
2022
{
@@ -103,6 +105,10 @@ string GetAspectLine(Mono.Cecil.CustomAttribute data, out InstrumentationCategor
103105
category = (InstrumentationCategory)Enum.Parse(typeof(InstrumentationCategory), arguments[1]);
104106
return $"[AspectClass({arguments[0]},[None],Propagation,[]){version}]";
105107
}
108+
else if (arguments.Count == 3)
109+
{
110+
return $"[AspectClass({arguments[0]},[None],{arguments[1]},{Check(arguments[2])}){version}]";
111+
}
106112
else if (arguments.Count == 4)
107113
{
108114
category = (InstrumentationCategory)Enum.Parse(typeof(InstrumentationCategory), arguments[1]);
@@ -254,7 +260,10 @@ namespace trace
254260

255261

256262
if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); }
257-
File.WriteAllText(outputPath / "generated_callsites.g.h", sb.ToString());
263+
var fileName = outputPath / "generated_callsites.g.h";
264+
File.WriteAllText(fileName, sb.ToString());
265+
266+
Serilog.Log.Information("CallSite definitions File saved: {File}", fileName);
258267

259268
string Format(string line)
260269
{

tracer/src/Datadog.Trace/ClrProfiler/Instrumentation.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public static class Instrumentation
4747

4848
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(Instrumentation));
4949

50-
private static TargetFrameworks _targetFramework = TargetFrameworks.None;
51-
5250
/// <summary>
5351
/// Gets a value indicating whether Datadog's profiler is attached to the current process.
5452
/// </summary>
@@ -109,8 +107,6 @@ public static void Initialize()
109107

110108
try
111109
{
112-
_targetFramework = (TargetFrameworks)Enum.Parse(typeof(TargetFrameworks), ConfigTelemetryData.ManagedTracerTfmValue.ToUpper().Replace(".", "_"));
113-
114110
Log.Debug("Enabling CallTarget integration definitions in native library.");
115111

116112
InstrumentationCategory enabledCategories = InstrumentationCategory.Tracing;
@@ -541,7 +537,7 @@ private static void EnableCallSiteInstrumentations(InstrumentationCategory categ
541537
var debugMsg = (isIast && raspEnabled) ? "IAST/RASP" : (isIast ? "IAST" : "RASP");
542538
Log.Debug("Registering {DebugMsg} Callsite Dataflow Aspects into native library.", debugMsg);
543539

544-
var aspects = NativeMethods.InitEmbeddedCallSiteDefinitions(categories, _targetFramework);
540+
var aspects = NativeMethods.InitEmbeddedCallSiteDefinitions(categories, ConfigTelemetryData.TargetFramework);
545541
Log.Information<int, string>("{Aspects} {DebugMsg} Callsite Dataflow Aspects added to the profiler.", aspects, debugMsg);
546542

547543
if (isIast)

tracer/src/Datadog.Trace/Telemetry/DTOs/ConfigTelemetryData.cs

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#nullable enable
77

8+
using Datadog.Trace.ClrProfiler;
9+
810
namespace Datadog.Trace.Telemetry
911
{
1012
internal static class ConfigTelemetryData
@@ -27,12 +29,16 @@ internal static class ConfigTelemetryData
2729
// We intentionally are using specific values here, not OR_GREATER_THAN
2830
#if NET6_0
2931
public const string ManagedTracerTfmValue = "net6.0";
32+
internal const TargetFrameworks TargetFramework = TargetFrameworks.NET6_0;
3033
#elif NETCOREAPP3_1
3134
public const string ManagedTracerTfmValue = "netcoreapp3.1";
35+
internal const TargetFrameworks TargetFramework = TargetFrameworks.NETCOREAPP3_1;
3236
#elif NETSTANDARD2_0
3337
public const string ManagedTracerTfmValue = "netstandard2.0";
38+
internal const TargetFrameworks TargetFramework = TargetFrameworks.NETSTANDARD2_0;
3439
#elif NETFRAMEWORK
3540
public const string ManagedTracerTfmValue = "net461";
41+
internal const TargetFrameworks TargetFramework = TargetFrameworks.NET461;
3642
#else
3743
#error Unexpected TFM
3844
#endif

0 commit comments

Comments
 (0)