Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function init(): Promise {
const SERVER_CONFIG = await config().get('calculator-service')
const ADD_SERVER_CONFIG = await config().get('add-service')
// Create thrift client
const thriftClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.host,
port: ADD_SERVER_CONFIG.port,
register: [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
],
const app = express()
app.use(
ZipkinTracingExpress({
localServiceName: 'calculator-client',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
)
// Create thrift client
const thriftClient: Calculator.Client = createHttpClient(
Calculator.Client,
{
hostName: SERVER_CONFIG.host,
port: SERVER_CONFIG.port,
register: [
ThriftClientZipkinFilter({
localServiceName: 'calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
],
export function createServer(sampleRate: number = 0): express.Application {
// Create thrift client
const addServiceClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.hostName,
port: ADD_SERVER_CONFIG.port,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
export async function createServer(
sampleRate: number = 0,
protocolType: ProtocolType = 'binary',
): Promise {
// Create thrift client
const addServiceClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.hostName,
port: ADD_SERVER_CONFIG.port,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
app.use([
ZipkinTracingExpress({
localServiceName: 'calculator-client',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2' ? 'v2' : 'v1',
sampleRate,
httpInterval: 0,
},
}),
])
}
// Create thrift client
const thriftClient: Calculator.Client = createHttpClient(
Calculator.Client,
{
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
protocol: protocolType,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
it('should reject when middleware rejects', async () => {
const client = createHttpClient(Calculator.Client, {
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
register: [
{
handler(
request: IThriftRequest,
next: NextFunction,
): Promise {
return next().then((res: IRequestResponse) => {
if (readThriftMethod(res.body) === 'nope') {
return Promise.resolve(res)
} else {
return Promise.reject(
new Error(
`Unrecognized method name: ${readThriftMethod(
res.body,
before(async () => {
calcServer = await createCalcServer()
addServer = await createAddServer()
client = createHttpClient(Calculator.Client, HAPI_CALC_SERVER_CONFIG)
return Promise.all([calcServer.start(), addServer.start()]).then(() => {
console.log('Thrift server started')
})
})
return new Promise((resolve, reject) => {
const app: express.Application = createCalcServer()
client = createHttpClient(
Calculator.Client,
EXPRESS_CALC_SERVER_CONFIG,
)
calcServer = app.listen(EXPRESS_CALC_SERVER_CONFIG.port, () => {
console.log(
`Express server listening on port: ${EXPRESS_CALC_SERVER_CONFIG.port}`,
)
addServer.start().then(() => resolve())
})
})
})
if (sampleRate > 0) {
await server.register({
plugin: ZipkinTracingHapi({
localServiceName: 'calculator-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2' ? 'v2' : 'v1',
sampleRate,
httpInterval: 0,
},
}),
})
}
const client: Calculator.Client = createHttpClient(Calculator.Client, {
serviceName: 'calculator-service',
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
path: HAPI_CALC_SERVER_CONFIG.path,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',