---
title: Enabling the Go Profiler
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > Continuous Profiler > Enabling the Profiler > Enabling the Go Profiler
---

# Enabling the Go Profiler

The profiler is shipped within Datadog tracing libraries. If you are already using [APM to collect traces](https://docs.datadoghq.com/tracing/trace_collection/) for your application, you can skip installing the library and go directly to enabling the profiler.

## Requirements{% #requirements %}

For a summary of the minimum and recommended runtime and tracer versions across all languages, read [Supported Language and Tracer Versions](https://docs.datadoghq.com/profiler/enabling/supported_versions/).

The Datadog Profiler requires one of the latest two major Go releases. These are the major Go releases [supported by the Go project](https://go.dev/doc/devel/release).

For the [Trace to Profiling integration](https://docs.datadoghq.com/profiler/connect_traces_and_profiles/#identify-code-hotspots-in-slow-traces) and [Endpoint Profiling](https://docs.datadoghq.com/profiler/connect_traces_and_profiles/#break-down-code-performance-by-api-endpoints), use `dd-trace-go` version 1.51.0+.

Continuous Profiler is not supported on some serverless platforms, such as AWS Lambda.

## Installation{% #installation %}

To begin profiling applications:

1. Ensure Datadog Agent v6+ is installed and running. Datadog recommends using [Datadog Agent v7+](https://app.datadoghq.com/account/settings/agent/latest?platform=overview).

1. Get `dd-trace-go` using the command:

   ```shell
   go get github.com/DataDog/dd-trace-go/v2/profiler
   ```
Important alert (level: info): If you are using v1 of the Go tracer, see the [migration guide](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/go/migration) to upgrade to v2 and for all future updates and features.
1. Import the [profiler](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/profiler#pkg-constants) at the start of your application:

   ```go
   import "github.com/DataDog/dd-trace-go/v2/profiler"
   ```

1. Add the following snippet to start the profiler:

   ```Go
   err := profiler.Start(
       profiler.WithService("<SERVICE_NAME>"),
       profiler.WithEnv("<ENVIRONMENT>"),
       profiler.WithVersion("<APPLICATION_VERSION>"),
       profiler.WithTags("<KEY1>:<VALUE1>", "<KEY2>:<VALUE2>"),
       profiler.WithProfileTypes(
         profiler.CPUProfile,
         profiler.HeapProfile,
         // The profiles below are disabled by default to keep overhead
         // low, but can be enabled as needed.
   
         // profiler.BlockProfile,
         // profiler.MutexProfile,
         // profiler.GoroutineProfile,
       ),
   )
   if err != nil {
       log.Fatal(err)
   }
   defer profiler.Stop()
   ```

1. Optional: Enable the [timeline feature](https://docs.datadoghq.com/profiler/connect_traces_and_profiles/#span-execution-timeline-view), see [prerequisites](https://docs.datadoghq.com/profiler/connect_traces_and_profiles/#prerequisites).

1. Optional: Set up [Source Code Integration](https://docs.datadoghq.com/integrations/guide/source-code-integration/?tab=go) to connect your profiling data with your Git repositories.

1. A couple of minutes after you start your application, your profiles appear on the [Datadog APM > Profiler page](https://app.datadoghq.com/profiling). If they do not, refer to the [Troubleshooting](https://docs.datadoghq.com/profiler/profiler_troubleshooting/go/) guide.

**Note**: By default, only the CPU and Heap profiles are enabled. Use [profiler.WithProfileTypes](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/profiler#WithProfileTypes) and [profile types](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/profiler#ProfileType). For legacy v1 documentation, view [profiler.WithProfileTypes](https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/profiler#WithProfileTypes) to enable additional [profile types](https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/profiler#ProfileType).

If you automatically instrument your Go application with [Orchestrion](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/go), it adds the continuous profiler code to your application. To enable the profiler at run time, set the environment variable `DD_PROFILING_ENABLED=true`.

## Configuration{% #configuration %}

You can set profiler parameters in code with these functions:

| Function    | Type            | Description                                                                                                                         |
| ----------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| WithService | String          | The Datadog [service](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) name, for example, `my-web-app`.  |
| WithEnv     | String          | The Datadog [environment](https://pkg.go.dev/github.com/ianlancetaylor/cgosymbolizer#pkg-overview) name, for example, `production`. |
| WithVersion | String          | The version of your application.                                                                                                    |
| WithTags    | List of strings | A list of tags to apply to an uploaded profile. Tags must be of the format `<KEY>:<VALUE>`.                                         |

Alternatively you can set profiler configuration using environment variables:

| Environment variable | Type   | Description                                                                                                                    |
| -------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `DD_ENV`             | String | The [environment](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) name, for example, `production`. |
| `DD_SERVICE`         | String | The [service](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) name, for example, `web-backend`.    |
| `DD_VERSION`         | String | The [version](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) of your service.                     |
| `DD_TAGS`            | String | Tags to apply to an uploaded profile. Must be a list of `<key>:<value>` separated by commas such as: `layer:api,team:intake`.  |

### Showing C function calls in CPU profiles{% #showing-c-function-calls-in-cpu-profiles %}

By default, Go's CPU profiler only shows detailed information for Go code. If your program calls C code, the time spent running C code is reflected in the profile, but the call stacks only show Go function calls.

To add detailed C function call information to CPU profiles, you may opt to use library such as [ianlancetaylor/cgosymbolizer](https://pkg.go.dev/github.com/ianlancetaylor/cgosymbolizer#pkg-overview). To use this library:

1. Download the package:

   ```shell
   go get github.com/ianlancetaylor/cgosymbolizer@latest
   ```

1. Add the following import anywhere in your program:

   ```Go
   import _ "github.com/ianlancetaylor/cgosymbolizer"
   ```

**Note**: This library is considered experimental. It can cause (infrequent) deadlocks in programs that use C++ exceptions, or that use libraries such as `tcmalloc`, which also collect call stacks.

## Save up to 14% CPU in production with PGO{% #save-up-to-14-cpu-in-production-with-pgo %}

Starting [Go 1.21](https://tip.golang.org/doc/go1.21), the Go compiler supports Profile-Guided Optimization (PGO). PGO enables additional optimizations on code identified as hot by CPU profiles of production workloads. This is compatible with Datadog Go Continuous Profiler and can be used for production builds.

Follow [this guide](https://docs.datadoghq.com/profiler/guide/save-cpu-in-production-with-go-pgo) to set it up.

## Not sure what to do next?{% #not-sure-what-to-do-next %}

The [Getting Started with Profiler](https://docs.datadoghq.com/getting_started/profiler/) guide takes a sample service with a performance problem and shows you how to use Continuous Profiler to understand and fix the problem.

## Further Reading{% #further-reading %}

- [Getting Started with Profiler](https://docs.datadoghq.com/getting_started/profiler)
- [Learn more about available profile visualizations](https://docs.datadoghq.com/profiler/profile_visualizations)
- [Fix problems you encounter while using the profiler](https://docs.datadoghq.com/profiler/profiler_troubleshooting/go)
