Tracing
In your main application, add the dd-trace-js
library. See Tracing Node.js applications for instructions.
Set ENV NODE_OPTIONS="--require dd-trace/init"
. This specifies that the dd-trace/init
module is required when the Node.js process starts.
Metrics
The tracing library also collects custom metrics. See the code examples.
Logs
The Datadog sidecar collects logs through a shared volume. To forward logs from your main container to the sidecar, configure your application to write all logs to a location such as shared-volume/logs/*.log
using the steps below. You must follow the setup in the GCP UI to add the environment variable DD_SERVERLESS_LOG_PATH
and a shared Volume Mount to both the main and sidecar container.
To set up logging in your application, see Node.js Log Collection. To set up trace log correlation, see Correlating Node.js Logs and Traces.
Tracing
Add dd-java-agent.jar
and other dependencies like java-dogstatsd-client
to your pom.xml
.
Example pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gcfv2</groupId>
<artifactId>helloworld</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencies>
<!-- Required for Function primitives -->
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!--
Google Cloud Functions Framework Maven plugin
This plugin allows you to run Cloud Functions Java code
locally. Use the following terminal command to run a
given function locally:
mvn function:run -Drun.functionTarget=your.package.yourFunction
-->
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.11.0</version>
<configuration>
<functionTarget>functions.HelloWorld</functionTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<get src="https://dtdg.co/latest-java-tracer" dest="dd-java-agent.jar" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Add dd-java-agent.jar
to your Dockerfile.
Example Dockerfile
:
FROM openjdk:17-jdk
# Set the working directory in the container
WORKDIR /
ADD 'https://dtdg.co/latest-java-tracer' dd-java-agent.jar
# Copy the JAR file into the container
COPY target/helloworld-0.0.1-SNAPSHOT.jar helloworld.jar
ENV JAVA_OPTS=-javaagent:dd-java-agent.jar
CMD ["java", "-javaagent:dd-java-agent.jar", "-jar", "helloworld.jar"]
Run mvn clean package
to update the target
directory with the new .jar
used in your Dockerfile.
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
Google Cloud Build or
Buildpacks to build and deploy your image.
For example:
gcloud builds submit --pack image=LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/IMAGE_NAME
Deploy the Java function by running the following command in the top level directory that contains your pom.xml
and Dockerfile
:
gcloud beta run deploy FUNCTION_NAME \
--source . \
--function FUNCTION_TARGET \
--clear-base-image \
--region REGION
- Replace
REGION
with the region where you want to deploy the function. - Replace
FUNCTION_TARGET
with your function entry point. For example, gcfv2.HelloworldApplication
. - Replace
FUNCTION_NAME
with the name of your Cloud Run function. - Ensure that you set –clear-base-image to deploy your Cloud Function with the Dockerfile.
When you set up your containers, ensure that you use the same container image as what you deployed in the previous steps.
Metrics
To collect custom metrics, install the Java DogStatsD client.
Logs
The Datadog sidecar collects logs through a shared volume. To forward logs from your main container to the sidecar, configure your application to write all logs to a location such as shared-volume/logs/*.log
using the steps below. You must follow the setup in the GCP UI to add the environment variable DD_SERVERLESS_LOG_PATH
and a shared Volume Mount to both the main and sidecar container.
To set up logging in your application, see Java Log Collection. To set up trace log correlation, see Correlating Java Logs and Traces.
Tracing
In your main application, add the dd-trace-go
library. See Tracing Go Applications for instructions.
Metrics
The tracing library also collects custom metrics. See the code examples.
Logs
The Datadog sidecar collects logs through a shared volume. To forward logs from your main container to the sidecar, configure your application to write all logs to a location such as shared-volume/logs/*.log
using the steps below. You must follow the setup in the GCP UI to add the environment variable DD_SERVERLESS_LOG_PATH
and a shared Volume Mount to both the main and sidecar container.
To set up logging in your application, see Go Log Collection. To set up trace log correlation, see Correlating Go Logs and Traces.
Tracing
In your main application, add the .NET tracing library. See Tracing .NET Applications for instructions.
Metrics
The tracing library also collects custom metrics. See the code examples.
Logs
The Datadog sidecar collects logs through a shared volume. To forward logs from your main container to the sidecar, configure your application to write all logs to a location such as shared-volume/logs/*.log
using the steps below. You must follow the setup in the GCP UI to add the environment variable DD_SERVERLESS_LOG_PATH
and a shared Volume Mount to both the main and sidecar container.
To set up logging in your application, see C# Log Collection. To set up trace log correlation, see Correlating .NET Logs and Traces.