Skip to content

Commit 7786b65

Browse files
[Azure Functions] Restore files moved by in-process Azure Functions SDK (#7419)
## Summary of changes Improve support for in-process Azure Functions my restoring the files moved by the SDK. ## Reason for change The Azure Functions SDK for in-process functions moves files from `$(PublishDir)**\*.dll` to `$(PublishDir)bin\` (keeping the directory structure). This breaks the tracer because the files are not found where expected. Furthermore, it splits the tracer files into two paths because it moves only our `.dll` files but not other files, like `.so`, `loader.confg`, or the agent binaries. See https://github.com/Azure/azure-functions-vs-build-sdk/blob/7a3e505c2382ee9c461985baef1603e980740ca6/src/Microsoft.NET.Sdk.Functions.MSBuild/Targets/Microsoft.NET.Sdk.Functions.Publish.targets#L134-L154 ## Implementation details Add a build target that runs after the SDK's `_GenerateFunctionsAndCopyContentFiles` target. This new target moves any files in `$(PublishDir)bin\datadog\**\*.dll` back to `$(PublishDir)datadog\`, maintaining the directory structure. Directory tree before: ``` .\publish\ ├── bin │ ├── datadog <---- dlls moved to bin/datadog/ │ │ ├── net6.0 │ │ │ └── Datadog.Trace.dll │ │ ├── win-x64 │ │ │ ├── Datadog.Trace.ClrProfiler.Native.dll │ │ │ └── Datadog.Tracer.Native.dll │ │ └── win-x86 │ │ ├── Datadog.Trace.ClrProfiler.Native.dll │ │ └── Datadog.Tracer.Native.dll │ ├── (application files) │ └── ... ├── datadog <---- other tracer files stay in datadog/ │ ├── bin │ │ ├── linux-amd64 │ │ │ └── datadog-serverless-compat │ │ └── windows-amd64 │ │ └── datadog-serverless-compat.exe │ ├── linux-x64 │ │ ├── Datadog.Trace.ClrProfiler.Native.so │ │ ├── Datadog.Tracer.Native.so │ │ └── loader.conf │ ├── net6.0 │ ├── win-x64 │ │ └── loader.conf │ └── win-x86 │ └── loader.conf ├── <function name> │ └── function.json ├── <function name> │ └── function.json ├── ... │ └── function.json └── host.json ``` Directory tree after: ``` .\publish\ ├── bin │ ├── (application files) │ └── ... ├── datadog <---- all tracer files stay in datadog/ │ ├── bin │ │ ├── linux-amd64 │ │ │ └── datadog-serverless-compat │ │ └── windows-amd64 │ │ └── datadog-serverless-compat.exe │ ├── linux-x64 │ │ ├── Datadog.Trace.ClrProfiler.Native.so │ │ ├── Datadog.Tracer.Native.so │ │ └── loader.conf │ ├── net6.0 │ │ └── Datadog.Trace.dll │ ├── win-x64 │ │ ├── Datadog.Trace.ClrProfiler.Native.dll │ │ ├── Datadog.Tracer.Native.dll │ │ └── loader.conf │ └── win-x86 │ ├── Datadog.Trace.ClrProfiler.Native.dll │ ├── Datadog.Tracer.Native.dll │ └── loader.conf ├── <function name> │ └── function.json ├── <function name> │ └── function.json ├── ... │ └── function.json └── host.json ``` ## Test coverage Tested manually. Will add automated tests before officially supporting in-process Azure Functions. ## Other details Fixes APMSVLS-136 <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: Copilot <[email protected]>
1 parent 1695128 commit 7786b65

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

tracer/src/Datadog.AzureFunctions/Datadog.AzureFunctions.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
<PackageCopyToOutput>false</PackageCopyToOutput>
5959
</None>
6060

61+
<None Include="Datadog.AzureFunctions.props" Pack="true" PackagePath="buildTransitive\Datadog.AzureFunctions.props" />
62+
<None Include="Datadog.AzureFunctions.targets" Pack="true" PackagePath="buildTransitive\Datadog.AzureFunctions.targets" />
63+
6164
<!-- win-x64 and win-x86 exclusions -->
6265
<None Remove="$(SourcePath)/win-*/Datadog.Profiler.Native.dll" />
6366
<None Remove="$(SourcePath)/win-*/datadog_profiling_ffi.dll" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<!-- Allow opting out of fix for in-process Azure Functions -->
4+
<RestoreDatadogFiles Condition="'$(RestoreDatadogFiles)' == ''">true</RestoreDatadogFiles>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- This build step is a workaround for the Azure Functions SDK moving our *.dll files from datadog/ to bin/datadog/
2+
See https://github.com/Azure/azure-functions-vs-build-sdk/blob/7a3e505c2382ee9c461985baef1603e980740ca6/src/Microsoft.NET.Sdk.Functions.MSBuild/Targets/Microsoft.NET.Sdk.Functions.Publish.targets#L134-L154 -->
3+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4+
<Target Name="_RestoreDatadogFiles"
5+
AfterTargets="_GenerateFunctionsAndCopyContentFiles"
6+
BeforeTargets="_FunctionsPostPublish"
7+
Condition="'$(RestoreDatadogFiles)' == 'true'">
8+
<!-- get a list of files that were moved -->
9+
<ItemGroup>
10+
<DatadogFilesAfter Include="$(PublishDir)bin\datadog\**\*.dll"/>
11+
</ItemGroup>
12+
13+
<!-- move the files back -->
14+
<Move SourceFiles="@(DatadogFilesAfter)"
15+
DestinationFiles="$(PublishDir)datadog\%(RecursiveDir)%(Filename)%(Extension)"
16+
OverwriteReadOnlyFiles="true" />
17+
18+
<RemoveDir Directories="$(PublishDir)bin\datadog"/>
19+
20+
<Message Text="[Datadog.AzureFunctions] Restored Datadog files from &quot;$(PublishDir)bin/datadog/&quot; back to &quot;$(PublishDir)datadog/&quot;" />
21+
</Target>
22+
</Project>

0 commit comments

Comments
 (0)