-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples(node-manual): add nodejs sample with manual instructions (#1842
- Loading branch information
Adnan Rahić
authored
Jan 16, 2023
1 parent
c0d9349
commit 3916865
Showing
13 changed files
with
7,182 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
examples/quick-start-nodejs-manual-instrumentation/.gitignore
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 | ||
.DS_Store |
7 changes: 7 additions & 0 deletions
7
examples/quick-start-nodejs-manual-instrumentation/Dockerfile
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,7 @@ | ||
FROM node:slim | ||
WORKDIR /usr/src/app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
EXPOSE 8080 | ||
CMD [ "npm", "run", "with-grpc-tracer" ] |
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,46 @@ | ||
const opentelemetry = require('@opentelemetry/api') | ||
const tracer = opentelemetry.trace.getTracer('quick-start-nodejs-manual-instrumentation-tracer') | ||
|
||
const express = require('express') | ||
const app = express() | ||
|
||
app.get('/', (req, res) => { | ||
const span = tracer.startSpan('Hello World') | ||
span.end() | ||
res.send('Hello World') | ||
}) | ||
|
||
app.get('/books', booksListHandler) | ||
|
||
function booksListHandler(req, res) { | ||
const span = tracer.startSpan('Books List') | ||
const books = getBooks() | ||
span.setAttribute('books.list.count', books.length) | ||
span.end() | ||
|
||
res.json(books) | ||
} | ||
|
||
function getBooks() { | ||
return [ | ||
{ | ||
id: 1, | ||
title: 'Harry Potter', | ||
isAvailable: 0, | ||
}, | ||
{ | ||
id: 2, | ||
title: 'Foundation', | ||
isAvailable: 0, | ||
}, | ||
{ | ||
id: 3, | ||
title: 'Moby Dick', | ||
isAvailable: 0, | ||
}, | ||
] | ||
} | ||
|
||
app.listen(8080, () => { | ||
console.log(`Listening for requests on http://localhost:8080`) | ||
}) |
9 changes: 9 additions & 0 deletions
9
examples/quick-start-nodejs-manual-instrumentation/docker-compose.yaml
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 @@ | ||
version: '3' | ||
services: | ||
app: | ||
image: quick-start-nodejs | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
build: . | ||
ports: | ||
- "8080:8080" |
Oops, something went wrong.