Skip to content

Commit

Permalink
Load Datadog.Trace.ClrProfiler.Managed via the AppDomain.AssemblyReso…
Browse files Browse the repository at this point in the history
…lve event (DataDog#505)

Product changes:
- In `Datadog.Trace.ClrProfiler.Managed.Loader` add the `AppDomain.AssemblyResolve` event handler to load managed profiler dependencies from disk where the profiler is installed. This would remove the need to install files into the GAC or add the `Datadog.Trace.ClrProfiler.Managed` NuGet package to receive auto-instrumentation.
- Stop adding assembly references to the managed profiler code in `ModuleLoadFinished` and instead do that operation in `JITCompilationStarted`. Because of this delayed reference, the runtime will not be able to resolve the assembly reference automatically (perhaps avoiding the SecurityGrant exceptions we have seen in the past!) and will rely on the newly implemented `AppDomain.AssemblyResolve` event to find the managed profiler code.
- Build `Datadog.Trace.ClrProfiler.Managed.Loader` for `netcoreapp2.0` and `net45` because reading environment variables (to obtain profiler file path) is only supported on `netstandard1.3` and higher.

Build changes:
- Combine common settings in `Directory.Build.props` for reproductions, reproduction-dependencies, and samples into `./Test.Common.props`
- For Windows-ready xUnit integration tests, add the `RunOnWindows=True` trait
- Produce managed profiler assets by running `dotnet publish Datadog.Trace.ClrProfiler.Managed` for each target framework
- Stop building `Datadog.Trace.ClrProfiler.Managed.Loader.csproj` inside `Datadog.Trace.proj`'s `BuildCpp` target and instead build it separately whenever we build `Datadog.Trace.ClrProfiler.Native`
  • Loading branch information
zacharycmontoya authored Sep 18, 2019
1 parent 47d87a6 commit 7b96de3
Show file tree
Hide file tree
Showing 63 changed files with 758 additions and 194 deletions.
47 changes: 39 additions & 8 deletions .azure-pipelines/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ variables:
buildConfiguration: Debug
packageFeed: /ffc32c57-3e0e-4e8f-8633-a7ad01df2e45
dotnetCoreSdkVersion: 2.2.401
publishOutput: $(Build.SourcesDirectory)/src/bin/managed-publish

jobs:

Expand Down Expand Up @@ -68,7 +69,37 @@ jobs:
command: build
projects: |
src/**/*.csproj
arguments: --configuration $(buildConfiguration) -p:Platform=$(buildPlatform)
arguments: --configuration $(buildConfiguration)

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework net45
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework net45 --output $(publishOutput)/net45

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework net461
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework net461 --output $(publishOutput)/net461

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework netstandard2.0
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework netstandard2.0 --output $(publishOutput)/netstandard2.0

- task: NuGetCommand@2
displayName: nuget restore native
Expand All @@ -91,24 +122,24 @@ jobs:
inputs:
command: restore
projects: |
samples/Samples.HttpMessageHandler/Samples.HttpMessageHandler.csproj
test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj
reproductions/**/*.csproj
samples/**/*.csproj
test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj
!reproductions/**/ExpenseItDemo*.csproj
!reproductions/**/EntityFramework6x*.csproj
vstsFeed: $(packageFeed)

- task: DotNetCoreCLI@2
displayName: dotnet build
displayName: dotnet build integration tests
inputs:
command: build
projects: |
samples/Samples.HttpMessageHandler/Samples.HttpMessageHandler.csproj
test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj
reproductions/**/*.csproj
samples/**/*.csproj
test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj
!reproductions/**/ExpenseItDemo*.csproj
!reproductions/**/EntityFramework6x*.csproj
arguments: --configuration $(buildConfiguration) -p:Platform=$(buildPlatform)
arguments: --configuration $(buildConfiguration) -p:Platform=$(buildPlatform) -p:ManagedProfilerOutputDirectory=$(publishOutput)

- task: NuGetCommand@2
displayName: 'nuget restore reproductions/**/packages.config'
Expand Down Expand Up @@ -160,4 +191,4 @@ jobs:
command: test
configuration: $(buildConfiguration)
projects: test/Datadog.Trace.ClrProfiler.IntegrationTests/Datadog.Trace.ClrProfiler.IntegrationTests.csproj
arguments: '--filter "FullyQualifiedName~Datadog.Trace.ClrProfiler.IntegrationTests.HttpClientTests|Category=Smoke" -p:Platform=$(buildPlatform)'
arguments: '--filter "RunOnWindows=True|Category=Smoke" -p:Platform=$(buildPlatform)'
49 changes: 49 additions & 0 deletions .azure-pipelines/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ variables:
buildConfiguration: release
packageFeed: /ffc32c57-3e0e-4e8f-8633-a7ad01df2e45
dotnetCoreSdkVersion: 2.2.401
publishOutput: $(Build.SourcesDirectory)/src/bin/managed-publish

jobs:

Expand All @@ -33,6 +34,14 @@ jobs:
inputs:
preferBundledVersion: false

- task: DotNetCoreCLI@2
displayName: dotnet build Datadog.Trace.ClrProfiler.Managed.Loader
inputs:
command: build
configuration: $(buildConfiguration)
projects: |
src/Datadog.Trace.ClrProfiler.Managed.Loader/Datadog.Trace.ClrProfiler.Managed.Loader.csproj
- task: NuGetCommand@2
displayName: nuget restore native
inputs:
Expand Down Expand Up @@ -84,6 +93,36 @@ jobs:
artifactName: nuget-packages
targetPath: nuget-output

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework net45
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework net45 --output $(publishOutput)/net45

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework net461
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework net461 --output $(publishOutput)/net461

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework netstandard2.0
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework netstandard2.0 --output $(publishOutput)/netstandard2.0

- task: MSBuild@1
displayName: msbuild msi
inputs:
Expand Down Expand Up @@ -125,6 +164,16 @@ jobs:
projects: src/**/*.csproj
arguments: --configuration $(buildConfiguration)

- task: DotNetCoreCLI@2
displayName: dotnet publish Datadog.Trace.ClrProfiler.Managed --framework netstandard2.0
inputs:
command: publish
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
projects: src/Datadog.Trace.ClrProfiler.Managed/Datadog.Trace.ClrProfiler.Managed.csproj
arguments: --configuration $(buildConfiguration) --framework netstandard2.0 --output $(publishOutput)/netstandard2.0

- task: DockerCompose@0
displayName: docker-compose run Profiler
inputs:
Expand Down
13 changes: 13 additions & 0 deletions .azure-pipelines/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ jobs:
vmImage: windows-2019

steps:
- task: DotNetCoreInstaller@0
displayName: install dotnet core sdk
inputs:
version: $(dotnetCoreSdkVersion)

- task: DotNetCoreCLI@2
displayName: dotnet build Datadog.Trace.ClrProfiler.Managed.Loader
inputs:
command: build
configuration: $(buildConfiguration)
projects: |
src/Datadog.Trace.ClrProfiler.Managed.Loader/Datadog.Trace.ClrProfiler.Managed.Loader.csproj
- task: NuGetCommand@2
displayName: nuget restore
inputs:
Expand Down
3 changes: 1 addition & 2 deletions Datadog.Trace.proj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<CppTestProject Include="test\**\*.vcxproj"/>
<SampleProject Include="samples*\**\*.csproj"/>
<WindowsInstallerProject Include="deploy\**\*.wixproj"/>
<ClrProfilerManagedLoaderProject Include="src\**\Datadog.Trace.ClrProfiler.Managed.Loader.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -53,7 +52,7 @@
</Target>

<Target Name="BuildCpp">
<MSBuild Targets="Build" Projects="@(ClrProfilerManagedLoaderProject);@(CppProject)">
<MSBuild Targets="Build" Projects="@(CppProject)">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput"/>
</MSBuild>
</Target>
Expand Down
47 changes: 47 additions & 0 deletions Test.Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project>
<PropertyGroup>
<OutputType Condition="'$(OutputType)' == ''">Exe</OutputType>
<Platforms>x64;x86</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>

<BaseIntermediateOutputPath Condition="'$(ApiVersion)'!=''">obj\$(ApiVersion)\</BaseIntermediateOutputPath>
<BaseOutputPath Condition="'$(ApiVersion)'!=''">bin\$(ApiVersion)\</BaseOutputPath>

<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<ProfilerOutputDirectory>$(MSBuildThisFileDirectory)\src\Datadog.Trace.ClrProfiler.Native\bin\$(Configuration)\$(Platform)</ProfilerOutputDirectory>
<ManagedProfilerOutputDirectory Condition="'$(ManagedProfilerOutputDirectory)' == ''">$(MSBuildThisFileDirectory)\src\Datadog.Trace.ClrProfiler.Managed\bin\$(Configuration)</ManagedProfilerOutputDirectory>

<DefineConstants Condition="'$(BuildingInsideVisualStudio)'=='true' or '$(TestAllPackageVersions)'!='true'">$(DefineConstants);DEFAULT_SAMPLES</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(ExcludeManagedProfiler)' != 'true' and
'$(LoadManagedProfilerFromProfilerDirectory)' != 'true' ">
<ProjectReference Include="$(MSBuildThisFileDirectory)\src\Datadog.Trace.ClrProfiler.Managed\Datadog.Trace.ClrProfiler.Managed.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(ExcludeNativeProfiler)' != 'true'">
<None Include="$(ProfilerOutputDirectory)\*.dll;$(ProfilerOutputDirectory)\*.so;$(ProfilerOutputDirectory)\*.pdb"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\%(RecursiveDir)\%(Filename)%(Extension)" />
<Content Include="$(MSBuildThisFileDirectory)\integrations.json"
CopyToOutputDirectory="Always"
CopyToPublishDirectory="Always"
Link="profiler-lib\integrations.json" />
</ItemGroup>

<Target Name="AfterBuildCopyManagedProfiler" AfterTargets="AfterBuild" Condition=" '$(LoadManagedProfilerFromProfilerDirectory)' == 'true'">
<ItemGroup>
<!-- Subfolders of the output directory should each be a target framework -->
<ManagedProfilerFiles Include="$(ManagedProfilerOutputDirectory)\**\*.dll" Exclude="$(ManagedProfilerOutputDirectory)\*\runtimes\**\*.dll" />
<ManagedProfilerFiles Include="$(ManagedProfilerOutputDirectory)\**\*.pdb" Exclude="$(ManagedProfilerOutputDirectory)\*\runtimes\**\*.pdb" />
</ItemGroup>

<!-- Remove the following debugging statements when it works in CI-->
<Message Text="ManagedProfilerOutputDirectory = $(ManagedProfilerOutputDirectory)" Importance="High" />
<Message Text="ManagedProfilerFiles = @(ManagedProfilerFiles)" Importance="High" />

<Copy SourceFiles="@(ManagedProfilerFiles)" DestinationFolder="$(OutputPath)profiler-lib\%(RecursiveDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<?define BaseProductName = ".NET Tracer" ?>
<?define ArpManufacturer = "Datadog, Inc." ?>
<?define Company = "Datadog" ?>
<?define ManagedDllPath = "$(sys.CURRENTDIR)..\..\src\Datadog.Trace.ClrProfiler.Managed\bin\$(var.Configuration)\net45" ?>
<?define ManagedDllPath = "$(sys.CURRENTDIR)..\..\src\bin\managed-publish" ?>
<?define NativeDllPath = "$(sys.CURRENTDIR)..\..\src\Datadog.Trace.ClrProfiler.Native\bin\$(var.Configuration)\$(var.Platform)" ?>
<?define ProfilerCLSID = "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}" ?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<DefineConstants>InstallerVersion=$(InstallerVersion)</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Files.Managed.Net45.wxs" />
<Compile Include="Files.Managed.Net461.wxs" />
<Compile Include="Files.Managed.NetStandard20.wxs" />
<Compile Include="Product.wxs" />
<Compile Include="WixUI_InstallDir_Custom.wxs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?include $(sys.CURRENTDIR)\Config.wxi?>
<Fragment>
<ComponentGroup Id="Files.Managed.Net45" Directory="net45">
<Component Win64="$(var.Win64)">
<File Id="net45_Datadog.Trace.ClrProfiler.Managed.dll"
Source="$(var.ManagedDllPath)\net45\Datadog.Trace.ClrProfiler.Managed.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net45_Datadog.Trace.dll"
Source="$(var.ManagedDllPath)\net45\Datadog.Trace.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net45_MsgPack.dll"
Source="$(var.ManagedDllPath)\net45\MsgPack.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net45_Newtonsoft.Json.dll"
Source="$(var.ManagedDllPath)\net45\Newtonsoft.Json.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net45_Sigil.dll"
Source="$(var.ManagedDllPath)\net45\Sigil.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net45_System.Runtime.InteropServices.RuntimeInformation.dll"
Source="$(var.ManagedDllPath)\net45\System.Runtime.InteropServices.RuntimeInformation.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?include $(sys.CURRENTDIR)\Config.wxi?>
<Fragment>
<ComponentGroup Id="Files.Managed.Net461" Directory="net461">
<Component Win64="$(var.Win64)">
<File Id="net461_Datadog.Trace.ClrProfiler.Managed.dll"
Source="$(var.ManagedDllPath)\net461\Datadog.Trace.ClrProfiler.Managed.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_Datadog.Trace.dll"
Source="$(var.ManagedDllPath)\net461\Datadog.Trace.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_MsgPack.dll"
Source="$(var.ManagedDllPath)\net461\MsgPack.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_Newtonsoft.Json.dll"
Source="$(var.ManagedDllPath)\net461\Newtonsoft.Json.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_Sigil.dll"
Source="$(var.ManagedDllPath)\net461\Sigil.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Net.Http.dll"
Source="$(var.ManagedDllPath)\net461\System.Net.Http.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Runtime.InteropServices.RuntimeInformation.dll"
Source="$(var.ManagedDllPath)\net461\System.Runtime.InteropServices.RuntimeInformation.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Security.Cryptography.Algorithms.dll"
Source="$(var.ManagedDllPath)\net461\System.Security.Cryptography.Algorithms.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Security.Cryptography.Encoding.dll"
Source="$(var.ManagedDllPath)\net461\System.Security.Cryptography.Encoding.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Security.Cryptography.Primitives.dll"
Source="$(var.ManagedDllPath)\net461\System.Security.Cryptography.Primitives.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
<Component Win64="$(var.Win64)">
<File Id="net461_System.Security.Cryptography.X509Certificates.dll"
Source="$(var.ManagedDllPath)\net461\System.Security.Cryptography.X509Certificates.dll"
KeyPath="yes" Checksum="yes"/>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Loading

0 comments on commit 7b96de3

Please sign in to comment.