Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jaeger-tracer

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jaeger-tracer - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

2

build/index.d.ts

@@ -5,3 +5,3 @@ export declare let initTracer: (serviceName: string, config?: import("./interfaces/jaeger-client-config.interface").Config, options?: import("./interfaces/jaeger-client-config.interface").Options) => import("./interfaces/jaegar-tracer.interface").Tracer;

export declare let spanMaker: (name: string, parentContext: import("./interfaces/jaegaer-span.interface").SpanContext | null, tracer: import("./interfaces/jaegar-tracer.interface").Tracer) => import("./interfaces/jaegaer-span.interface").Span;
export declare let jaegarTracerMiddleware: (httpModules: import("./interfaces/httpModules.interface").httpModules, serviceName: string, config?: import("./interfaces/jaeger-client-config.interface").Config | undefined, options?: import("./interfaces/jaeger-client-config.interface").Options | undefined) => (req: import("express-serve-static-core").Request, res: import("express-serve-static-core").Response, next: Function) => void;
export declare let jaegarTracerMiddleware: (httpModules: import("./interfaces/httpModules.interface").httpModules, serviceName: string, config?: import("./interfaces/jaeger-client-config.interface").Config, options?: import("./interfaces/jaeger-client-config.interface").Options) => (req: import("express-serve-static-core").Request, res: import("express-serve-static-core").Response, next: Function) => void;
export declare let getContext: () => import("continuation-local-storage").Namespace;

@@ -8,0 +8,0 @@ export declare let unirestWrapper: <T extends {

@@ -25,2 +25,3 @@ export interface Config {

};
shouldTrace?: () => Boolean | Boolean;
}

@@ -31,2 +32,3 @@ export interface Options {

logger?: any;
filterData?: (data: any) => any;
}
import { Request, Response } from "express-serve-static-core";
import { Config, Options } from "./interfaces/jaeger-client-config.interface";
import { httpModules } from './interfaces/httpModules.interface';
export declare let jaegarTracerMiddleWare: (httpModules: httpModules, serviceName: string, config?: Config | undefined, options?: Options | undefined) => (req: Request, res: Response, next: Function) => void;
export declare let jaegarTracerMiddleWare: (httpModules: httpModules, serviceName: string, config?: Config, options?: Options) => (req: Request, res: Response, next: Function) => void;

@@ -12,2 +12,6 @@ "use strict";

exports.jaegarTracerMiddleWare = function (httpModules, serviceName, config, options) {
if (config === void 0) { config = {}; }
if (options === void 0) { options = {}; }
if (!shouldTrace(config.shouldTrace))
return function (req, res, next) { return next(); };
var tracer = tracer_1.initTracer(serviceName, config, options);

@@ -20,3 +24,3 @@ var middleware = function (req, res, next) {

spanDataSetter_1.setReqSpanData(req, res, mainReqSpan);
var responseInterceptor = spanDataSetter_1.setResSpanData(req, res, mainReqSpan);
var responseInterceptor = spanDataSetter_1.setResSpanData(req, res, mainReqSpan, options.filterData);
spanDataSetter_1.putParentHeaderInOutgoingRequests(httpModules, tracer, mainReqSpan);

@@ -28,2 +32,14 @@ ClsManager_1.associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor);

};
function shouldTrace(isTraceWorking) {
if (isTraceWorking === undefined)
return true;
var type = typeof isTraceWorking;
if (type === 'boolean') {
return isTraceWorking;
}
if (type === 'function') {
return isTraceWorking();
}
throw Error("shouldTrace value should of type \"boolean\" or \"function\" that returns a boolean");
}
//# sourceMappingURL=middleware.js.map

@@ -6,3 +6,3 @@ import { Request, Response } from "express";

export declare let setReqSpanData: (req: Request, res: Response, span: Span) => Span;
export declare let setResSpanData: (req: Request, res: Response, span: Span) => any;
export declare let setResSpanData: (req: Request, res: Response, span: Span, filterFunction: any) => any;
export declare let putParentHeaderInOutgoingRequests: ({ http, https }: httpModules, tracer: Tracer, span: Span) => void;

@@ -13,2 +13,37 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -32,3 +67,3 @@ var express_mung_1 = require("express-mung");

};
exports.setResSpanData = function (req, res, span) {
exports.setResSpanData = function (req, res, span, filterFunction) {
res.once('error', function (err) {

@@ -48,3 +83,3 @@ span.log({

res.once('finish', function () {
span.log(__assign({}, responseSpanLog, { headers: this.getHeaders ? this.getHeaders() : this.headers || {}, statusCode: this.statusCode || 'no status found', statusMessage: this.statusMessage || 'no message found' }));
span.log(applyDataFilter(filterFunction, __assign({}, responseSpanLog, { headers: this.getHeaders ? this.getHeaders() : this.headers || {}, statusCode: this.statusCode || 'no status found', statusMessage: this.statusMessage || 'no message found' })));
span.finish();

@@ -100,2 +135,19 @@ });

var theNothingFunction = function () { return null; };
function applyDataFilter(filterFunction, data) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!filterFunction)
return [2, data];
result = filterFunction(data);
if (!result.then) return [3, 2];
return [4, result];
case 1: return [2, _a.sent()];
case 2: return [2, result];
}
});
});
}
//# sourceMappingURL=spanDataSetter.js.map
{
"name": "jaeger-tracer",
"version": "1.1.7",
"version": "1.1.8",
"description": "client library for jaegar to ease out the instrumenting in express and any other backend application based on express in nodejs",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -40,3 +40,10 @@ export interface Config {

refreshIntervalMs?: number;
}
},
/**
* @description this is a property to control if the tracer should work or not
* usually used to stop tracing in production systems
*/
shouldTrace?: () => Boolean | Boolean;
};

@@ -48,2 +55,9 @@

logger?: any;
/**
* @description this is a function which will be applied on the data before they
* are put into log
* @returns has to return the data to be logged or else it will log nothing
*/
filterData?: (data: any) => any;
}

@@ -17,4 +17,8 @@ import { getNamespace } from 'continuation-local-storage';

*/
export let jaegarTracerMiddleWare = function (httpModules: httpModules, serviceName: string, config?: Config, options?: Options) {
export let jaegarTracerMiddleWare = function (httpModules: httpModules, serviceName: string, config: Config = {}, options: Options = {}) {
// if we should not trace then just return an empty middleware
if (!shouldTrace(config.shouldTrace))
return (req: any, res: any, next: Function) => next();
// initiating the tracer outside the middleware so we dont have to initiate it everytime a request comes

@@ -43,3 +47,3 @@ let tracer = initTracer(serviceName, config, options);

// setting span data on the response and ending the span when the response comes
let responseInterceptor = setResSpanData(req, res, mainReqSpan);
let responseInterceptor = setResSpanData(req, res, mainReqSpan, options.filterData);

@@ -58,2 +62,21 @@ // monkey patch http and https modules to put the headers inside

function shouldTrace(isTraceWorking?: () => Boolean | Boolean) {
// by default we should trace
if (isTraceWorking === undefined)
return true;
let type = typeof isTraceWorking;
if (type === 'boolean') {
return isTraceWorking;
}
if (type === 'function') {
return isTraceWorking();
}
throw Error(`shouldTrace value should of type "boolean" or "function" that returns a boolean`);
}
/**

@@ -60,0 +83,0 @@ * when the request comes we will initiate a tracer -- checked

@@ -27,3 +27,3 @@ import { Request, Response } from "express";

export let setResSpanData = (req: Request, res: Response, span: Span): any => {
export let setResSpanData = (req: Request, res: Response, span: Span, filterFunction: any): any => {

@@ -48,8 +48,11 @@ // listening to the error

// just finishing the span in case the mung did not work
span.log({
...responseSpanLog,
headers: this.getHeaders ? this.getHeaders() : this.headers || {},
statusCode: this.statusCode || 'no status found',
statusMessage: this.statusMessage || 'no message found'
});
span.log(
// applying the filter function which the user usually provide
applyDataFilter(filterFunction, {
...responseSpanLog,
headers: this.getHeaders ? this.getHeaders() : this.headers || {},
statusCode: this.statusCode || 'no status found',
statusMessage: this.statusMessage || 'no message found'
})
);
span.finish();

@@ -75,2 +78,9 @@ });

/**
* @description this is the function which override the actual http.request and https.request
* to put the tracer headers in the request
* @param param0
* @param tracer
* @param span
*/
export let putParentHeaderInOutgoingRequests = ({ http, https }: httpModules, tracer: Tracer, span: Span) => {

@@ -137,2 +147,22 @@ let headers = getInjectHeaders(tracer, span);

let theNothingFunction = () => null;
/**
* @description just an empty function used for passing function purposes
*/
let theNothingFunction = () => null;
/**
* @description this is a function which apply filters on the logged data before they are logged
*/
async function applyDataFilter(filterFunction: Function, data: any) {
if (!filterFunction)
return data;
// calling the data filter function
let result = filterFunction(data);
// if it returned a promise await it
if (result.then)
return await result;
return result;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc