Skip to content

Instantly share code, notes, and snippets.

@ganny26
Created January 16, 2022 14:22
Show Gist options
  • Save ganny26/726861a88589c2f145746a61dc8f1486 to your computer and use it in GitHub Desktop.
Save ganny26/726861a88589c2f145746a61dc8f1486 to your computer and use it in GitHub Desktop.
service.js
const { init } = require('./tracer')
const api = require('@opentelemetry/api')
init('demo-node-service', 'development')
const express = require('express')
const axios = require('axios')
const app = express()
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.get('/hello', async (req, res) => {
const apiResponse = await axios.get('https://randomuser.me/api/')
const activeSpan = api.trace.getSpan(api.context.active())
activeSpan.addEvent('Hello API Called', { randomIndex: 1 })
res.status(200).send({
success: true,
result: apiResponse.data,
})
})
app.listen(3000, (req, res) => {
console.log('server started')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment