Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Newrelic agent for ASP.NET Core 2.1

rfb

#22

Hi,
I tried with .net core 2.1 (2.1.401) , Newrelic 8.6.45.0, Docker for windows. Its not working.

I have exception, when I run docker image,

Unhandled Exception: System.BadImageFormatException: Bad IL format.
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at NewRelicSupportedWebApp.Program.Main(String[] args) in /src/NewRelicSupportedWebApp/Program.cs:line 17

Here my docker file

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

ENV CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER="{36032161-FFC0-4B61-B559-F6C5D41BAE5A}" \
CORECLR_NEWRELIC_HOME="/usr/local/newrelic-netcore20-agent" \
CORECLR_PROFILER_PATH="/usr/local/newrelic-netcore20-agent/libNewRelicProfiler.so" \
NEW_RELIC_LICENSE_KEY="thisiskey" \
NEW_RELIC_APP_NAME="appname"



ARG NewRelic=./NewRelicSupportedWebApp/newrelic
COPY $NewRelic ./newrelic

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["NewRelicSupportedWebApp/NewRelicSupportedWebApp.csproj", "NewRelicSupportedWebApp/"]
RUN dotnet restore "NewRelicSupportedWebApp/NewRelicSupportedWebApp.csproj"
COPY . .
WORKDIR "/src/NewRelicSupportedWebApp"
RUN dotnet build "NewRelicSupportedWebApp.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "NewRelicSupportedWebApp.csproj" -c Release -o /app




FROM base AS final
WORKDIR /app
COPY --from=publish /app .

RUN dpkg -i ./newrelic/newrelic-netcore20-agent_8.6.45.0_amd64.deb

ENTRYPOINT ["dotnet", "NewRelicSupportedWebApp.dll"]

#23

Hi @oguzhan.eren,

Just to be clear, have you tried running the application without the .NET agent? I don’t see any actual agent methods in the stack trace. It looks like the problem is with something in the applications Main() method. Try running the same application without calling the agent and let us know your results.


#24

I tried to run .net core app in docker with /newrelic/newrelic-netcore20-agent_8.6.45.0_amd64.deb agent (in docker.)

You can find example repository here: https://github.com/oguzhaneren/netcore-docker-newrelic/tree/master/NewRelicSupportedWebApp


#25

Hi,

You are using the MS provided image as base but it doesn’t explicitly call out the runtime version. Is it possible that you are running an older runtime? Are you able to explicitly call out the 2.1.401-sdk in your dockerfile (that is the one that has the fix)?

Thanks


#26

I updated my docker as follow, there is no BAD IL format exception now but applications seems not sending data to newrelic. NewRelic UI didn’t detect any activity.

FROM microsoft/dotnet:2.1.401-sdk AS build-env
WORKDIR /app

ENV CORECLR_ENABLE_PROFILING="1" \
ASPNETCORE_ENVIRONMENT="production" \
CORECLR_PROFILER="{36032161-FFC0-4B61-B559-F6C5D41BAE5A}" \
CORECLR_NEWRELIC_HOME="/usr/local/newrelic-netcore20-agent" \
CORECLR_PROFILER_PATH="/usr/local/newrelic-netcore20-agent/libNewRelicProfiler.so" \
NEW_RELIC_LICENSE_KEY="key" \
NEW_RELIC_APP_NAME="NewrelicSupportedWebApp"


# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

ARG NewRelic=./newrelic/
COPY $NewRelic ./newrelic
#
RUN dpkg -i ./newrelic/newrelic-netcore20-agent_8.6.45.0_amd64.deb



# build runtime image
FROM microsoft/dotnet:2.1.3-aspnetcore-runtime

ENV ASPNETCORE_URLS http://+:80
EXPOSE 80
EXPOSE 802

WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "NewRelicSupportedWebApp.dll"]

#27

I tried microsoft/dotnet:2.1.402-sdk-bionic image and that seems to work fine.


#28

Is there any plan to update the NewRelic.Azure.WebSites.Extension to support .NET Core? It seems like this extension, installable through the kudu interface, only supports .NET Framework as of now