Skip to content

Commit

Permalink
fix: semantic
Browse files Browse the repository at this point in the history
  • Loading branch information
CircleCI committed Mar 8, 2022
1 parent 486af9f commit 93a0196
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/*.js
**/*.test.*s
src/**/jsonSortify.ts
src/**/xmlToJson.ts
src/**/xmlToJson.ts
src/**/logsInstrumentation.ts
2 changes: 2 additions & 0 deletions src/hooks/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export const ExpressHooks: InstrumentationIfc<ExpressRequestType, any> = {
res.send = function (data: any) {
response = data;
res.send = oldResSend;
// eslint-disable-next-line prefer-rest-params
return oldResSend.apply(res, arguments);
};
res.end = function () {
diag.debug('opentelemetry-instrumentation-express on end()');
return safeExecute(() => {
// eslint-disable-next-line prefer-rest-params
const origRes = oldResEnd.apply(res, arguments);
if (res.getHeaders())
span.setAttribute('http.response.headers', JSON.stringify(res.getHeaders()));
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InstrumentationIfc } from './hooksIfc';
import { isAwsService, runOneTimeWrapper, safeExecute } from '../utils';
import { getAwsServiceData } from '../spans/awsSpan';

// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

const isFunctionAlreadyWrapped = (fn) => fn && fn.__wrapped;
Expand Down Expand Up @@ -43,7 +44,7 @@ const createEmitResponseOnEmitBeforeHookHandler = (
span: Span & { attributes: Record<string, string> }
) => {
let body = '';
let maxPayloadSize = MAX_SIZE;
const maxPayloadSize = MAX_SIZE;
return function (args) {
const { headers, statusCode } = response;
if (args[0] === 'data' && body.length < maxPayloadSize) {
Expand Down Expand Up @@ -95,8 +96,10 @@ export const extractBodyFromEmitSocketEvent = (socketEventArgs) => {
) {
const httpMessage = socketEventArgs._httpMessage;
let lines = [];
// eslint-disable-next-line no-prototype-builtins
if (httpMessage.hasOwnProperty('outputData')) {
lines = httpMessage.outputData[0]?.data.split('\n') || [];
// eslint-disable-next-line no-prototype-builtins
} else if (httpMessage.hasOwnProperty('output')) {
lines = httpMessage.output[0]?.split('\n') || [];
}
Expand Down Expand Up @@ -208,7 +211,7 @@ export const HttpHooks: InstrumentationIfc<
headers: {},
},
};
let headers = getRequestHeaders(request);
const headers = getRequestHeaders(request);
requestData.request.host = span?.attributes && span.attributes['http.host'];
if (headers) {
requestData.request.headers = headers;
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentros/LumigoHttpInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpHooks } from '../hooks/http';

const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import axios, { AxiosResponse } from 'axios';
import { LUMIGO_ENDPOINT } from '../wrapper';

Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { sortify } from './tools/jsonSortify';

export function safeExecute<T>(
callback: Function,
message: string = 'Error in Lumigo tracer',
logLevel: string = 'warn',
message = 'Error in Lumigo tracer',
logLevel = 'warn',
defaultReturn: T = undefined
): Function {
return function (...args) {
Expand All @@ -31,7 +31,7 @@ export const runOneTimeWrapper = (func: Function, context: any = undefined): Fun

export const safeGet = (obj, arr, dflt = null) => {
let current = obj;
for (let i in arr) {
for (const i in arr) {
if (!current) {
return dflt;
}
Expand All @@ -54,7 +54,7 @@ export const isAwsService = (host, responseData = undefined): boolean => {
export const parseQueryParams = (queryParams) => {
return safeExecute(() => {
if (typeof queryParams !== 'string') return {};
let obj = {};
const obj = {};
queryParams.replace(
/([^=&]+)=([^&]*)/g,
// @ts-ignore
Expand Down
16 changes: 10 additions & 6 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
// And optionally change the logging level (Defaults to INFO)
import LumigoHttpInstrumentation from './instrumentros/LumigoHttpInstrumentation';
import LumigoExpressInstrumentation from './instrumentros/LumigoExpressInstrumentation';
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { Resource } = require('@opentelemetry/resources');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { Resource } from "@opentelemetry/resources";
import { CollectorTraceExporter } from "@opentelemetry/exporter-collector";
const logLevel =
(process.env.LUMIGO_DEBUG || 'false').toLowerCase() === 'true'
? DiagLogLevel.ALL
Expand All @@ -17,6 +17,7 @@ export const LUMIGO_ENDPOINT =
'http://lumigo-wrapper-collector.golumigo.com:55681/v1/trace' || process.env.LUMIGO_ENDPOINT;

export const getTracerInfo = (): { name: string; version: string } => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');
const { name, version } = pkg;
return { name, version };
Expand All @@ -40,6 +41,7 @@ const trace = (lumigoToken: string, serviceName: string, endpoint = LUMIGO_ENDPO
return;
}
const exporter = new CollectorTraceExporter({
// @ts-ignore
serviceName,
url: endpoint,
});
Expand All @@ -59,7 +61,9 @@ const trace = (lumigoToken: string, serviceName: string, endpoint = LUMIGO_ENDPO

registerInstrumentations({
instrumentations: [
// @ts-ignore
new LumigoHttpInstrumentation(lumigoToken, endpoint),
// @ts-ignore
new LumigoExpressInstrumentation(),
],
});
Expand All @@ -86,6 +90,6 @@ module.exports = {
LumigoExpressInstrumentation,
LumigoInstrumentations: (lumigoToken?: string) => [
new LumigoHttpInstrumentation(lumigoToken),
new LumigoExpressInstrumentation(lumigoToken),
new LumigoExpressInstrumentation(),
],
};

0 comments on commit 93a0196

Please sign in to comment.