Skip to content

Commit 3b28600

Browse files
committed
cleanup nodejs page; fix links
1 parent a92a866 commit 3b28600

File tree

9 files changed

+115
-61
lines changed

9 files changed

+115
-61
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: Instrumenting a Node.js Cloud Run Container In-Process
3+
further_reading:
4+
- link: '/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#getting-started'
5+
tag: 'Documentation'
6+
text: 'Tracing Node.js Applications'
7+
---
8+
9+
## 1. Install the Tracer
10+
11+
In your main application, add the `dd-trace-js` library.
12+
13+
```shell
14+
npm install dd-trace --save
15+
```
16+
17+
Then, add this to your application code to initialize the tracer:
18+
```javascript
19+
const tracer = require('dd-trace').init({
20+
logInjection: true,
21+
});
22+
```
23+
24+
For more information, see [Tracing Node.js applications](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#getting-started).
25+
26+
## 2. Install Serverless-Init
27+
28+
Add the following instructions and arguments to your Dockerfile.
29+
30+
```dockerfile
31+
COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
32+
ENV NODE_OPTIONS="--require dd-trace/init"
33+
ENV DD_SERVICE=datadog-demo-run-nodejs
34+
ENV DD_ENV=datadog-demo
35+
ENV DD_VERSION=1
36+
ENTRYPOINT ["/app/datadog-init"]
37+
CMD ["/nodejs/bin/node", "/path/to/your/app.js"]
38+
```
39+
40+
#### Explanation
41+
42+
1. Copy the Datadog `serverless-init` into your Docker image.
43+
44+
```dockerfile
45+
COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
46+
```
47+
48+
2. Specify that the `dd-trace/init` module is required when the Node.js process starts.
49+
50+
```dockerfile
51+
ENV NODE_OPTIONS="--require dd-trace/init"
52+
```
53+
54+
3. (Optional) Add Datadog tags.
55+
56+
```dockerfile
57+
ENV DD_SERVICE=datadog-demo-run-nodejs
58+
ENV DD_ENV=datadog-demo
59+
ENV DD_VERSION=1
60+
```
61+
62+
4. Change the entrypoint to wrap your application in the Datadog `serverless-init` process.
63+
**Note**: If you already have an entrypoint defined inside your Dockerfile, see the [alternative configuration](#alt-node).
64+
65+
```dockerfile
66+
ENTRYPOINT ["/app/datadog-init"]
67+
```
68+
69+
5. Execute your binary application wrapped in the entrypoint. Adapt this line to your needs.
70+
```dockerfile
71+
CMD ["node", "/path/to/your/app.js"]
72+
```
73+
74+
#### Alternative configuration {#alt-node}
75+
If you already have an entrypoint defined inside your Dockerfile, you can instead modify the CMD argument.
76+
77+
```dockerfile
78+
COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
79+
RUN npm install --prefix /dd_tracer/node dd-trace --save
80+
ENV DD_SERVICE=datadog-demo-run-nodejs
81+
ENV DD_ENV=datadog-demo
82+
ENV DD_VERSION=1
83+
CMD ["/app/datadog-init", "/nodejs/bin/node", "/path/to/your/app.js"]
84+
```
85+
86+
## 3. Setup Logs
87+
88+
To enable logging, set the environment variable `DD_LOGS_ENABLED=true`. This allows serverless-init to read logs from stdout and stderr.
89+
90+
If you want multiline logs to be preserved in a single log message, we recommend writing your logs in JSON format. For example:
91+
```javascript
92+
const tracer = require('dd-trace').init({
93+
logInjection: true,
94+
});
95+
const { createLogger, format, transports } = require('winston');
96+
97+
const logger = createLogger({
98+
level: 'info',
99+
exitOnError: false,
100+
format: format.json(),
101+
transports: [
102+
new transports.File({ filename: `/shared-volume/logs/app.log` }),
103+
new transports.Console()
104+
],
105+
});
106+
107+
logger.info(`Hello world!`);
108+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.

content/en/serverless/google_cloud_run/in_process/nodejs.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

layouts/partials/serverless/in-process-languages.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,50 @@
33
<div class="container cards-dd col-num-3">
44
<div class="row row-cols-2 row-cols-md-4 g-2 g-xl-3 justify-content-sm-center">
55
<div class="col">
6-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/python/">
6+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/python/">
77
<div class="card-body text-center py-2 px-1">
88
{{ partial "img.html" (dict "root" . "src" "integrations_logos/python.png" "class" "img-fluid" "alt" "Python" "width" "400") }}
99
</div>
1010
</a>
1111
</div>
1212
<div class="col">
13-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/nodejs/">
13+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/nodejs/">
1414
<div class="card-body text-center py-2 px-1">
1515
{{ partial "img.html" (dict "root" . "src" "integrations_logos/nodejs.png" "class" "img-fluid" "alt" "Node.js" "width" "400") }}
1616
</div>
1717
</a>
1818
</div>
1919
<div class="col">
20-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/go/">
20+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/go/">
2121
<div class="card-body text-center py-2 px-1">
2222
{{ partial "img.html" (dict "root" . "src" "integrations_logos/go-metro.png" "class" "img-fluid" "alt" "go" "width" "400") }}
2323
</div>
2424
</a>
2525
</div>
2626
<div class="w-100 d-none d-md-block"></div>
2727
<div class="col">
28-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/java/">
28+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/java/">
2929
<div class="card-body text-center py-2 px-1">
3030
{{ partial "img.html" (dict "root" . "src" "integrations_logos/java.png" "class" "img-fluid" "alt" "Java" "width" "400") }}
3131
</div>
3232
</a>
3333
</div>
3434
<div class="col">
35-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/ruby/">
35+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/ruby/">
3636
<div class="card-body text-center py-2 px-1">
3737
{{ partial "img.html" (dict "root" . "src" "integrations_logos/ruby.png" "class" "img-fluid" "alt" "Ruby" "width" "400") }}
3838
</div>
3939
</a>
4040
</div>
4141
<div class="col">
42-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/dotnet/">
42+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/dotnet/">
4343
<div class="card-body text-center py-2 px-1">
4444
{{ partial "img.html" (dict "root" . "src" "integrations_logos/dotnet_text.png" "class" "img-fluid" "alt" ".NET" "width" "400") }}
4545
</div>
4646
</a>
4747
</div>
4848
<div class="col">
49-
<a class="card h-100" href="/serverless/google_cloud_run/containers/in_process/php/">
49+
<a class="card h-100" href="/serverless/google_cloud_run/container_in_process/php/">
5050
<div class="card-body text-center py-2 px-1">
5151
{{ partial "img.html" (dict "root" . "src" "integrations_logos/php.png" "class" "img-fluid" "alt" "PHP" "width" "400") }}
5252
</div>

0 commit comments

Comments
 (0)