Skip to content

Commit

Permalink
Add support for Microsoft.Azure.Functions.Worker.Core v2 (#6472)
Browse files Browse the repository at this point in the history
## Summary of changes

Adds support for `Microsoft.Azure.Functions.Worker.Core` V2.

## Reason for change

A new major version of it was released and instrumentations stopped at
V1.

## Implementation details

- Checked code changes in
https://github.com/Azure/azure-functions-dotnet-worker/releases/tag/2.0.0
  - Didn't notice anything that appeared would impact us largely
- Upped max version of assembly instrumented
- Added to automated package bump as it was left out

## Test coverage

I relied on CI to run the tests 🙃 
Noticed that the snapshots exception message in the span changed unsure
why

## Other details
<!-- Fixes #{issue} -->

I noticed this old PR
#6203 I'm unsure if this
impacts this?
Fixes DataDog/datadog-aas-extension#295

https://datadoghq.atlassian.net/browse/AIDM-518
https://datadoghq.atlassian.net/browse/AIDM-519

<!-- ⚠️ 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. -->
  • Loading branch information
bouwkast authored Jan 7, 2025
1 parent b34e73c commit f75778d
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 13 deletions.
11 changes: 11 additions & 0 deletions tracer/build/PackageVersionsGeneratorDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,5 +743,16 @@
"4.20.*",
"4.*.*"
]
},
{
"IntegrationName": "AzureFunctions",
"SampleProjectName": "Samples.AzureFunctions.V4Isolated",
"NugetPackageSearchName": "Microsoft.Azure.Functions.Worker",
"MinVersion": "1.6.0",
"MaxVersionExclusive": "3.0.0",
"SpecificVersions": [
"1.6.*",
"2.*.*"
]
}
]
24 changes: 24 additions & 0 deletions tracer/build/PackageVersionsLatestMajors.g.props
Original file line number Diff line number Diff line change
Expand Up @@ -4558,5 +4558,29 @@ NOTE: This code was generated by the GeneratePackageVersions tool. To safely
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.Selenium</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=1.24.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net6.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=2.0.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net6.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=1.24.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net7.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=2.0.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net7.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
</ItemGroup>
</Project>
204 changes: 204 additions & 0 deletions tracer/build/PackageVersionsLatestMinors.g.props

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tracer/build/PackageVersionsLatestSpecific.g.props
Original file line number Diff line number Diff line change
Expand Up @@ -6992,5 +6992,29 @@ NOTE: This code was generated by the GeneratePackageVersions tool. To safely
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.Selenium</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=1.6.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net6.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=2.0.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net6.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=1.6.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net7.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
<PackageVersionSample Include="test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated\Samples.AzureFunctions.V4Isolated.csproj">
<Properties>ApiVersion=2.0.0;RestoreRecursive=false;BuildProjectReferences=false</Properties>
<TargetFramework>net7.0</TargetFramework>
<RequiresDockerDependency>None</RequiresDockerDependency>
<SampleName>Samples.AzureFunctions.V4Isolated</SampleName>
</PackageVersionSample>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with the correct arguments outside of Visual Studio.
<SkipArm64>true</SkipArm64>";

private const string EntryFormat =
@" <PackageVersionSample Include=""test\test-applications\integrations\{0}\{0}.csproj"">
@" <PackageVersionSample Include=""test\test-applications\{4}\{0}\{0}.csproj"">
<Properties>ApiVersion={1};RestoreRecursive=false;BuildProjectReferences=false</Properties>{2}
<RequiresDockerDependency>{3}</RequiresDockerDependency>
<SampleName>{0}</SampleName>
Expand Down Expand Up @@ -90,7 +90,19 @@ public override void Write(PackageVersionEntry packageVersionEntry, IEnumerable<

var properties = targetFrameworkProperty + skipAlpineProperty + skipArm64Property;

FileStringBuilder.AppendLine(string.Format(EntryFormat, packageVersionEntry.SampleProjectName, packageVersion, properties, requiresDockerDependency));
// HACK: support Azure Functions as it is in a different location
var testFolder = "integrations";
if (packageVersionEntry.SampleProjectName.Contains("Samples.AzureFunctions"))
{
testFolder = "azure-functions";
}

FileStringBuilder.AppendLine(string.Format(EntryFormat,
packageVersionEntry.SampleProjectName, // {0}
packageVersion, // {1}
properties, // {2}
requiresDockerDependency, // {3}
testFolder)); // {4}
}
}

Expand Down
3 changes: 2 additions & 1 deletion tracer/build/_build/Honeypot/IntegrationGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static IntegrationMap()
NugetPackages.Add("Serilog", new [] { "Serilog" });
NugetPackages.Add("NLog", new [] { "NLog" });
NugetPackages.Add("log4net", new [] { "log4net" });
NugetPackages.Add("Microsoft.Azure.Functions.Worker.Core", new string[] { });
NugetPackages.Add("Microsoft.Azure.Functions.Worker.Core", new string[] { "Microsoft.Azure.Functions.Worker.Core" });
NugetPackages.Add("Microsoft.Azure.Functions.Worker", new string[] { "Microsoft.Azure.Functions.Worker" });
NugetPackages.Add("Microsoft.Azure.WebJobs.Host", new [] { "Microsoft.Azure.WebJobs" });
NugetPackages.Add("Microsoft.Azure.WebJobs.Script.Grpc", new string[] { });
NugetPackages.Add("Microsoft.Azure.WebJobs.Script.WebHost", new string[] { });
Expand Down
2 changes: 1 addition & 1 deletion tracer/build/supported_calltargets.g.json
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@
"Item3": 0
},
"MaximumVersion": {
"Item1": 1,
"Item1": 2,
"Item2": 65535,
"Item3": 65535
},
Expand Down
14 changes: 12 additions & 2 deletions tracer/build/supported_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,18 @@
"integrationName": "AzureFunctions",
"assemblyName": "Microsoft.Azure.Functions.Worker.Core",
"minAssemblyVersionInclusive": "1.4.0",
"maxAssemblyVersionInclusive": "1.65535.65535",
"packages": []
"maxAssemblyVersionInclusive": "2.65535.65535",
"packages": [
{
"name": "Microsoft.Azure.Functions.Worker.Core",
"minVersionAvailableInclusive": "1.0.0",
"minVersionSupportedInclusive": "1.4.0",
"minVersionTestedInclusive": null,
"maxVersionSupportedInclusive": "2.0.0",
"maxVersionAvailableInclusive": "2.0.0",
"maxVersionTestedInclusive": null
}
]
},
{
"integrationName": "AzureFunctions",
Expand Down
5 changes: 5 additions & 0 deletions tracer/dependabot/Datadog.Dependabot.Integrations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
<!-- Latest package https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.46.0 -->
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.46.0" />

<!-- Integration: Microsoft.Azure.Functions.Worker.Core -->
<!-- Assembly: Microsoft.Azure.Functions.Worker.Core -->
<!-- Latest package https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Core/2.0.0 -->
<PackageReference Include="Microsoft.Azure.Functions.Worker.Core" Version="2.0.0" />

<!-- Integration: Microsoft.Azure.WebJobs.Host -->
<!-- Assembly: Microsoft.Azure.WebJobs.Host -->
<!-- Latest package https://www.nuget.org/packages/Microsoft.Azure.WebJobs/3.0.41 -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="FunctionExecutionMiddlewareInvokeIntegration.cs" company="Datadog">
// <copyright file="FunctionExecutionMiddlewareInvokeIntegration.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand All @@ -20,7 +20,7 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions;
ReturnTypeName = ClrNames.Task,
ParameterTypeNames = new[] { "Microsoft.Azure.Functions.Worker.FunctionContext" },
MinimumVersion = "1.4.0",
MaximumVersion = "1.*.*",
MaximumVersion = "2.*.*",
IntegrationName = AzureFunctionsCommon.IntegrationName)]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ std::vector<CallTargetDefinition3> callTargets =
{(WCHAR*)WStr("AWSSDK.SQS"),(WCHAR*)WStr("Amazon.SQS.AmazonSQSClient"),(WCHAR*)WStr("SendMessageAsync"),sig201,3,3,0,0,3,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.SQS.SendMessageAsyncIntegration"),CallTargetKind::Default,1,15},
{(WCHAR*)WStr("AWSSDK.SQS"),(WCHAR*)WStr("Amazon.SQS.AmazonSQSClient"),(WCHAR*)WStr("SendMessageBatch"),sig026,2,3,0,0,3,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.SQS.SendMessageBatchIntegration"),CallTargetKind::Default,1,15},
{(WCHAR*)WStr("AWSSDK.SQS"),(WCHAR*)WStr("Amazon.SQS.AmazonSQSClient"),(WCHAR*)WStr("SendMessageBatchAsync"),sig200,3,3,0,0,3,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.AWS.SQS.SendMessageBatchAsyncIntegration"),CallTargetKind::Default,1,15},
{(WCHAR*)WStr("Microsoft.Azure.Functions.Worker.Core"),(WCHAR*)WStr("Microsoft.Azure.Functions.Worker.Pipeline.FunctionExecutionMiddleware"),(WCHAR*)WStr("Invoke"),sig163,2,1,4,0,1,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions.FunctionExecutionMiddlewareInvokeIntegration"),CallTargetKind::Default,1,14},
{(WCHAR*)WStr("Microsoft.Azure.Functions.Worker.Core"),(WCHAR*)WStr("Microsoft.Azure.Functions.Worker.Pipeline.FunctionExecutionMiddleware"),(WCHAR*)WStr("Invoke"),sig163,2,1,4,0,2,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions.FunctionExecutionMiddlewareInvokeIntegration"),CallTargetKind::Default,1,14},
{(WCHAR*)WStr("Microsoft.Azure.WebJobs.Host"),(WCHAR*)WStr("Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor"),(WCHAR*)WStr("TryExecuteAsync"),sig212,3,3,0,0,3,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions.AzureFunctionsExecutorTryExecuteAsyncIntegration"),CallTargetKind::Default,1,14},
{(WCHAR*)WStr("Microsoft.Azure.WebJobs.Script.Grpc"),(WCHAR*)WStr("Microsoft.Azure.WebJobs.Script.Grpc.GrpcMessageConversionExtensions"),(WCHAR*)WStr("ToRpcHttp"),sig213,4,4,0,0,4,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions.GrpcMessageConversionExtensionsToRpcHttpIntegration"),CallTargetKind::Default,1,14},
{(WCHAR*)WStr("Microsoft.Azure.WebJobs.Script.WebHost"),(WCHAR*)WStr("Microsoft.Azure.WebJobs.Script.WebHost.Middleware.FunctionInvocationMiddleware"),(WCHAR*)WStr("Invoke"),sig160,2,3,0,0,4,65535,65535,assemblyName,(WCHAR*)WStr("Datadog.Trace.ClrProfiler.AutoInstrumentation.Azure.Functions.FunctionInvocationMiddlewareInvokeIntegration"),CallTargetKind::Default,1,14},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ protected async Task AssertIsolatedSpans(IImmutableList<MockSpan> spans)
new(@"Microsoft.Azure.WebJobs.Extensions, Version=\d.\d.\d.\d"),
@"Microsoft.Azure.WebJobs.Extensions, Version=0.0.0.0");

settings.AddRegexScrubber(new(@" in .+\.cs:line \d+"), string.Empty);

await VerifyHelper.VerifySpans(spans, settings)
.UseFileName($"{nameof(AzureFunctionsTests)}.Isolated")
.DisableRequireUniquePrefix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,7 @@ public class PackageVersions
public static IEnumerable<object[]> AzureServiceBus => IsAllMinorPackageVersions ? PackageVersionsLatestMinors.AzureServiceBus : PackageVersionsLatestSpecific.AzureServiceBus;

public static IEnumerable<object[]> Selenium => IsAllMinorPackageVersions ? PackageVersionsLatestMinors.Selenium : PackageVersionsLatestSpecific.Selenium;

public static IEnumerable<object[]> AzureFunctions => IsAllMinorPackageVersions ? PackageVersionsLatestMinors.AzureFunctions : PackageVersionsLatestSpecific.AzureFunctions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,24 @@ public class PackageVersionsLatestMajors
#if NET9_0
new object[] { "4.27.0" },
#endif
#endif
};

public static IEnumerable<object[]> AzureFunctions =>

new List<object[]>
{
#if DEFAULT_SAMPLES
new object[] { string.Empty },
#else
#if NET6_0
new object[] { "1.24.0" },
new object[] { "2.0.0" },
#endif
#if NET7_0
new object[] { "1.24.0" },
new object[] { "2.0.0" },
#endif
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6009,6 +6009,54 @@ public class PackageVersionsLatestMinors
new object[] { "4.26.1" },
new object[] { "4.27.0" },
#endif
#endif
};

public static IEnumerable<object[]> AzureFunctions =>

new List<object[]>
{
#if DEFAULT_SAMPLES
new object[] { string.Empty },
#else
#if NET6_0
new object[] { "1.6.0" },
new object[] { "1.8.0" },
new object[] { "1.9.0" },
new object[] { "1.10.1" },
new object[] { "1.13.0" },
new object[] { "1.14.1" },
new object[] { "1.15.0" },
new object[] { "1.16.0" },
new object[] { "1.17.0" },
new object[] { "1.18.0" },
new object[] { "1.19.0" },
new object[] { "1.20.1" },
new object[] { "1.21.0" },
new object[] { "1.22.0" },
new object[] { "1.23.0" },
new object[] { "1.24.0" },
new object[] { "2.0.0" },
#endif
#if NET7_0
new object[] { "1.6.0" },
new object[] { "1.8.0" },
new object[] { "1.9.0" },
new object[] { "1.10.1" },
new object[] { "1.13.0" },
new object[] { "1.14.1" },
new object[] { "1.15.0" },
new object[] { "1.16.0" },
new object[] { "1.17.0" },
new object[] { "1.18.0" },
new object[] { "1.19.0" },
new object[] { "1.20.1" },
new object[] { "1.21.0" },
new object[] { "1.22.0" },
new object[] { "1.23.0" },
new object[] { "1.24.0" },
new object[] { "2.0.0" },
#endif
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,24 @@ public class PackageVersionsLatestSpecific
new object[] { "4.20.0" },
new object[] { "4.27.0" },
#endif
#endif
};

public static IEnumerable<object[]> AzureFunctions =>

new List<object[]>
{
#if DEFAULT_SAMPLES
new object[] { string.Empty },
#else
#if NET6_0
new object[] { "1.6.0" },
new object[] { "2.0.0" },
#endif
#if NET7_0
new object[] { "1.6.0" },
new object[] { "2.0.0" },
#endif
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@
error.stack:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Exception
---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: System.InvalidOperationException: Task failed successfully.
at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log),
Exception: Task failed successfully.
Stack: at Samples.AzureFunctions.AllTriggers.AllTriggers.Exception(HttpRequestData req, ILogger log)
at Samples.AzureFunctions.V4Isolated.DirectFunctionExecutor.ExecuteAsync(FunctionContext context),
error.type: Microsoft.Azure.WebJobs.Host.FunctionInvocationException,
http.method: GET,
http.request.headers.host: localhost:00000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ApiVersion Condition="'$(ApiVersion)' == ''">2.0.0</ApiVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
Expand All @@ -8,9 +9,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" Condition="'$(ApiVersion)' &gt;= '2.0.0'" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" Condition="'$(ApiVersion)' &lt; '2.0.0'" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="$(ApiVersion)" />
</ItemGroup>

<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit f75778d

Please sign in to comment.