newrelic / nri-kubernetes

New Relic integration for Kubernetes
https://docs.newrelic.com/docs/integrations/kubernetes-integration/get-started/introduction-kubernetes-integration
Apache License 2.0
40 stars 51 forks source link

How to configure .net application running in kubernetes pod to see the APM data of app in the newrelic APM tab? #1072

Open Amit-limbasiya opened 2 weeks ago

Amit-limbasiya commented 2 weeks ago

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?

workato-integration[bot] commented 2 weeks ago

https://new-relic.atlassian.net/browse/NR-282738