Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ runs:
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x

- id: dotnet
shell: bash
Expand Down
35 changes: 31 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<!--
Platform package lines (System.Diagnostics.DiagnosticSource and the other .NET-versioned
System.* packages that Elastic.Apm references directly).

Rule, enforced at pack time by the build (Build.verifyPlatformPackageParity):
* net8.0 / net10.0 assets reference the in-box line of their runtime (net8.0: the PackageVersion items below,
net10.0: Net10PlatformPackageVersion). Referencing higher forces an out-of-band copy into every consumer and
breaks startup-hook / profiler loading on that runtime.
* netstandard2.0 / netstandard2.1 assets must not reference a version higher than the lowest
runtime-specific asset (currently the net8.0 line). Integration packages ship only netstandard
assets, those assets land on .NET 8 hosts, and .NET cannot bind to a lower version than referenced.
The PackageVersion items below therefore stay on the 8.0.x line.
* net462 / net472 assets have no in-box copy, so the package is the only source. They use the newest
supported LTS line (the NetFx* properties below). Referencing higher than netstandard is safe here
because .NET Framework binding redirects unify upward.
-->
<PropertyGroup>
<!-- net462 / net472: 8.x LTS line of the .NET-versioned platform packages -->
<NetFxPlatformPackageVersion>8.0.1</NetFxPlatformPackageVersion>
<!-- net10.0: the in-box line of the runtime (DiagnosticSource, PerformanceCounter, Microsoft.Extensions.*). -->
<Net10PlatformPackageVersion>10.0.11</Net10PlatformPackageVersion>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="MinVer" Version="6.0.0" PrivateAssets="All" />
<GlobalPackageReference Condition="'$(TargetFramework)' == 'net462'" Include="Microsoft.NETFramework.ReferenceAssemblies.net462" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>
<!-- Community Packages -->
<ItemGroup>
<PackageVersion Include="AngleSharp" Version="0.14.0" />
<PackageVersion Include="AngleSharp" Version="1.5.2" />
<PackageVersion Include="AngleSharp.Io" Version="1.0.0" />
<PackageVersion Include="Antlr3.Runtime" Version="3.5.1" />
<PackageVersion Include="Azure.Messaging.ServiceBus" Version="7.0.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.13.0" />
Expand Down Expand Up @@ -104,9 +127,10 @@
<PackageVersion Include="Microsoft.Azure.Storage.Blob" Version="11.2.2" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" PrivateAssets="All" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" PrivateAssets="All" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
Expand All @@ -125,13 +149,16 @@
<PackageVersion Include="System.Data.SQLite" Version="1.0.112" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="8.0.1" />
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
<PackageVersion Include="System.Reflection.Emit" Version="4.3.0" />
<PackageVersion Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="5.0.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.1" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.1" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.ValueTuple" Version="4.6.2" />
</ItemGroup>
</Project>
88 changes: 87 additions & 1 deletion build/scripts/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,91 @@ module Build =
currentDiagnosticSourceVersion <- Some(version)
version

/// Verifies the platform package rule documented in Directory.Packages.props against the packed Elastic.Apm nuspec.
/// For each of the four .NET-versioned platform packages (DiagnosticSource, Reflection.Metadata,
/// Tasks.Dataflow, PerformanceCounter):
/// * net8.0 and net10.0 must not reference a higher major version than their runtime,
/// * netstandard2.0 and netstandard2.1 must reference the same version,
/// * netstandard must not reference a higher version than net8.0 (and net8.0 not higher than net10.0),
/// because netstandard-only integration assets land on those runtimes and .NET cannot bind to a lower version,
/// * net462 and net472 must reference the same version, not lower than netstandard (redirects unify upward),
/// * all six TFM groups must be present (a missing group means the package was not built for that target).
let VerifyPlatformPackageParity () =
let isCorePackage (file: string) =
let name = Path.GetFileName file
let prefix = "Elastic.Apm."
name.StartsWith(prefix) && name.Length > prefix.Length && Char.IsDigit name.[prefix.Length] && not (name.Contains ".symbols.")
let nupkg =
if Directory.Exists Paths.NugetOutput then
let pkgs =
Directory.GetFiles(Paths.NugetOutput, "Elastic.Apm.*.nupkg")
|> Array.filter isCorePackage
// Array.tryHead picks an arbitrary file when stale packages from earlier builds are present.
// Fail loudly so callers know to clean the output directory before verifying.
if pkgs.Length > 1 then
failwithf "Platform package parity check: %d core packages found in %s; clean the output directory first." pkgs.Length Paths.NugetOutput
Array.tryHead pkgs
else None
match nupkg with
| None -> failwithf "Platform package parity check: no Elastic.Apm nupkg found in %s" Paths.NugetOutput
| Some path ->
use zip = ZipFile.OpenRead path
let entry = zip.Entries |> Seq.find (fun e -> e.FullName.EndsWith ".nuspec")
use stream = entry.Open()
let doc = XDocument.Load stream
let ns = doc.Root.GetDefaultNamespace()
let groupTfms =
doc.Descendants(ns + "group")
|> Seq.map (fun g -> g.Attribute(XName.Get "targetFramework").Value)
|> Set.ofSeq
// All six TFM groups must be present in the nuspec.
let requiredTfms = [ ".NETStandard2.0"; ".NETStandard2.1"; "net8.0"; "net10.0"; ".NETFramework4.6.2"; ".NETFramework4.7.2" ]
for tfm in requiredTfms do
if not (Set.contains tfm groupTfms) then
failwithf "Platform package parity check: expected TFM group '%s' is absent from %s" tfm path
let fail rule = failwithf "Platform package parity check failed (%s). See the rule in Directory.Packages.props." rule
let checkPackage (packageId: string) =
let versionByTfm =
doc.Descendants(ns + "group")
|> Seq.choose (fun g ->
let tfm = g.Attribute(XName.Get "targetFramework").Value
g.Elements(ns + "dependency")
|> Seq.tryFind (fun d -> d.Attribute(XName.Get "id").Value = packageId)
|> Option.map (fun d -> tfm, SemVer.parse (d.Attribute(XName.Get "version").Value)))
|> Map.ofSeq
// netstandard and .NET Framework targets have no in-box copy, so the dependency must be explicit.
let explicitVersion tfm =
match Map.tryFind tfm versionByTfm with
| Some v -> v
| None -> failwithf "Platform package parity check: no %s dependency for %s in %s" packageId tfm path
// Runtime-specific targets: the SDK prunes references that the framework provides in-box, so a
// missing dependency means the in-box line of that runtime. Runtime lines are compared by major
// version only: a pruned group reads as x.0.0, while an explicit dependency carries a patch (e.g. 8.0.1).
let inBoxVersion tfm (inBoxLine: string) =
defaultArg (Map.tryFind tfm versionByTfm) (SemVer.parse inBoxLine)
groupTfms |> Set.iter (fun tfm ->
let shown = match Map.tryFind tfm versionByTfm with Some v -> string v | None -> "(in-box, pruned)"
printfn "%-48s %-18s %s" packageId tfm shown)
let ns20, ns21 = explicitVersion ".NETStandard2.0", explicitVersion ".NETStandard2.1"
let net462, net472 = explicitVersion ".NETFramework4.6.2", explicitVersion ".NETFramework4.7.2"
let net8 = inBoxVersion "net8.0" "8.0.0"
let net10 = inBoxVersion "net10.0" "10.0.0"
if net8.Major > 8u then fail $"{packageId}: net8.0 must not reference a version line higher than 8"
if net10.Major > 10u then fail $"{packageId}: net10.0 must not reference a version line higher than 10"
if ns20 <> ns21 then fail $"{packageId}: netstandard2.0 and netstandard2.1 must reference the same version"
if ns20.Major > net8.Major then fail $"{packageId}: netstandard must not reference a higher version line than net8.0"
if net8.Major > net10.Major then fail $"{packageId}: net8.0 must not reference a higher version line than net10.0"
if net462 <> net472 then fail $"{packageId}: net462 and net472 must reference the same version"
if net462.Major < ns20.Major then fail $"{packageId}: net462/net472 must not reference a lower version line than netstandard"
let platformPackages = [
"System.Diagnostics.DiagnosticSource"
"System.Reflection.Metadata"
"System.Threading.Tasks.Dataflow"
"System.Diagnostics.PerformanceCounter"
]
platformPackages |> List.iter checkPackage
printfn "Platform package parity check passed for %s" (Path.GetFileName path)

/// Publishes specific projects with specific DiagnosticSource versions
let private publishProjectsWithDiagnosticSourceVersion projects version =
projects
Expand Down Expand Up @@ -219,6 +304,7 @@ module Build =
/// Packages projects into nuget packages
let Pack () =
DotNet.Exec ["pack" ; Paths.Solution; "-c"; "Release"; $"--property:PackageOutputPath=%s{Paths.NugetOutput}"]
VerifyPlatformPackageParity()

let Clean () =
Shell.cleanDir Paths.BuildOutputFolder
Expand Down Expand Up @@ -329,4 +415,4 @@ module Build =
if File.exists zip then
printf $"%s{zip} already exists on disk"
File.delete zip
ZipFile.CreateFromDirectory(profilerDir.FullName, zip)
ZipFile.CreateFromDirectory(profilerDir.FullName, zip)
4 changes: 3 additions & 1 deletion build/scripts/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ module Main =
Targets.Target("publish", ["restore"; "clean"; "version"], fun _ -> Build.Publish None)

Targets.Target("pack", ["agent-zip"; "profiler-zip"], fun _ -> Build.Pack())


Targets.Target("verify-platform-packages", fun _ -> Build.VerifyPlatformPackageParity())

let startupHookZip () =
printfn "Running startup hooks zip..."
let projs = !! (Paths.SrcProjFile "Elastic.Apm")
Expand Down
53 changes: 53 additions & 0 deletions docs/reference/setup-asp-dot-net.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,59 @@
* The deployed .NET application must NOT run under quirks mode. This makes `LegacyAspNetSynchronizationContext` the async context handler and can break `HttpContext.Items` correctly restoring when async code introduces a thread switch.
::::

::::{important}
**Binding redirects.** The agent's .NET Framework assemblies reference the 8.x line of the .NET platform packages, for example `System.Diagnostics.DiagnosticSource` 8.0.x. ASP.NET applications, including SDK-style projects, do not automatically update `web.config` with binding redirects at build time. Add or update the required redirects in `web.config`, or configure your build tooling to do so. Regardless of project style, verify that the deployed `web.config` redirects the assemblies that the agent brings into the application to the versions deployed to the application's `bin` folder. Missing or outdated redirects can prevent the module from loading with a `FileLoadException`.

The following redirects cover the assemblies the agent itself depends on. The versions match the packages the agent depends on at this release:

```xml
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Dataflow" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.PerformanceCounter" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<!-- The next two entries apply only to applications targeting .NET Framework 4.6.2, where the agent brings these two
packages. Include them only when the corresponding assemblies are present in your bin folder. -->
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
```

In every entry, `newVersion` must be the assembly version of the file that is actually in your `bin` folder, and the upper bound of `oldVersion` must be the same version. If another package in your application brings a newer version of one of these assemblies, or of shared dependencies such as `System.Memory`, `System.Buffers` and `System.Numerics.Vectors`, redirect to the version in `bin` instead of the values shown here. Check the versions again after updating the agent, because they change when the agent updates its dependencies.

Check notice on line 127 in docs/reference/setup-asp-dot-net.md

View workflow job for this annotation

GitHub Actions / build / vale

Elastic.Versions: Use 'later version' instead of 'newer version' when referring to versions.
::::


1. Recompile your application and deploy it.

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "9.0.303",
"version": "10.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
}
2 changes: 1 addition & 1 deletion sample/ApiSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ public static void SampleSpanWithCustomContextFillAll()
// ReSharper disable once UseObjectOrCollectionInitializer
#pragma warning disable IDE0017
span.Context.Http = new Http { Url = "http://mysite.com", Method = "GET" };
#pragma warning restore IDE0017
// send request, get response with status code
span.Context.Http.StatusCode = 200;
#pragma warning restore IDE0017
});

transaction.CaptureSpan("SampleSpan2", "SampleSpanType",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

<ItemGroup>
<ProjectReference Include="..\Elastic.Apm\Elastic.Apm.csproj" />
<!-- Not part of the default .NET Framework 4.6.2 reference set. -->
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/Elastic.Apm/BackendComm/BackendCommUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ internal static HttpClientHandler CreateHttpClientHandler(IConfiguration configu
{
try
{
#if NET9_0_OR_GREATER
var serverCertificate = X509CertificateLoader.LoadCertificateFromFile(configuration.ServerCert);
#else
var serverCertificate = new X509Certificate2(configuration.ServerCert);
#endif
var publicKey = serverCertificate.GetPublicKeyString();

serverCertificateCustomValidationCallback = (_, certificate, _, policyError) =>
Expand Down
4 changes: 3 additions & 1 deletion src/Elastic.Apm/Config/ConfigurationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public static void PrintAgentLogPreamble(IApmLogger logger, IConfigurationReader
info.Log("Time zone: {TimeZone}", TimeZoneInfo.Local);
info.Log("Runtime: {RunTime}", RuntimeInformation.FrameworkDescription);

#if NET8_0
#if NET10_0
info.Log("Matched TFM: {TargetFrameworkMoniker}", "net10.0");
#elif NET8_0
info.Log("Matched TFM: {TargetFrameworkMoniker}", "net8.0");
#elif NETSTANDARD2_0
info.Log("Matched TFM: {TargetFrameworkMoniker}", "netstandard2.0");
Expand Down
Loading
Loading