Skip to content

Commit

Permalink
chore(node): Extract node version constant (#7734)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Apr 5, 2023
1 parent c9fdf10 commit a0e9489
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
11 changes: 2 additions & 9 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import type { Hub } from '@sentry/core';
import { getCurrentHub } from '@sentry/core';
import type { EventProcessor, Integration, Span, TracePropagationTargets } from '@sentry/types';
import {
dynamicSamplingContextToSentryBaggageHeader,
fill,
logger,
parseSemver,
stringMatchesSomePattern,
} from '@sentry/utils';
import { dynamicSamplingContextToSentryBaggageHeader, fill, logger, stringMatchesSomePattern } from '@sentry/utils';
import type * as http from 'http';
import type * as https from 'https';
import { LRUMap } from 'lru_map';

import type { NodeClient } from '../client';
import { NODE_VERSION } from '../nodeVersion';
import type { RequestMethod, RequestMethodArgs } from './utils/http';
import { cleanSpanDescription, extractRawUrl, extractUrl, isSentryRequest, normalizeRequestArgs } from './utils/http';

const NODE_VERSION = parseSemver(process.versions.node);

interface TracingOptions {
/**
* List of strings/regex controlling to which outgoing requests
Expand Down
4 changes: 1 addition & 3 deletions packages/node/src/integrations/undici/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import type { EventProcessor, Integration } from '@sentry/types';
import {
dynamicRequire,
dynamicSamplingContextToSentryBaggageHeader,
parseSemver,
stringMatchesSomePattern,
stripUrlQueryAndFragment,
} from '@sentry/utils';

import type { NodeClient } from '../../client';
import { NODE_VERSION } from '../../nodeVersion';
import { isSentryRequest } from '../utils/http';
import type { DiagnosticsChannel, RequestCreateMessage, RequestEndMessage, RequestErrorMessage } from './types';

const NODE_VERSION = parseSemver(process.versions.node);

export enum ChannelName {
// https://github.com/nodejs/undici/blob/e6fc80f809d1217814c044f52ed40ef13f21e43c/docs/api/DiagnosticsChannel.md#undicirequestcreate
RequestCreate = 'undici:request:create',
Expand Down
3 changes: 1 addition & 2 deletions packages/node/src/integrations/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getCurrentHub } from '@sentry/core';
import { parseSemver } from '@sentry/utils';
import type * as http from 'http';
import type * as https from 'https';
import { URL } from 'url';

const NODE_VERSION = parseSemver(process.versions.node);
import { NODE_VERSION } from '../../nodeVersion';

/**
* Checks whether given url points to Sentry server
Expand Down
3 changes: 3 additions & 0 deletions packages/node/src/nodeVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { parseSemver } from '@sentry/utils';

export const NODE_VERSION: ReturnType<typeof parseSemver> = parseSemver(process.versions.node);
5 changes: 2 additions & 3 deletions packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Span, Transaction } from '@sentry/core';
import * as sentryCore from '@sentry/core';
import { addTracingExtensions, Hub } from '@sentry/core';
import type { TransactionContext } from '@sentry/types';
import { logger, parseSemver, TRACEPARENT_REGEXP } from '@sentry/utils';
import { logger, TRACEPARENT_REGEXP } from '@sentry/utils';
import * as http from 'http';
import * as https from 'https';
import * as HttpsProxyAgent from 'https-proxy-agent';
Expand All @@ -11,11 +11,10 @@ import * as nock from 'nock';
import type { Breadcrumb } from '../../src';
import { NodeClient } from '../../src/client';
import { Http as HttpIntegration } from '../../src/integrations/http';
import { NODE_VERSION } from '../../src/nodeVersion';
import type { NodeClientOptions } from '../../src/types';
import { getDefaultNodeClientOptions } from '../helper/node-client-options';

const NODE_VERSION = parseSemver(process.versions.node);

const originalHttpGet = http.get;
const originalHttpRequest = http.request;

Expand Down
8 changes: 4 additions & 4 deletions packages/node/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseSemver } from '@sentry/utils';
import { NODE_VERSION } from '../src/nodeVersion';

/**
* Returns`describe` or `describe.skip` depending on allowed major versions of Node.
Expand All @@ -7,12 +7,12 @@ import { parseSemver } from '@sentry/utils';
* @return {*} {jest.Describe}
*/
export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => {
const NODE_VERSION = parseSemver(process.versions.node).major;
if (!NODE_VERSION) {
const major = NODE_VERSION.major;
if (!major) {
return describe.skip as jest.Describe;
}

return NODE_VERSION < (allowedVersion.min || -Infinity) || NODE_VERSION > (allowedVersion.max || Infinity)
return major < (allowedVersion.min || -Infinity) || major > (allowedVersion.max || Infinity)
? (describe.skip as jest.Describe)
: (describe as any);
};

0 comments on commit a0e9489

Please sign in to comment.