Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const opentelemetry = require('@opentelemetry/core');
const config = require('./setup');
/**
* The trace instance needs to be initialized first, if you want to enable
* automatic tracing for built-in plugins (gRPC in this case).
*/
config.setupTracerAndExporters('grpc-client-service');
const grpc = require('grpc');
const messages = require('./helloworld_pb');
const services = require('./helloworld_grpc_pb');
const PORT = 50051;
const tracer = opentelemetry.getTracer();
/** A function which makes requests and handles response. */
function main() {
// span corresponds to outgoing requests. Here, we have manually created
// the span, which is created to track work that happens outside of the
// request lifecycle entirely.
const span = tracer.startSpan('client.js:main()');
tracer.withSpan(span, () => {
console.log('Client traceId ', span.context().traceId);
const client = new services.GreeterClient(
`localhost:${PORT}`,
grpc.credentials.createInsecure()
);
const request = new messages.HelloRequest();
let user;
if (process.argv.length >= 3) {
'use strict';
const opentelemetry = require('@opentelemetry/core');
const config = require('./setup');
/**
* The trace instance needs to be initialized first, if you want to enable
* automatic tracing for built-in plugins (HTTP in this case).
*/
config.setupTracerAndExporters('http-client-service');
const http = require('http');
const tracer = opentelemetry.getTracer();
/** A function which makes requests and handles response. */
function makeRequest() {
// span corresponds to outgoing requests. Here, we have manually created
// the span, which is created to track work that happens outside of the
// request lifecycle entirely.
const span = tracer.startSpan('makeRequest');
tracer.withSpan(span, () => {
http.get({
host: 'localhost',
port: 8080,
path: '/helloworld'
}, (response) => {
let body = [];
response.on('data', chunk => body.push(chunk));
response.on('end', () => {
function doWork(parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const span = opentelemetry.getTracer().startSpan('doWork', {
parent: parent
});
// simulate some random work.
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i++) { }
// Set attributes to the span.
span.setAttribute('key', 'value');
// Annotate our span to capture metadata about our operation
span.addEvent('invoking doWork').end();
}
function doWork(parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const span = opentelemetry.getTracer().startSpan('doWork', {
parent: parent
});
// simulate some random work.
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i++) { }
// Set attributes to the span.
span.setAttribute('key', 'value');
// Annotate our span to capture metadata about our operation
span.addEvent('invoking doWork').end();
}