-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add typescript e2e example/test (#800)
* test: add typescript e2e test * chore: fix linting
- Loading branch information
Showing
12 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
lib | ||
src/profiling/proto | ||
examples/typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { start } from '@splunk/otel'; | ||
import * as otel from '@opentelemetry/api'; | ||
|
||
start({ | ||
serviceName: 'random-number-generator', | ||
// Set up the OpenTelemetry metrics pipeline and start collecting runtime metrics. | ||
metrics: { | ||
runtimeMetricsEnabled: true, | ||
}, | ||
}); | ||
|
||
// Load libraries after calling start() | ||
import * as express from 'express'; | ||
|
||
const tracer = otel.trace.getTracer('rng-app'); | ||
const meter = otel.metrics.getMeter('rng-app'); | ||
const requestCounter = meter.createCounter('requests'); | ||
|
||
const app = express(); | ||
|
||
app.get('/', (req, res) => { | ||
requestCounter.add(1); | ||
const randomValue = tracer.startActiveSpan('calculate-random', (span) => { | ||
const result = (Math.random() * 42) | 0; | ||
span.setAttribute('random-result', result); | ||
span.setAttribute('random-method', 'diceroll'); | ||
span.end(); | ||
return result; | ||
}); | ||
|
||
res.json({ randomValue }); | ||
}); | ||
|
||
app.listen(process.env.PORT || 8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "splunk-otel-example-typescript", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "npm run compile && node index.js", | ||
"compile": "tsc" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.3.0", | ||
"@splunk/otel": "2.4.1", | ||
"express": "^4.18.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "5.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
app: | ||
working_dir: /home/node/app/examples/typescript | ||
env_file: ./typescript/app.env | ||
command: npm run start | ||
depends_on: | ||
- collector | ||
test: | ||
command: node ./typescript | ||
environment: | ||
REQ_URL: http://app/ | ||
COLLECTOR_URL: http://collector:8378 | ||
depends_on: | ||
- app | ||
- collector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PORT=80 | ||
OTEL_RESOURCE_ATTRIBUTES='deployment.environment=dev' | ||
OTEL_LOG_LEVEL='DEBUG' | ||
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { | ||
assertSpans, | ||
logSpanTable, | ||
request, | ||
waitSpans, | ||
} = require('../utils.js'); | ||
const snapshot = require('./snapshot.js'); | ||
|
||
waitSpans(snapshot.length).then((data) => { | ||
logSpanTable(data); | ||
return assertSpans(data, snapshot); | ||
}).then((validatedSpans) => { | ||
console.log(`${validatedSpans} spans validated.`); | ||
}); | ||
|
||
request(process.env.REQ_URL ?? 'http://localhost:8080'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
module.exports = [ | ||
{ | ||
traceId: 'neZpe/CP+vAd5/rhg0Tw3A==', | ||
id: 'fe+RxrZ76pE=', | ||
startTime: '2023-09-18T20:16:38.412999936Z', | ||
hrStartTime: 1695068198412999936n, | ||
name: 'middleware - query', | ||
kind: 'internal', | ||
parentSpanId: 'NVeO5hUT2bw=', | ||
parent: { id: 'NVeO5hUT2bw=', traceId: 'neZpe/CP+vAd5/rhg0Tw3A==' }, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': '@opentelemetry/instrumentation-express', | ||
'otel.library.version': '0.33.0', | ||
'http.route': '/', | ||
'express.name': 'query', | ||
'express.type': 'middleware', | ||
'span.kind': 'internal' | ||
} | ||
}, | ||
{ | ||
traceId: 'neZpe/CP+vAd5/rhg0Tw3A==', | ||
id: 'CnuvgyiHryk=', | ||
startTime: '2023-09-18T20:16:38.416Z', | ||
hrStartTime: 1695068198416000000n, | ||
name: 'middleware - expressInit', | ||
kind: 'internal', | ||
parentSpanId: 'NVeO5hUT2bw=', | ||
parent: { id: 'NVeO5hUT2bw=', traceId: 'neZpe/CP+vAd5/rhg0Tw3A==' }, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': '@opentelemetry/instrumentation-express', | ||
'otel.library.version': '0.33.0', | ||
'http.route': '/', | ||
'express.name': 'expressInit', | ||
'express.type': 'middleware', | ||
'span.kind': 'internal' | ||
} | ||
}, | ||
{ | ||
traceId: 'neZpe/CP+vAd5/rhg0Tw3A==', | ||
id: 'ZXuWjxuKTqw=', | ||
startTime: '2023-09-18T20:16:38.416999936Z', | ||
hrStartTime: 1695068198416999936n, | ||
name: 'request handler - /', | ||
kind: 'internal', | ||
parentSpanId: 'NVeO5hUT2bw=', | ||
parent: { id: 'NVeO5hUT2bw=', traceId: 'neZpe/CP+vAd5/rhg0Tw3A==' }, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': '@opentelemetry/instrumentation-express', | ||
'otel.library.version': '0.33.0', | ||
'http.route': '/', | ||
'express.name': '/', | ||
'express.type': 'request_handler', | ||
'span.kind': 'internal' | ||
} | ||
}, | ||
{ | ||
traceId: 'neZpe/CP+vAd5/rhg0Tw3A==', | ||
id: '2rGvSI5L/p4=', | ||
startTime: '2023-09-18T20:16:38.417999872Z', | ||
hrStartTime: 1695068198417999872n, | ||
name: 'calculate-random', | ||
kind: 'internal', | ||
parentSpanId: 'NVeO5hUT2bw=', | ||
parent: { id: 'NVeO5hUT2bw=', traceId: 'neZpe/CP+vAd5/rhg0Tw3A==' }, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': 'rng-app', | ||
'random-result': undefined, | ||
'random-method': 'diceroll', | ||
'span.kind': 'internal' | ||
} | ||
}, | ||
{ | ||
traceId: 'neZpe/CP+vAd5/rhg0Tw3A==', | ||
id: 'NVeO5hUT2bw=', | ||
startTime: '2023-09-18T20:16:38.400999936Z', | ||
hrStartTime: 1695068198400999936n, | ||
name: 'GET /', | ||
kind: 'server', | ||
parentSpanId: undefined, | ||
parent: undefined, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': '@opentelemetry/instrumentation-http', | ||
'otel.library.version': '0.41.2', | ||
'http.url': 'http://app/', | ||
'http.host': 'app', | ||
'net.host.name': 'app', | ||
'http.method': 'GET', | ||
'http.scheme': 'http', | ||
'http.target': '/', | ||
'http.user_agent': 'undici', | ||
'http.flavor': '1.1', | ||
'net.transport': 'ip_tcp', | ||
'net.host.ip': '::ffff:172.31.0.3', | ||
'net.host.port': undefined, | ||
'net.peer.ip': '::ffff:172.31.0.4', | ||
'net.peer.port': undefined, | ||
'http.status_code': undefined, | ||
'http.status_text': 'OK', | ||
'http.route': '/', | ||
'span.kind': 'server' | ||
} | ||
} | ||
]; |