Installing APM Agent for .NET App on OpenShift

Hello,

I want to install an APM agent on a .NET application running on OpenShift.

How can I do it?

Thanks.

Welcome @Umut!

Are you deploying your app on OpenShift via Kubernetes? I'm not an OpenShift expert but I would have assumed adding the agent to the manifest and adding the required permissions as documented here.

Let us know if that helps!

Hi Umut,

I'm also not familiar with using OpenShift, but for .NET on OpenShift (which is Kubernetes under the hood), I believe the recommended zero-code-change approach is profiler-based auto-instrumentation via an init container, the same as when using k8s directly.

We publish a purpose-built init container image at docker.elastic.co/observability/apm-agent-dotnet: that contains just the profiler binaries. The init container copies those files into a shared emptyDir volume that your application container then reads at startup.

Here is a minimal Deployment manifest that may work as an example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-app
spec:
  template:
    spec:
      initContainers:
        - name: elastic-apm-agent
          image: docker.elastic.co/observability/apm-agent-dotnet:1.34.3
          command: ['sh', '-c', 'cp -r /usr/agent/apm-dotnet-agent/. /elastic-apm-agent/']
          volumeMounts:
            - name: elastic-apm-agent
              mountPath: /elastic-apm-agent
      containers:
        - name: your-app
          image: your-image
          env:
            - name: CORECLR_ENABLE_PROFILING
              value: "1"
            - name: CORECLR_PROFILER
              value: "{FA65FE15-F085-4681-9B20-95E04F6C03CC}"
            - name: CORECLR_PROFILER_PATH
              value: "/elastic-apm-agent/libelastic_apm_profiler.so"
            - name: ELASTIC_APM_PROFILER_HOME
              value: "/elastic-apm-agent"
            - name: ELASTIC_APM_PROFILER_INTEGRATIONS
              value: "/elastic-apm-agent/integrations.yml"
            - name: ELASTIC_APM_SERVICE_NAME
              value: "your-service-name"
            - name: ELASTIC_APM_SERVER_URL
              valueFrom:
                secretKeyRef:
                  name: elastic-apm-secret
                  key: server-url
            - name: ELASTIC_APM_API_KEY
              valueFrom:
                secretKeyRef:
                  name: elastic-apm-secret
                  key: api-key
          volumeMounts:
            - name: elastic-apm-agent
              mountPath: /elastic-apm-agent
      volumes:
        - name: elastic-apm-agent
          emptyDir: {}

Create the secret beforehand using the OpenShift CLI:

oc create secret generic elastic-apm-secret \
  --from-literal=server-url=https://your-apm-server:8200 \
  --from-literal=api-key=your-api-key

We don't explicitly test against OpenShift, so the above is generalised guidance based on the underlying Kubernetes behaviour.

Alternative: bake the profiler into your image(s)

If you prefer not to use an init container, you can include the profiler directly in your application image using a multi-stage Docker build. See the Docker containers section of the auto-instrumentation setup docs.

If you run into any issues specific to OpenShift, please do share the details as it could help us improve our guidance.