File tree 3 files changed +40
-10
lines changed
3 files changed +40
-10
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ Open a command line terminal and navigate to the root of the directory.
34
34
For example:
35
35
36
36
````
37
- cd ~/splunk-opentelemetry-examples/instrumentation/nodejs
37
+ cd ~/splunk-opentelemetry-examples/instrumentation/nodejs/linux
38
38
````
39
39
40
40
### Initialize NPM and Install Packages (Optional)
@@ -53,18 +53,18 @@ npm install express
53
53
npm install pino
54
54
````
55
55
56
- There's no need to run these commands again as you can use the ` package.json ` file that
57
- was already created.
58
-
59
- ### Instrument with the Splunk Distribution of OpenTelemetry JS (Optional)
60
-
61
- Next, we'll instrument our application using the Splunk Distribution of OpenTelemetry JS
62
- by first installing the ` @splunk/otel ` package:
56
+ Next, we'll instrument our application using the Splunk Distribution of OpenTelemetry JS
57
+ by first installing the ` @splunk/otel ` package, so let's install this package as well:
63
58
64
59
````
65
60
npm install @splunk/otel
66
61
````
67
62
63
+ There's no need to run these commands again as you can use the ` package.json ` file that
64
+ was already created.
65
+
66
+ ### Configure the Splunk Distribution of OpenTelemetry JS
67
+
68
68
To configure the instrumentation, we've set the following environment variables:
69
69
70
70
````
@@ -80,6 +80,12 @@ AlwaysOn Profiling capabilities.
80
80
81
81
### Execute the application
82
82
83
+ Let's install the packages in the ` package.json ` file with the following command:
84
+
85
+ ````
86
+ npm install
87
+ ````
88
+
83
89
Next, we'll execute the application with the ` @splunk/otel ` package as follows:
84
90
85
91
````
Original file line number Diff line number Diff line change 1
1
const express = require ( "express" ) ;
2
2
const app = express ( ) ;
3
3
const logger = require ( 'pino' ) ( )
4
+ const opentelemetry = require ( '@opentelemetry/api' ) ;
4
5
5
6
const PORT = process . env . PORT || "8080" ;
7
+ const tracer = opentelemetry . trace . getTracer ( 'example-app' , '0.1.0' ) ;
6
8
7
9
app . get ( "/hello" , ( _ , res ) => {
8
- logger . info ( '/hello endpoint invoked, sending response' ) ;
9
- res . status ( 200 ) . send ( "Hello, World!" ) ;
10
+ hello ( res ) ;
10
11
} ) ;
11
12
12
13
app . listen ( parseInt ( PORT , 10 ) , ( ) => {
13
14
logger . info ( `Listening for requests on http://localhost:${ PORT } ` ) ;
14
15
} ) ;
16
+
17
+ function hello ( res ) {
18
+ logger . info ( '/hello endpoint invoked, sending response' ) ;
19
+ slow_function ( )
20
+ res . status ( 200 ) . send ( "Hello, World!" ) ;
21
+ }
22
+
23
+ // include a slow function to demonstrate CPU call stacks
24
+ function slow_function ( ) {
25
+
26
+ let result = 0 ;
27
+ for ( let i = 0 ; i < 1000000000 ; i ++ ) {
28
+ result += i ;
29
+ }
30
+
31
+ return result ;
32
+ }
You can’t perform that action at this time.
0 commit comments