Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cloud Run and Functions to include profiler #27780

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nina9753
Copy link
Contributor

What does this PR do? What is the motivation?

Updates Dockerfile for Java cloud run functions and add profiler section to both Cloud Run and Cloud run Functions

Merge instructions

Merge readiness:

  • Ready for merge

Merge queue is enabled in this repo. To have it automatically merged after it receives the required reviews, create the PR (from a branch that follows the <yourname>/description naming convention) and then add the following PR comment:

/merge

Additional notes

@nina9753 nina9753 requested review from a team as code owners February 24, 2025 16:02
@domalessi domalessi self-assigned this Feb 24, 2025
Copy link
Contributor

@domalessi domalessi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback. Let me know if anything's unclear!

@@ -140,6 +156,9 @@ ENV DD_TRACE_DEBUG=true

ENTRYPOINT ["dotnet", "dotnet.dll"]
```
#### Profiling
The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and go directly to enabling the profiler. See [Enabling the .NET Profiler][5] to add the environment variables.
The Dockerfile above also has the environment variables for the profiler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Dockerfile above also has the environment variables for the profiler.
The previous Dockerfile example also has the environment variables for the profiler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2. Run `mvn clean package` to update the `target` directory with the new `.jar` used in your Dockerfile.

<div class="alert alert-info">
As an alternative to the provided Dockerfile, you can also use Artifact Registry to store the images built from your function source code. You can use <a href="#">Google Cloud Build</a> or <a href="#">Buildpacks</a> to build and deploy your image.<br/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As an alternative to the provided Dockerfile, you can also use Artifact Registry to store the images built from your function source code. You can use <a href="#">Google Cloud Build</a> or <a href="#">Buildpacks</a> to build and deploy your image.<br/>
As an alternative to the provided Dockerfile, you can use Artifact Registry to store the images built from your function source code. You can use <a href="#">Google Cloud Build</a> or <a href="#">Buildpacks</a> to build and deploy your image.<br/>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the hrefs are functioning as expected? They just bring me to the top of this page.

Comment on lines +182 to +184
Cloud Run Function code runs with a classpath that includes the function code itself and its dependencies.
The Maven plugin automatically computes the classpath based on the dependencies expressed in pom.xml.
When [invoking the Functions Framework directly](https://github.com/GoogleCloudPlatform/functions-framework-java?tab=readme-ov-file#function-classpath)with the datadog agent, you must update your dockerfile ENTRYPOINT to use `--classpath` and `--target` to indicate how to find the code and add the java option fo the datadog agent `-javaagent:dd-java-agent.jar`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cloud Run Function code runs with a classpath that includes the function code itself and its dependencies.
The Maven plugin automatically computes the classpath based on the dependencies expressed in pom.xml.
When [invoking the Functions Framework directly](https://github.com/GoogleCloudPlatform/functions-framework-java?tab=readme-ov-file#function-classpath)with the datadog agent, you must update your dockerfile ENTRYPOINT to use `--classpath` and `--target` to indicate how to find the code and add the java option fo the datadog agent `-javaagent:dd-java-agent.jar`.
Cloud Run Function code runs with a classpath that includes the function code and its dependencies. The Maven plugin automatically determines the classpath based on the dependencies in `pom.xml`.
If invoking the Functions Framework directly with the Datadog Agent, update your Dockerfile `ENTRYPOINT` to include the `--classpath` and `--target` options, along with the Java agent flag:

Comment on lines +190 to +191
- Replace `FUNCTION_JAR` with the target jar generated from the mvn step above with all dependencies.
- Replace `FUNCTION_TARGET` with Function entry point. For example, `gcfv2.HelloworldApplication`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Replace `FUNCTION_JAR` with the target jar generated from the mvn step above with all dependencies.
- Replace `FUNCTION_TARGET` with Function entry point. For example, `gcfv2.HelloworldApplication`.
- Replace `FUNCTION_JAR` with the target JAR generated from the Maven build, including all dependencies.
- Replace `FUNCTION_TARGET` with the function's entry point (for example, `gcfv2.HelloworldApplication`).

```
2. Add `dd-java-agent.jar` to your Dockerfile.
- Replace `FUNCTION_JAR` with the target jar generated from the mvn step above with all dependencies.
- Replace `FUNCTION_TARGET` with Function entry point. For example, `gcfv2.HelloworldApplication`.

**Example `Dockerfile`**:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this (all the "Example Dockerfile" content) may need to be indented if it's supposed to all fall under step 3??


```

4. Deploy the Java function by running the following command in the top level directory that contains your `pom.xml` and `Dockerfile`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. Deploy the Java function by running the following command in the top level directory that contains your `pom.xml` and `Dockerfile`:
4. To deploy the Java function, run the following command from the top-level directory containing your `pom.xml` and `Dockerfile`:

@@ -171,7 +234,10 @@ To set up logging in your application, see [Python Log Collection][3]. [Python L
- Replace `FUNCTION_NAME` with the name of your Cloud Run function.
- Ensure that you set [--clear-base-image][5] to deploy your Cloud Function with the Dockerfile.

4. When you set up your [containers](#containers), ensure that you use the same container image as what you deployed in the previous steps.
5. When you set up your [containers](#containers), ensure that you use the same container image as what you deployed in the previous steps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
5. When you set up your [containers](#containers), ensure that you use the same container image as what you deployed in the previous steps.
5. When setting up your [containers](#containers), use the same container image deployed in the previous steps.

@@ -507,17 +612,33 @@ public class HelloworldApplication implements HttpFunction {
#### Dockerfile

```dockerfile
# Download datadog java agent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Download datadog java agent
# Download Datadog Java Agent


**Example `Dockerfile`**:
```dockerfile
FROM openjdk:17-jdk
# Download datadog java agent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Download datadog java agent
# Download Datadog Java Agent

@@ -26,6 +26,9 @@ In your main application, add the `dd-trace-js` library. See [Tracing Node.js ap

Set `ENV NODE_OPTIONS="--require dd-trace/init"`. This specifies that the `dd-trace/init` module is required when the Node.js process starts.

#### Profiling
The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and go directly to enabling the profiler. See [Enabling the Node.js Profiler][5] to add the environment variables.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and go directly to enabling the profiler. See [Enabling the Node.js Profiler][5] to add the environment variables.
The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and proceed to enabling the profiler. See [Enabling the Node.js Profiler][5] to add the environment variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"proceed to" is a bit clearer and more professional than "go directly to". Not a huge deal, but I'd recommend updating all the text to follow suit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants