Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when distributed tracing is enabled and using ASP.NET Core RequestLocalization middleware #22

Closed
alanwest opened this issue Jul 8, 2020 · 2 comments · Fixed by #493
Assignees
Labels
bug Something isn't working

Comments

@alanwest
Copy link
Member

alanwest commented Jul 8, 2020

Description

Agent causes exception when distributed tracing is enabled and ASP.NET Core application uses the RequestLocalization middleware. Appears to affect ASP.NET Core apps running on Linux in a docker container.

Steps to Reproduce

Create new Web API

mkdir locale
cd locale
dotnet new webapi

Add the RequestLocalization middleware in Startup.cs

var supportedCultures = new[]
{
    new CultureInfo("en-US"),
    new CultureInfo("ar"),
};

app.UseRequestLocalization(new RequestLocalizationOptions
{
    DefaultRequestCulture = new RequestCulture("en-US"),
    SupportedCultures = supportedCultures
});

Add the following controller

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace RequestLocalization.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class TestController : ControllerBase
    {
        [HttpGet]
        public async Task<string> Get()
        {
            using (var client = new System.Net.Http.HttpClient())
            {
                return await client.GetStringAsync("https://newrelic.com");
            }
        }
    }
}

Create a Dockerfile and replace put_license_key_here

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.0

RUN curl -O https://download.newrelic.com/dot_net_agent/latest_release/newrelic-netcore20-agent_8.29.0.0_amd64.deb
RUN dpkg -i ./newrelic-netcore20-agent*.deb

ENV CORECLR_NEWRELIC_HOME /usr/local/newrelic-netcore20-agent
ENV NEW_RELIC_LICENSE_KEY put_license_key_here

WORKDIR /app
COPY ./bin/Debug/netcoreapp3.1/publish .

EXPOSE 5000

ENTRYPOINT ["/bin/bash", "-c", "dotnet locale.dll"]

Create a docker-compose.yml file

version: "3"

services:
  locale:
    image: locale:latest
    ports:
      - 5000:5000
    environment:
      ASPNETCORE_URLS: http://*:5000
      ASPNETCORE_ENVIRONMENT: Development
      CORECLR_ENABLE_PROFILING: 1
      CORECLR_PROFILER: "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}"
      CORECLR_PROFILER_PATH: /usr/local/newrelic-netcore20-agent/libNewRelicProfiler.so
      NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: "true"

Publish and run the application

dotnet publish
docker build -t locale .
docker-compose up

Hit the endpoint

curl -s -H 'Accept-Language: ar' -XGET http://localhost:5000/Test

You will get the following exception:

System.Net.Http.HttpRequestException: Request headers must contain only ASCII characters.
@alanwest alanwest added the bug Something isn't working label Jul 8, 2020
@github-actions
Copy link
Contributor

This has been marked stale after 30 days with no activity. It will be closed in 5 days if there is no activity.

@github-actions github-actions bot added the stale label Aug 22, 2020
@angelatan2 angelatan2 added this to the Q3 .NET Bug Smash Milestone milestone Sep 9, 2020
@angelatan2 angelatan2 added the on-hold On hold pending more information label Nov 13, 2020
@angelatan2
Copy link
Contributor

Monitoring for more community feedback on this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants