

# Profile your application

To send data to Amazon CloudWatch Profiles, use a profiler that produces data in OpenTelemetry Protocol (OTLP) format. CloudWatch doesn't own most of the tools described here, so this page summarizes each option and links to its documentation.

If you send through the CloudWatch agent, turn on its OTLP endpoint first. For more information, see [Use the CloudWatch agent](CloudWatch-Profiles-publish-emit.md#CloudWatch-Profiles-publish-agent-config).

**Note**  
On Kubernetes, the CloudWatch Observability EKS add-on and the `amazon-cloudwatch-observability` Helm chart turn on the profiler in your Java workloads and send the profiles to CloudWatch for you. For more information, see [Profile Java workloads on Kubernetes](CloudWatch-Profiles-getting-started-kubernetes.md).

To send the data to CloudWatch, see [Send profiles to CloudWatch](CloudWatch-Profiles-publish-emit.md).

Use one of the following options:
+ **async-profiler** – A low-overhead sampling profiler for Java. Version 4.6 and later send OTLP over HTTP when the output file name is an `http://` or `https://` URL. Sending needs libcurl on the host or in the application's container. With OTLP output, async-profiler records one event at a time. We recommend `event=itimer`. It stores the profile type `process_itimer:itimer:count:itimer:ns` on any host. For configuration, see the [async-profiler](https://github.com/async-profiler/async-profiler) repository on the GitHub website.

  Start your application with `OTEL_SERVICE_NAME` set, or with the `otel.service.name` system property, because async-profiler reads the service name from the profiled JVM. Then run the following command against the running process.

  ```bash
  asprof -e itimer --loop 60s -f http://localhost:4318/v1development/profiles {{pid}}
  ```
  + `{{pid}}` – The process ID of your running Java application.
+ **OpenTelemetry eBPF profiler** – Samples the stacks of every process on a Linux host from the kernel, without changes to your applications. By default, it samples on-CPU time. You can run it yourself for applications in languages other than Java. It runs as the `profiling` receiver in the `otelcol-ebpf-profiler` OpenTelemetry Collector distribution. It doesn't sign requests, so export its data to the CloudWatch agent or an OpenTelemetry Collector.

  The profiler runs with elevated privileges and can read the memory and environment of every process on the host. Run it only on hosts that you control. CloudWatch rejects a profile with more than 16,000 samples, so don't raise the `reporter_interval` of the receiver. If a process has no `service.name`, the CloudWatch agent stores its profiles under `unknown_service`. The [opentelemetry-ebpf-profiler](https://github.com/open-telemetry/opentelemetry-ebpf-profiler) repository on the GitHub website describes setup, required privileges, supported runtimes, and the supported Collector distribution to deploy.

  For example, save the following configuration as `config.yaml`. It sends the profiles to the CloudWatch agent on the same host.

  ```yaml
  receivers:
    profiling: {}
  exporters:
    otlp_http:
      profiles_endpoint: http://localhost:4318/v1development/profiles
  service:
    pipelines:
      profiles:
        receivers: [profiling]
        exporters: [otlp_http]
  ```

  Start the Collector with the profiles feature gate:

  ```bash
  sudo ./otelcol-ebpf-profiler --config config.yaml --feature-gates=+service.profilesSupport
  ```
+ **ADOT Java agent** – Version 2.32.0 and later of the AWS Distro for OpenTelemetry (ADOT) Java agent embed async-profiler for HotSpot Java virtual machines (JVMs) on Linux, on x86\_64 and arm64. The profiler is off by default. To download the agent, see the [aws-otel-java-instrumentation releases](https://github.com/aws-observability/aws-otel-java-instrumentation/releases) on the GitHub website.

  To turn it on, set the following environment variables when you start your application. Replace `{{my-service}}` with your service name and `{{my-app.jar}}` with the path to your application JAR file.

  ```bash
  OTEL_AWS_PROFILER_ENABLED=true \
  OTEL_SERVICE_NAME={{my-service}} \
  java -javaagent:/opt/aws-opentelemetry-agent/aws-opentelemetry-agent.jar -jar {{my-app.jar}}
  ```

  You can also set the following variables:
  + `OTEL_AWS_PROFILER_MODE` – Sets the profiling mode. `wall` (default) samples threads on and off the CPU. `cpu` samples only threads running on the CPU.
  + `OTEL_AWS_PROFILER_MEMORY_ENABLED` – Turns on memory allocation profiling when set to `true`. The default is `false`. The CloudWatch Observability EKS add-on and the Helm chart set it to `true`.
  + `OTEL_AWS_PROFILER_WINDOW_SECONDS` – Sets the length of each profile, in seconds. The default is `60`.
  + `OTEL_AWS_PROFILER_ENDPOINT` – Sets where the agent sends profiles, used as given. If unset, the agent uses `OTEL_EXPORTER_OTLP_ENDPOINT`, with `/v1development/profiles` appended for OTLP/HTTP. If neither is set, it uses `http://localhost:4318/v1development/profiles` for OTLP/HTTP, or `http://localhost:4317` when `OTEL_EXPORTER_OTLP_PROTOCOL=grpc`. The default OTLP/HTTP endpoint is the default endpoint of the CloudWatch agent.
+ **Build your own** – Any client can send profiles if it produces OTLP profile data in development version `1`. It must also either sign its requests or send them through the CloudWatch agent or a Collector. For more information about authentication, see [Send directly to the endpoint](CloudWatch-Profiles-publish-emit.md#CloudWatch-Profiles-publish-direct). For more information about the data format, see the [OpenTelemetry profiles protocol](https://github.com/open-telemetry/opentelemetry-proto/tree/main/opentelemetry/proto/profiles) on the GitHub website. For more information about the version that CloudWatch accepts, see [Supported profile format version](CloudWatch-Profiles-publish.md#CloudWatch-Profiles-publish-version).