Get started with OpenTelemetry profiling

OpenTelemetry profiling collects whole-system, always-on CPU profiles from your Linux hosts with the OpenTelemetry eBPF profiler. It doesn't require code instrumentation, debug symbols on the host, or service restarts, and it works with native code and most popular languages, such as Java, Python, and Node.js, out of the box.

To use OpenTelemetry profiling, install the OpenTelemetry Profiling integration on the hosts you want to profile, point it at your deployment or project, and the data shows up in the Profiling app.

On Elastic Cloud Serverless, OpenTelemetry profiling is the only supported way to collect profiles.

The profiler is a receiver that runs inside Elastic Agent, or inside any OpenTelemetry Collector that includes it, on each host you profile. It reads stack samples from the kernel through eBPF (which is why it needs elevated privileges) and sends the profiles straight to Elasticsearch with the elasticsearch exporter. There is no separate backend to install or operate, as OpenTelemetry profiling only needs the profiler on the host and an Elasticsearch endpoint it can reach. Elasticsearch stores the profiles in data streams that it creates automatically.

  • Elastic Stack 9.6 or later on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, or a self-managed deployment, or an Elastic Observability Serverless project. For the serverless tiers required, refer to Elastic Observability Serverless feature tiers.
  • On Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed deployments, a subscription that includes Profiling.
  • On self-managed and Elastic Cloud on Kubernetes deployments, the Profiling app must be turned on in Kibana, as described in Turn on Profiling.
  • Kibana privileges to add integrations and manage agent policies in Fleet if you deploy the profiler with Fleet. Refer to Required roles and privileges for the roles that grant them.

The profiler runs on each host you want to profile. Every host must meet these requirements:

  • Linux with an x86_64 or ARM64 CPU. The profiler doesn't run on other operating systems or CPU architectures.
  • Linux kernel 5.10 or later with eBPF support.
  • Access to the host's tracefs or debugfs filesystem. On Linux, tracefs is mounted at /sys/kernel/tracing. If the profiler runs in a container, mount that host directory read-only at /sys/kernel/tracing in the container. Running the container as privileged doesn't expose the directory.
  • Root privileges or the CAP_SYS_ADMIN capability for the profiler process. Elastic Agent in unprivileged mode is not supported: run it as root.
  • Elastic Agent 9.4 or later if you deploy the profiler with Fleet.

The profiler captures native code, such as C, C++, Go, and Rust, as well as applications written in these runtimes:

Runtime Minimum version
JVM/JDK 7
Python 3.6
V8 (Node.js) 8.1.0
Perl 5.28
PHP 7.3
Ruby 2.5
.NET 6
Erlang/OTP 27.2.4

On Elastic Cloud Hosted, Elastic Cloud Enterprise, and Serverless, the Profiling app is turned on by default. However, on self-managed and Elastic Cloud on Kubernetes deployments, the Kibana plugin is turned off. To turn it on, add the following setting to kibana.yml and restart Kibana:

xpack.profiling.enabled: true
		

On Elastic Cloud on Kubernetes, add this setting under spec.config in the Kibana resource. For more information, refer to Configure Kibana on Elastic Cloud on Kubernetes. This setting is the only Kibana configuration OpenTelemetry profiling needs. You don't need to change anything in Elasticsearch, as the profiling plugin and the OpenTelemetry index templates are installed by default.

Select the deployment option that matches how you run Elastic Agent:

These options run the same profiling receiver. For details about the integration, refer to OpenTelemetry Profiling.

Note

Whichever option you select, run exactly one profiler per host. Don't run a separate profiler container beside each application.

  1. In Kibana, find Infrastructure in the navigation menu and open Profiling, or use the global search field, then click Add data. If your deployment or project has no profiling data yet, the Add profiling data page opens directly.
  2. On the Profiling tab, click Add OpenTelemetry Profiling integration. The page opens in Integrations. You can also find it by searching for OpenTelemetry Profiling in Integrations.
  3. Click Add OpenTelemetry Profiling and configure the integration:
    • Optionally, expand the settings for OpenTelemetry Profiling receiver, then Advanced options, and set samples_per_second to change how often the profiler samples each CPU. Lower values reduce overhead and storage at the cost of detail.
    • Select an existing agent policy or create a new one. Every Elastic Agent enrolled in this policy runs the profiler, so use a policy for hosts that meet the host requirements.
  4. Click Save and continue. Fleet installs the integration and adds it to the agent policy you selected. Agents already enrolled in that policy receive it automatically.
  5. Install a Fleet-managed Elastic Agent on each host you want to profile and enroll it in the policy. The agent must run as root.

If you run Elastic Agent on Kubernetes managed by Fleet, follow Run Elastic Agent on Kubernetes managed by Fleet and make these changes in the DaemonSet. The profiler needs access to the host's processes, elevated privileges, and tracefs:

  1. Set hostPID: true under spec.template.spec, and set the following securityContext on the Elastic Agent container under spec.template.spec.containers:

    securityContext:
      readOnlyRootFilesystem: true
      privileged: true
      runAsUser: 0
      runAsGroup: 0
      capabilities:
        add:
          - SYS_ADMIN
    		
  2. Mount the host's /sys/kernel/tracing directory read-only at /sys/kernel/tracing in the Elastic Agent container. The security context alone doesn't expose tracefs.

  1. Download and extract Elastic Agent for your Linux architecture. The package includes the otelcol executable.

  2. In the extracted directory, save the following configuration as otel.yml. It adds the profiling receiver to a profiles pipeline and sends the profiles to Elasticsearch with the elasticsearch exporter in the otel mapping mode. Replace <ELASTICSEARCH_ENDPOINT> with your Elasticsearch URL and <ELASTICSEARCH_API_KEY> with an encoded Elasticsearch API key:

    receivers:
      profiling:
        samples_per_second: 19
    
    exporters:
      elasticsearch:
        endpoint: <ELASTICSEARCH_ENDPOINT>
        api_key: <ELASTICSEARCH_API_KEY>
        mapping:
          mode: otel
    
    service:
      pipelines:
        profiles:
          receivers: [ profiling ]
          exporters: [ elasticsearch ]
    		
    1. Optional. Defaults to 20.
  3. Profiles support in the Collector is behind the service.profilesSupport feature gate. From the extracted directory, start the Collector with the feature turned on and with elevated privileges:

    sudo ./otelcol --config otel.yml --feature-gates=service.profilesSupport
    		

Optionally, you can collect metrics instead of raw profiles. The profilingmetrics connector turns each stack sample into OpenTelemetry metrics that break down CPU time by frame type, shared library, kernel subsystem, and system call. Those metrics use less ingest and storage than raw profiles, and they power the Elastic OTel Profiling Metrics dashboards. However, as this configuration doesn't send raw profiles, the stacktraces, flamegraphs, and functions views stay empty.

  1. Save the following configuration as otel.yml. Replace <ELASTICSEARCH_ENDPOINT> and <ELASTICSEARCH_API_KEY> with your Elasticsearch URL and API key:

    receivers:
      profiling:
        samples_per_second: 19
    
    connectors:
      profilingmetrics:
    
    exporters:
      elasticsearch:
        endpoint: <ELASTICSEARCH_ENDPOINT>
        api_key: <ELASTICSEARCH_API_KEY>
        mapping:
          mode: otel
    
    service:
      pipelines:
        profiles:
          receivers: [ profiling ]
          exporters: [ profilingmetrics ]
        metrics:
          receivers: [ profilingmetrics ]
          exporters: [ elasticsearch ]
    		
    1. Optional. Defaults to 20.
  2. Start the Collector:

    sudo ./otelcol --config otel.yml --feature-gates=service.profilesSupport
    		

    If it is already running, stop it and start it again with the same command.

To profile every node in a cluster, run the Collector as a DaemonSet. The OpenTelemetry Collector Helm chart has a profiling preset that adds the receiver to a profiles pipeline and configures the host PID access, security context, and volumes the eBPF profiler needs.

  1. Save the following example as profiling-values.yml. It uses the Elastic Agent image, and the ELASTIC_AGENT_OTEL environment variable configures Elastic Agent as an OTel Collector. Replace <ELASTIC_AGENT_VERSION> with the version you deploy, and replace the endpoint and API key placeholders with your Elasticsearch connection details. Set the image tag explicitly: the chart's default tag is an upstream Collector version, not an Elastic Agent version.

    mode: daemonset
    
    image:
      repository: docker.elastic.co/elastic-agent/elastic-agent
      tag: "<ELASTIC_AGENT_VERSION>"
    
    extraEnvs:
      - name: ELASTIC_AGENT_OTEL
        value: "true"
    
    presets:
      profiling:
        enabled: true
    
    command:
      extraArgs:
        - --feature-gates=service.profilesSupport
    
    config:
      exporters:
        elasticsearch:
          endpoint: <ELASTICSEARCH_ENDPOINT>
          api_key: <ELASTICSEARCH_API_KEY>
          mapping:
            mode: otel
      service:
        pipelines:
          profiles:
            exporters: [ elasticsearch ]
    		
  2. Install the chart with these values. The profiling preset requires chart version 0.152.1 or later. The command uses the minimum version, and you can replace it with a later one:

    helm upgrade --install profiling opentelemetry-collector \
      --repo https://open-telemetry.github.io/opentelemetry-helm-charts \
      --version 0.152.1 \
      --namespace profiling --create-namespace \
      --values profiling-values.yml
    		

A few minutes after the profiler starts, check if data is arriving:

  • In Kibana, find Infrastructure in the navigation menu and open Profiling, or use the global search field, then open Stacktraces. The Executables, Threads, Traces, and Hosts graphs show data. If your deployment also has Universal Profiling data, make sure that the schema selector below the search bar shows OpenTelemetry. For more information on how the selector picks a default and which schemas it lists, refer to Select a profiling schema.

  • In Dev Tools, count events in the OpenTelemetry profiling data streams:

    				GET /profiling-events-all.otel-*/_count
    		

    A count greater than 0 confirms that OpenTelemetry profile events have been indexed. This count includes all retained events. You can use the time picker in Stacktraces to check recent ingestion.

Profiles appear in stacktraces, flamegraphs, and functions views. To learn how to read them, refer to Profiling.

If no data arrives, refer to Troubleshoot OpenTelemetry profiling to match the symptom you see in the Elastic Agent logs or in Kibana with its fix.

OpenTelemetry profiles are stored in data streams that follow the OpenTelemetry semantic conventions:

Data Data stream
Profile events profiling-events-*.otel-default
Stack traces profiling-stacktraces.otel-default
Stack frames profiling-stackframes.otel-default
Executables profiling-executables.otel-default
Host metadata profiling-hosts.otel-default

Retention is managed with the data stream lifecycle.

Note

The Universal Profiling pages about index lifecycle management and the Storage explorer don't apply to these data streams. Any data that you might have collected with Universal Profiling is not migrated.