Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 489d8c5

Browse files
OrGeva10gitbook-bot
authored andcommitted
GitBook: [#159] add NestJS instructions
1 parent de48ec9 commit 489d8c5

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

SUMMARY.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
* [How Do You Want to Send Your Data?](send-tracing-data-to-aspecto/send-tracing-data-to-aspecto.md)
1414
* [Using Aspecto SDK](send-tracing-data-to-aspecto/aspecto-sdk/README.md)
1515
* [NodeJS](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/README.md)
16-
* [For AWS Lambda](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/lambda.md)
17-
* [For GCF](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/gcf.md)
16+
* [NestJS](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/nestjs.md)
17+
* [AWS Lambda](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/lambda.md)
18+
* [Google Cloud Functions](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/gcf.md)
1819
* [Customize Defaults](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/customize-defaults/README.md)
1920
* [Advanced](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/customize-defaults/advanced.md)
2021
* [Send Spans Manually](send-tracing-data-to-aspecto/aspecto-sdk/nodejs/customize-defaults/manual-spans.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
description: Instrument your NestJS application using Aspecto
3+
---
4+
5+
# NestJS
6+
7+
## Auto Instrument
8+
9+
Nest applications are commonly started in one of 2 ways:
10+
11+
* Nest cli (`nest start`)
12+
* Directly with the `node` executable (for example: `node dist/main`)
13+
14+
It is recommended to use ["Auto Instrument" technique](./#auto-instrument) with node's "preload" command line option, to ensure instrumentation is initialized before Nest framework.
15+
16+
### Using Nest Cli
17+
18+
To instrument your Nest application when started with Nest cli, add the ["-e" ("--exec")](https://docs.nestjs.com/cli/usages#nest-start) option to `nest start` like this:
19+
20+
```
21+
nest start -e 'node -r @aspecto/opentelemetry/auto-instrument'
22+
```
23+
24+
This should be added everywhere `nest start` is invoked (`package.json`, scripts, terminal, etc).
25+
26+
### Using Node Executable
27+
28+
To instrument you Nest application when started with node executable, add the ["-r" ("--require")](https://nodejs.org/api/cli.html#-r---require-module) to `node` execution like this:
29+
30+
```
31+
node -r '@aspecto/opentelemetry/auto-instrument' dist/main
32+
```
33+
34+
## Configuration
35+
36+
When instrumenting an application with "Auto Instrument", configuration is supplied via environment variables or `aspecto.json` file. 
37+
38+
{% hint style="info" %}
39+
`ASPECTO_AUTH` **must be provided.** [Other configuration options](customize-defaults/advanced.md) are optional.
40+
{% endhint %}
41+
42+
### .env File
43+
44+
This part is relevant if you are using `@nestjs/config` package to load environment variables from `.env` file (or if you are loading the file yourself).
45+
46+
If you store Aspecto's SDK config options in `.env` file, it needs to be preloaded before `@aspecto/opentelemetry`, e.g.
47+
48+
```
49+
nest start -e 'node -r dotenv/config -r @aspecto/opentelemetry/auto-instrument'
50+
// or
51+
node -r dotenv/config -r '@aspecto/opentelemetry/auto-instrument' dist/main
52+
```

0 commit comments

Comments
 (0)