Skip to content

Commit c06bec9

Browse files
committed
add dev notes; update auto-instrumentations-node which eliminates the need for wait for batch span send at the end of app.js
1 parent 6928f88 commit c06bec9

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

packages/esbuild-plugin/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,83 @@ https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1856
88
More details in the PR.
99

1010
XXX obviously I need to fill this all in
11+
12+
13+
## Dev Notes
14+
15+
While this is all still in a development state, here is roughly how I work on this:
16+
17+
Get a clone of the https://github.com/open-telemetry/opentelemetry-js/pull/4818 feature branch (e.g. to `~/tm/opentelemetry-js10` in the example below).
18+
Get a clone of the https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2295 feature branch (e.g. to `~/tm/opentelemetry-js-contrib5` in the example below).
19+
20+
Setup the node_modules in the example in the contrib repo.
21+
22+
```bash
23+
cd ~/tm/opentelemetry-js-contrib5/packages/esbuild-plugin/example # my tm-esbuild-plugin-alternative branch
24+
# Note: You probably want to update to a recent '@opentelemetry/auto-instrumentations-node' dep, e.g. '^0.55.2'
25+
npm install # get the initial layout
26+
```
27+
28+
Build and copy in the changes from `@opentelemetry/instrumentation` in the core repo clone.
29+
30+
```bash
31+
cd ~/tm/opentelemetry-js10/experimental/packages/opentelemetry-instrumentation # my tm-esbuild-plugin-alternative branch
32+
vi ... # make whatever edits I need
33+
npm run compile
34+
rsync -av ~/tm/opentelemetry-js10/experimental/packages/opentelemetry-instrumentation/build/ ~/tm/opentelemetry-js-contrib5/packages/esbuild-plugin/example/node_modules/@opentelemetry/instrumentation/build/
35+
```
36+
37+
Back to the opentelemetry-js-contrib clone.
38+
39+
```bash
40+
cd ~/tm/opentelemetry-js-contrib5/packages/esbuild-plugin/example
41+
```
42+
43+
Run services used by app.js in a separate terminal:
44+
45+
```bash
46+
docker run --name redis -ti --rm -p 6379:6379 redis:7 # run redis in a terminal for app.js to use
47+
```
48+
49+
To watch OTel telemetry data for dev, I personally use `mockotlpserver` (https://github.com/elastic/elastic-otel-node/tree/main/packages/mockotlpserver#readme) which I and co-workers have written at Elastic. It is a smallish Node.js app that listens on the OTLP/HTTP and gRPC default ports and dumps a text representation of the data it receives. You can use it as follows, or use whatever you are used to:
50+
51+
```bash
52+
npx @elastic/mockotlpserver
53+
```
54+
55+
Now, run the *unbundled* app with instrumentation to see what to expect:
56+
57+
```bash
58+
export OTEL_NODE_DISABLED_INSTRUMENTATIONS=net,dns,fs # disable some distracting instrumentations
59+
export OTEL_NODE_RESOURCE_DETECTORS=env,host,os,process,serviceinstance # avoid cloud detectors to reduce noise
60+
node -r @opentelemetry/auto-instrumentations-node/register app.js
61+
```
62+
63+
If you get the same as me, the "mockotlpserver" summary output shows this tracing data:
64+
65+
```
66+
------ trace b3fbd7 (1 span) ------
67+
span c0f9c8 "redis-connect" (6.2ms, SPAN_KIND_CLIENT)
68+
------ trace a9186c (1 span) ------
69+
span 8666f5 "redis-SET" (0.7ms, SPAN_KIND_CLIENT)
70+
------ trace 2f54b8 (4 spans) ------
71+
span 65d728 "GET" (7.7ms, SPAN_KIND_CLIENT, GET http://localhost:3000/ping -> 200)
72+
+3ms `- span 91109f "GET /ping" (4.4ms, SPAN_KIND_SERVER, GET http://localhost:3000/ping -> 200)
73+
+0ms `- span f4aaca "request handler - fastify" (3.1ms, SPAN_KIND_INTERNAL)
74+
+1ms `- span 92f5d1 "redis-GET" (1.4ms, SPAN_KIND_CLIENT)
75+
```
76+
77+
Now run the *bundled* app with instrumentation and compare:
78+
79+
```bash
80+
vi esbuild.mjs # edit the `otelPlugin` function
81+
npm run build # build the bundle (in build/app.js)
82+
node -r @opentelemetry/auto-instrumentations-node/register build/app.js
83+
```
84+
85+
Verify that the bundle isn't using `node_modules/{redis,fastify}`:
86+
87+
```bash
88+
rm -rf node_modules/fastify node_modules/redis
89+
node -r @opentelemetry/auto-instrumentations-node/register build/app.js
90+
```

packages/esbuild-plugin/example/app.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ async function main() {
3232
server.close();
3333

3434
await redis.quit();
35-
36-
setTimeout(function () {
37-
console.log('Done lame wait for batch span send.')
38-
// console.log('XXX ', process._getActiveHandles());
39-
}, 10000);
4035
}
4136

4237
main();

packages/esbuild-plugin/example/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
},
88
"XXX dependencies": {
99
"@opentelemetry/auto-instrumentations-node": "^0.47.1",
10-
"@opentelemetry/instrumentation": "file:../../../../opentelemetry-js10/experimental/packages/opentelemetry-instrumentation",
11-
"@opentelemetry/instrumentation-fastify": "^0.37.0",
12-
"tabula": "^1.10.0"
10+
"@opentelemetry/instrumentation": "file:../../../../opentelemetry-js10/experimental/packages/opentelemetry-instrumentation"
1311
},
1412
"dependencies": {
15-
"@aws-sdk/client-s3": "^3.600.0",
16-
"@opentelemetry/auto-instrumentations-node": "^0.47.1",
13+
"@opentelemetry/auto-instrumentations-node": "^0.55.2",
1714
"fastify": "^4.28.0",
1815
"redis": "^4.6.14"
1916
}

0 commit comments

Comments
 (0)