asp.netkubernetesnewrelicapm

How to configure .net application running in kubernetes to see the app in the newrelic APM tab?


I have the application running inside the kubernetes pod.

I have installed the newrelic dotnet agent in the kubernetes daemonset via helm command shown in the offical documentation.

Now I want that this .net agent will identify the dotnet application running inside the pod and forward its log as well as APM data like avg response time, % of error etc.

Currently when the application starts i.e. pod is up and running, it is sending the logs in the kubernetes section in newrelic account. where I can see the logs and filter them by pod name or container name. But I cant see the APM data or application in the APM tab. How/what to configure to see the APM data of the application.

New relic dotnet agent installed in the kubernetes daemonset.

I have added two nuget packages in the application:

<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.NewRelic" Version="2.0.0" />

In the launchSettings.json I have added the following environment variables:

"ASPNETCORE_ENVIRONMENT": "Development",
"CORECLR_ENABLE_PROFILING": "1"

I have configured the serilog as following in the appsettings.json:

"Serilog": {
"Properties": {
"app": "test_api",
"Application": "test_api"
},
"WriteTo": {
"NewRelicLogsSink": {
"Name": "NewRelic",
"Args": {
"applicationName": "test_api"
}
}
}
},

Create and Use the log in program.cs: Creation:

var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration, "Serilog")
.Enrich.FromLogContext()
.CreateLogger();

builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);

Use: Log.Information("This is get endpoint from test api");

pod.yaml file

apiVersion: v1
kind: Pod
metadata:
  name: test-api-serilog-pod
  labels:
    app: test-api-serilog
spec:
  containers:
    - name: test-api-serilog-container
      image: test-api-serilog:latest
      imagePullPolicy: Never
      ports:
      - containerPort: 8080
      env:
      - name: ASPNETCORE_ENVIRONMENT
        value: "Development"
      - name: CORECLR_ENABLE_PROFILING
        value: "1"
      - name: NEW_RELIC_APP_NAME
        value: "A new test api serilog 2"        
      - name: NEW_RELIC_LOG
        value: "stdout"
      - name: NEW_RELIC_APPLICATION_LOGGING_ENABLED
        value: "true"
      - name: NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED
        value: "true"
      - name: NEW_RELIC_LICENSE_KEY
        valueFrom:
          secretKeyRef: 
            name: newrelic-bundle-newrelic-logging-config
            key: license

I am able to get logs on the newrelic cloud, which I can filter by pod_name or container_name.

Expecting: Now I want the APM Data in the newrelic cloud like avg.response time or % of error, type of error etc. APM ss Can't see the A new test api serilog 2 (Value of NEW_RELIC_APP_NAME) in the APM tag. Additionally Inside the newrelic cloud Kubernetes->pods->test-api-serilog-pod I can see the logs of the pod but can't see the APM data.

Doubt: Is it necessary to have the dotnet agent installed inside the application running container, Or can we configure the dotnet agent running in daemonset to send the APM data to newrelic as well?


Solution

  • The APM agent does need to run in the container to get the types of information you're looking for. There are three ways to achieve this: add another NuGet package and related config, build it into your container image (follow the install wizard here), or try out the new Kubernetes Agent Operator to automatically inject it. (Note that the last one is still in preview as of July 2024.)