src/census/plugins/http.ts
File http.ts
has 350 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
/**
* Copyright 2018, OpenCensus Authors
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
Function getPatchIncomingRequestFunction
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
protected getPatchIncomingRequestFunction () {
return (original: (event: string) => boolean) => {
const plugin = this
// This function's signature is that of an event listener, which can have
// any number of variable-type arguments.
Function getMakeRequestTraceFunction
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private getMakeRequestTraceFunction (
request: httpModule.ClientRequest, options: httpModule.RequestOptions,
plugin: HttpPlugin): Func<httpModule.ClientRequest> {
return (span: Span): httpModule.ClientRequest => {
plugin.logger.debug('makeRequestTrace')
Function incomingRequest
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
return function incomingRequest (event: string, ...args: any[]): boolean {
// Only traces request events
if (event !== 'request') {
return original.apply(this, arguments)
}
Function getPatchOutgoingRequestFunction
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
protected getPatchOutgoingRequestFunction () {
return (original: Func<httpModule.ClientRequest>): Func<
httpModule.ClientRequest> => {
const plugin = this
const kind = plugin.moduleName === 'https' ? 'HTTPS' : 'HTTP'
Function outgoingRequest
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
return function outgoingRequest (
options: httpModule.RequestOptions | string,
callback): httpModule.ClientRequest {
if (!options) {
return original.apply(this, arguments)
Function end
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
Wontfix
response.end = function (this: httpModule.ServerResponse) {
response.end = originalEnd
const returned = response.end.apply(this, arguments)
const requestUrl = url.parse(request.url || 'localhost')
Function convertTraceStatus
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static convertTraceStatus (statusCode: number): number {
if (statusCode < 200 || statusCode > 504) {
return TraceStatusCodes.UNKNOWN
} else if (statusCode >= 200 && statusCode < 400) {
return TraceStatusCodes.OK
Consider simplifying this complex logical expression. Open
Open
if (typeof (options) === 'string') {
const parsedUrl = url.parse(options)
options = parsedUrl
pathname = parsedUrl.pathname || '/'
origin = `${parsedUrl.protocol || 'http:'}//${parsedUrl.host}`
Avoid too many return
statements within this function. Open
Open
return plugin.tracer.startRootSpan(
traceOptions,
plugin.getMakeRequestTraceFunction(request, options, plugin))
Avoid too many return
statements within this function. Open
Open
return (plugin.getMakeRequestTraceFunction(request, options, plugin))(
span)
Function convertTraceStatus
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
static convertTraceStatus (statusCode: number): number {
if (statusCode < 200 || statusCode > 504) {
return TraceStatusCodes.UNKNOWN
} else if (statusCode >= 200 && statusCode < 400) {
return TraceStatusCodes.OK
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"