|
1 | 1 | ---
|
2 | 2 | title: Instrumenting Google Cloud Run Containers In-Process
|
3 |
| -further_reading: |
4 |
| - |
5 |
| -- link: 'https://www.datadoghq.com/blog/collect-traces-logs-from-cloud-run-with-datadog/' |
6 |
| - tag: 'Blog' |
7 |
| - text: 'Collect traces, logs, and custom metrics from Cloud Run services' |
8 |
| - |
9 |
| ---- |
10 |
| - |
11 |
| -## Overview |
12 |
| - |
13 |
| -Google Cloud Run is a fully managed serverless platform for deploying and scaling container-based applications. |
14 |
| - |
15 |
| -This page provides instructions for instrumenting your Google Cloud Run containers with the Datadog Agent, which enables tracing, custom metrics, and direct log collection. |
16 |
| - |
17 |
| -<div class="alert alert-info">To instrument your Google Cloud Run applications with the Datadog Agent running in a sidecar, see <a href="/serverless/google_cloud_run/containers">Instrument Google Cloud Run with Sidecar</a>.</div> |
18 |
| - |
19 |
| -<div class="alert alert-info"> |
20 |
| -<strong>Have you set up your <a href="/integrations/google-cloud-platform/">Google Cloud integration</a>?</strong> Datadog recommends setting up the integration, which collects metrics and logs from Google Cloud services, before proceeding on to instrumentation. Remember to add the <code>cloud asset viewer</code> role to your service account and enable the Cloud Asset Inventory API in Google Cloud. |
21 |
| -</div> |
22 |
| - |
23 |
| -### Prerequisites |
24 |
| - |
25 |
| -Make sure you have a [Datadog API key][7] and are using a programming language [supported by a Datadog tracing library][2]. |
26 |
| - |
27 |
| -## Instrument your application |
28 |
| - |
29 |
| -Datadog publishes new releases of the `serverless-init` container image to Google’s gcr.io, AWS’s ECR, and on Docker Hub: |
30 |
| - |
31 |
| -| dockerhub.io | gcr.io | public.ecr.aws | |
32 |
| -| ------------ | ------ | -------------- | |
33 |
| -| datadog/serverless-init | gcr.io/datadoghq/serverless-init | public.ecr.aws/datadog/serverless-init | |
34 |
| - |
35 |
| -Images are tagged based on semantic versioning, with each new version receiving three relevant tags: |
36 |
| - |
37 |
| -* `1`, `1-alpine`: use these to track the latest minor releases, without breaking changes |
38 |
| -* `1.x.x`, `1.x.x-alpine`: use these to pin to a precise version of the library |
39 |
| -* `latest`, `latest-alpine`: use these to follow the latest version release, which may include breaking changes |
40 |
| - |
41 |
| -## How `serverless-init` works |
42 |
| - |
43 |
| -The `serverless-init` application wraps your process and executes it as a subprocess. It starts a DogStatsD listener for metrics and a Trace Agent listener for traces. It collects logs by wrapping the stdout/stderr streams of your application. After bootstrapping, serverless-init then launches your command as a subprocess. |
44 |
| - |
45 |
| -To get full instrumentation, ensure you are calling `datadog-init` as the first command that runs inside your Docker container. You can do this through by setting it as the entrypoint, or by setting it as the first argument in CMD. |
46 |
| - |
47 |
| -{{< programming-lang-wrapper langs="nodejs,python,java,go,dotnet,ruby,php" >}} |
48 |
| -{{< programming-lang lang="nodejs" >}} |
49 |
| - |
50 |
| -{{% svl-init-nodejs %}} |
51 |
| - |
52 |
| -{{< /programming-lang >}} |
53 |
| -{{< programming-lang lang="python" >}} |
54 |
| - |
55 |
| -{{% svl-init-python %}} |
56 |
| - |
57 |
| -{{< /programming-lang >}} |
58 |
| -{{< programming-lang lang="java" >}} |
59 |
| - |
60 |
| -{{% svl-init-java %}} |
61 |
| - |
62 |
| -{{< /programming-lang >}} |
63 |
| -{{< programming-lang lang="go" >}} |
64 |
| - |
65 |
| -{{% svl-init-go %}} |
66 |
| - |
67 |
| -{{< /programming-lang >}} |
68 |
| -{{< programming-lang lang="dotnet" >}} |
69 |
| - |
70 |
| -{{% svl-init-dotnet %}} |
71 |
| - |
72 |
| -{{< /programming-lang >}} |
73 |
| -{{< programming-lang lang="ruby" >}} |
74 |
| - |
75 |
| -{{% svl-init-ruby %}} |
76 |
| - |
77 |
| -{{< /programming-lang >}} |
78 |
| -{{< programming-lang lang="php" >}} |
79 |
| - |
80 |
| -{{% svl-init-php %}} |
81 |
| - |
82 |
| -{{< /programming-lang >}} |
83 |
| -{{< /programming-lang-wrapper >}} |
84 |
| - |
85 |
| -### Buildpack |
86 |
| - |
87 |
| -<div class="alert alert-info">Buildpack instrumentation is deprecated.</div> |
88 |
| - |
89 |
| -[`Pack Buildpacks`][3] provide a convenient way to package your container without using a Dockerfile. |
90 |
| - |
91 |
| -First, manually install your tracer: |
92 |
| -- [Node.JS][14] |
93 |
| -- [Python][13] |
94 |
| -- [Java][15] |
95 |
| -- [Go][12] |
96 |
| -- [.NET][18] |
97 |
| -- [Ruby][16] |
98 |
| -- [PHP][17] |
99 |
| - |
100 |
| -Then, build your application by running the following command: |
101 |
| - |
102 |
| -```shell |
103 |
| -pack build --builder=gcr.io/buildpacks/builder \ |
104 |
| ---buildpack from=builder \ |
105 |
| ---buildpack datadog/serverless-buildpack:latest \ |
106 |
| -gcr.io/<YOUR_PROJECT>/<YOUR_APP_NAME> |
107 |
| -``` |
108 |
| - |
109 |
| -**Note**: Buildpack instrumentation is not compatible with Alpine images. |
110 |
| - |
111 |
| -## Configure your application |
112 |
| - |
113 |
| -After the container is built and pushed to your registry, set the required environment variables for the Datadog Agent: |
114 |
| -- `DD_API_KEY`: Datadog API key, used to send data to your Datadog account. It should be configured as a [Google Cloud Secret][11] for privacy and safety. |
115 |
| -- `DD_SITE`: Datadog endpoint and website. Select your site on the right side of this page. Your site is: {{< region-param key="dd_site" code="true" >}}. |
116 |
| - |
117 |
| -For more environment variables and their function, see [Environment Variables](#environment-variables). |
118 |
| - |
119 |
| -The following command deploys the service and allows any external connection to reach it. In this example, your service listening is set to port 8080. Ensure that this port number matches the exposed port inside of your Dockerfile. |
120 |
| - |
121 |
| -``` |
122 |
| -shell |
123 |
| -gcloud run deploy <APP_NAME> --image=gcr.io/<YOUR_PROJECT>/<APP_NAME> \ |
124 |
| - --port=8080 \ |
125 |
| - --update-env-vars=DD_API_KEY=$DD_API_KEY \ |
126 |
| - --update-env-vars=DD_SITE=$DD_SITE \ |
127 |
| -``` |
128 |
| - |
129 |
| -See [all arguments and flags for `gcloud run deploy`][26]. |
130 |
| - |
131 |
| -## Results |
132 |
| - |
133 |
| -After the deployment is completed, your metrics and traces are sent to Datadog. In Datadog, navigate to **Infrastructure > Serverless** to see your serverless metrics and traces. |
134 |
| - |
135 |
| -## Additional configurations |
136 |
| - |
137 |
| -- **Advanced tracing:** The Datadog Agent already provides some basic tracing for popular frameworks. Follow the [advanced tracing guide][2] for more information. |
138 |
| - |
139 |
| -- **Logs:** If you use the [Google Cloud integration][1], your logs are already being collected. Alternatively, you can set the `DD_LOGS_ENABLED` environment variable to `true` to capture application logs through the serverless instrumentation directly. |
140 |
| - |
141 |
| -- **Custom metrics:** You can submit custom metrics using a [DogStatsD client][4]. For monitoring Cloud Run and other serverless applications, use [distribution][9] metrics. Distributions provide `avg`, `sum`, `max`, `min`, and `count` aggregations by default. On the Metric Summary page, you can enable percentile aggregations (p50, p75, p90, p95, p99) and also manage tags. To monitor a distribution for a gauge metric type, use `avg` for both the [time and space aggregations][11]. To monitor a distribution for a count metric type, use `sum` for both the time and space aggregations. |
142 |
| - |
143 |
| -### Environment variables |
144 |
| - |
145 |
| -| Variable | Description | |
146 |
| -| -------- | ----------- | |
147 |
| -|`DD_API_KEY`| [Datadog API key][7] - **Required**| |
148 |
| -| `DD_SITE` | [Datadog site][5] - **Required** | |
149 |
| -| `DD_LOGS_ENABLED` | When true, send logs (stdout and stderr) to Datadog. Defaults to false. | |
150 |
| -| `DD_LOGS_INJECTION`| When true, enrich all logs with trace data for supported loggers in [Java][19], [Node][20], [.NET][21], and [PHP][22]. See additional docs for [Python][23], [Go][24], and [Ruby][25]. | |
151 |
| -| `DD_SERVICE` | See [Unified Service Tagging][6]. | |
152 |
| -| `DD_VERSION` | See [Unified Service Tagging][6]. | |
153 |
| -| `DD_ENV` | See [Unified Service Tagging][6]. | |
154 |
| -| `DD_SOURCE` | See [Unified Service Tagging][6]. | |
155 |
| -| `DD_TAGS` | See [Unified Service Tagging][6]. | |
156 |
| - |
157 |
| -## Troubleshooting |
158 |
| - |
159 |
| -This integration depends on your runtime having a full SSL implementation. If you are using a slim image, you may need to add the following command to your Dockerfile to include certificates. |
160 |
| - |
161 |
| -``` |
162 |
| -RUN apt-get update && apt-get install -y ca-certificates |
163 |
| -``` |
164 |
| - |
165 |
| -## Further reading |
166 |
| - |
167 |
| -{{< partial name="whats-next/whats-next.html" >}} |
168 |
| - |
169 |
| - |
170 |
| -[1]: /integrations/google_cloud_platform/#log-collection |
171 |
| -[2]: /tracing/trace_collection/#for-setup-instructions-select-your-language |
172 |
| -[3]: https://buildpacks.io/docs/tools/pack/ |
173 |
| -[4]: /metrics/custom_metrics/dogstatsd_metrics_submission/ |
174 |
| -[5]: /getting_started/site/ |
175 |
| -[6]: /getting_started/tagging/unified_service_tagging/ |
176 |
| -[7]: /account_management/api-app-keys/#api-keys |
177 |
| -[8]: https://github.com/DataDog/crpb/tree/main |
178 |
| -[9]: /metrics/distributions/ |
179 |
| -[10]: /metrics/#time-and-space-aggregation |
180 |
| -[11]: https://cloud.google.com/run/docs/configuring/secrets |
181 |
| -[12]: /tracing/trace_collection/library_config/go/ |
182 |
| -[13]: /tracing/trace_collection/dd_libraries/python/?tab=containers#instrument-your-application |
183 |
| -[14]: /tracing/trace_collection/dd_libraries/nodejs/?tab=containers#instrument-your-application |
184 |
| -[15]: /tracing/trace_collection/dd_libraries/java/?tab=containers#instrument-your-application |
185 |
| -[16]: /tracing/trace_collection/dd_libraries/ruby/?tab=containers#instrument-your-application |
186 |
| -[17]: /tracing/trace_collection/dd_libraries/php/?tab=containers#install-the-extension |
187 |
| -[18]: /tracing/trace_collection/dd_libraries/dotnet-core/?tab=linux#custom-instrumentation |
188 |
| -[19]: /tracing/other_telemetry/connect_logs_and_traces/java/?tab=log4j2 |
189 |
| -[20]: /tracing/other_telemetry/connect_logs_and_traces/nodejs |
190 |
| -[21]: /tracing/other_telemetry/connect_logs_and_traces/dotnet?tab=serilog |
191 |
| -[22]: /tracing/other_telemetry/connect_logs_and_traces/php |
192 |
| -[23]: /tracing/other_telemetry/connect_logs_and_traces/python |
193 |
| -[24]: /tracing/other_telemetry/connect_logs_and_traces/go |
194 |
| -[25]: /tracing/other_telemetry/connect_logs_and_traces/ruby |
195 |
| -[26]: https://cloud.google.com/sdk/gcloud/reference/run/deploy |
| 3 | +type: multi-code-lang |
| 4 | +--- |
0 commit comments