Skip to content

Extended HttpClient logger doesn't export {OriginalFormat} field #6364

@iliar-turdushev

Description

@iliar-turdushev

Description

Extended HttpClient logger from the M.E.Http.Diagnostics package doesn't export {OriginalFormat} field. As a result, when used together with OpenTelemetry the message being exported (LogRecord.Body property in OpenTelemetry) is always formatted.

Reproduction Steps

Project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <LangVersion>13</LangVersion>
    <Nullable>enable</Nullable>
    <TargetFramework>net8.0</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
    <PackageReference Include="Microsoft.Extensions.Compliance.Redaction" Version="9.4.0" />
    <PackageReference Include="Microsoft.Extensions.Http.Diagnostics" Version="9.4.0" />
    <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.1" />
  </ItemGroup>
</Project>

C# code:

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;

internal static class Program
{
    public static async Task Main()
    {
        using IHost host = new HostBuilder()
            .ConfigureServices((_, services) =>
            {
                services.AddLogging(builder => builder.AddOpenTelemetry(options => options.AddConsoleExporter()));
                services.AddRedaction();
                services.AddHttpClient("test-client").AddExtendedHttpClientLogging();
            })
            .Build();

        await host.StartAsync();

        var factory = host.Services.GetRequiredService<IHttpClientFactory>();
        var client = factory.CreateClient("test-client");
        await client.GetAsync("https://microsoft.com/api/users/{userId}");

        await host.StopAsync();
    }
}

Expected behavior

  • Body must not be formatted, it must include parameter placeholders: {http.request.method} {server.address}/{url.path}.
  • {OriginalFormat} must be included in the attributes of the LogRecord.

Actual behavior

The Body is formatted, the Attributes doesn't include {OriginalFormat}.

Image

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Labels

area-telemetrybugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions