Skip to content

ref(node-experimental): Remove deprecated class integrations #10675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Integrations as CoreIntegrations } from '@sentry/core';

import * as NodeExperimentalIntegrations from './integrations';
export { expressIntegration } from './integrations/express';
export { fastifyIntegration } from './integrations/fastify';
export { graphqlIntegration } from './integrations/graphql';
Expand All @@ -14,13 +11,6 @@ export { nativeNodeFetchIntegration } from './integrations/node-fetch';
export { postgresIntegration } from './integrations/postgres';
export { prismaIntegration } from './integrations/prisma';

/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
export const Integrations = {
// eslint-disable-next-line deprecation/deprecation
...CoreIntegrations,
...NodeExperimentalIntegrations,
};

export { init, getDefaultIntegrations } from './sdk/init';
export { getAutoPerformanceIntegrations } from './integrations/getAutoPerformanceIntegrations';
export * as Handlers from './sdk/handlers';
Expand Down
154 changes: 2 additions & 152 deletions packages/node-experimental/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import { SpanKind } from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';

import {
addBreadcrumb,
defineIntegration,
getIsolationScope,
hasTracingEnabled,
isSentryRequestUrl,
} from '@sentry/core';
import { addBreadcrumb, defineIntegration, getIsolationScope, isSentryRequestUrl } from '@sentry/core';
import { _INTERNAL, getClient, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
import type { EventProcessor, Hub, Integration, IntegrationFn } from '@sentry/types';
import { stringMatchesSomePattern } from '@sentry/utils';
import type { IntegrationFn } from '@sentry/types';

import { setIsolationScope } from '../sdk/scope';
import type { NodeExperimentalClient } from '../types';
import { addOriginToSpan } from '../utils/addOriginToSpan';
import { getRequestUrl } from '../utils/getRequestUrl';

Expand Down Expand Up @@ -111,148 +103,6 @@ const _httpIntegration = ((options: HttpOptions = {}) => {

export const httpIntegration = defineIntegration(_httpIntegration);

interface OldHttpOptions {
/**
* Whether breadcrumbs should be recorded for requests
* Defaults to true
*/
breadcrumbs?: boolean;

/**
* Whether tracing spans should be created for requests
* Defaults to false
*/
spans?: boolean;

/**
* Do not capture spans or breadcrumbs for outgoing HTTP requests to URLs matching the given patterns.
*/
ignoreOutgoingRequests?: (string | RegExp)[];
}

/**
* Http instrumentation based on @opentelemetry/instrumentation-http.
* This instrumentation does two things:
* * Create breadcrumbs for outgoing requests
* * Create spans for outgoing requests
*
* Note that this integration is also needed for the Express integration to work!
*
* @deprecated Use `httpIntegration()` instead.
*/
export class Http implements Integration {
/**
* @inheritDoc
*/
public static id: string = 'Http';

/**
* @inheritDoc
*/
public name: string;

/**
* If spans for HTTP requests should be captured.
*/
public shouldCreateSpansForRequests: boolean;

private _unload?: () => void;
private readonly _breadcrumbs: boolean;
// If this is undefined, use default behavior based on client settings
private readonly _spans: boolean | undefined;
private _ignoreOutgoingRequests: (string | RegExp)[];

/**
* @inheritDoc
*/
public constructor(options: OldHttpOptions = {}) {
// eslint-disable-next-line deprecation/deprecation
this.name = Http.id;
this._breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs;
this._spans = typeof options.spans === 'undefined' ? undefined : options.spans;

this._ignoreOutgoingRequests = options.ignoreOutgoingRequests || [];

// Properly set in setupOnce based on client settings
this.shouldCreateSpansForRequests = false;
}

/**
* @inheritDoc
*/
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void, _getCurrentHub: () => Hub): void {
// No need to instrument if we don't want to track anything
if (!this._breadcrumbs && this._spans === false) {
return;
}

const client = getClient<NodeExperimentalClient>();
const clientOptions = client?.getOptions();

// This is used in the sampler function
this.shouldCreateSpansForRequests =
typeof this._spans === 'boolean' ? this._spans : hasTracingEnabled(clientOptions);

// Register instrumentations we care about
this._unload = registerInstrumentations({
instrumentations: [
new HttpInstrumentation({
ignoreOutgoingRequestHook: request => {
const url = getRequestUrl(request);

if (!url) {
return false;
}

if (isSentryRequestUrl(url, getClient())) {
return true;
}

if (this._ignoreOutgoingRequests.length && stringMatchesSomePattern(url, this._ignoreOutgoingRequests)) {
return true;
}

return false;
},

ignoreIncomingRequestHook: request => {
const method = request.method?.toUpperCase();
// We do not capture OPTIONS/HEAD requests as transactions
if (method === 'OPTIONS' || method === 'HEAD') {
return true;
}

return false;
},

requireParentforOutgoingSpans: true,
requireParentforIncomingSpans: false,
requestHook: (span, req) => {
_updateSpan(span, req);

// Update the isolation scope, isolate this request
if (getSpanKind(span) === SpanKind.SERVER) {
setIsolationScope(getIsolationScope().clone());
}
},
responseHook: (span, res) => {
if (this._breadcrumbs) {
_addRequestBreadcrumb(span, res);
}
},
}),
],
});
}

/**
* Unregister this integration.
*/
public unregister(): void {
this._unload?.();
}
}

/** Update the span with data we need. */
function _updateSpan(span: Span, request: ClientRequest | IncomingMessage): void {
addOriginToSpan(span, 'auto.http.otel.http');
Expand Down
20 changes: 0 additions & 20 deletions packages/node-experimental/src/integrations/index.ts

This file was deleted.

113 changes: 3 additions & 110 deletions packages/node-experimental/src/integrations/node-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import type { Span } from '@opentelemetry/api';
import { SpanKind } from '@opentelemetry/api';
import type { Instrumentation } from '@opentelemetry/instrumentation';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { addBreadcrumb, defineIntegration, hasTracingEnabled } from '@sentry/core';
import { _INTERNAL, getClient, getSpanKind } from '@sentry/opentelemetry';
import type { Integration, IntegrationFn } from '@sentry/types';
import { addBreadcrumb, defineIntegration } from '@sentry/core';
import { _INTERNAL, getSpanKind } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
import { parseSemver } from '@sentry/utils';

import type { NodeExperimentalClient } from '../types';
import { addOriginToSpan } from '../utils/addOriginToSpan';
import { NodePerformanceIntegration } from './NodePerformanceIntegration';

const NODE_VERSION: ReturnType<typeof parseSemver> = parseSemver(process.versions.node);

Expand Down Expand Up @@ -77,111 +75,6 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {

export const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration);

interface OldNodeFetchOptions {
/**
* Whether breadcrumbs should be recorded for requests
* Defaults to true
*/
breadcrumbs?: boolean;

/**
* Whether tracing spans should be created for requests
* Defaults to false
*/
spans?: boolean;
}

/**
* Fetch instrumentation based on opentelemetry-instrumentation-fetch.
* This instrumentation does two things:
* * Create breadcrumbs for outgoing requests
* * Create spans for outgoing requests
*
* @deprecated Use `nativeNodeFetchIntegration()` instead.
*/
export class NodeFetch extends NodePerformanceIntegration<OldNodeFetchOptions> implements Integration {
/**
* @inheritDoc
*/
public static id: string = 'NodeFetch';

/**
* @inheritDoc
*/
public name: string;

/**
* If spans for HTTP requests should be captured.
*/
public shouldCreateSpansForRequests: boolean;

private readonly _breadcrumbs: boolean;
// If this is undefined, use default behavior based on client settings
private readonly _spans: boolean | undefined;

/**
* @inheritDoc
*/
public constructor(options: OldNodeFetchOptions = {}) {
super(options);

// eslint-disable-next-line deprecation/deprecation
this.name = NodeFetch.id;
this._breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs;
this._spans = typeof options.spans === 'undefined' ? undefined : options.spans;

// Properly set in setupOnce based on client settings
this.shouldCreateSpansForRequests = false;
}

/** @inheritDoc */
public setupInstrumentation(): void | Instrumentation[] {
// Only add NodeFetch if Node >= 16, as previous versions do not support it
if (!NODE_VERSION.major || NODE_VERSION.major < 16) {
return;
}

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { FetchInstrumentation } = require('opentelemetry-instrumentation-fetch-node');
return [
new FetchInstrumentation({
onRequest: ({ span }: { span: Span }) => {
_updateSpan(span);

if (this._breadcrumbs) {
_addRequestBreadcrumb(span);
}
},
}),
];
} catch (error) {
// Could not load instrumentation
}
}

/**
* @inheritDoc
*/
public setupOnce(): void {
super.setupOnce();

const client = getClient<NodeExperimentalClient>();
const clientOptions = client?.getOptions();

// This is used in the sampler function
this.shouldCreateSpansForRequests =
typeof this._spans === 'boolean' ? this._spans : hasTracingEnabled(clientOptions);
}

/**
* Unregister this integration.
*/
public unregister(): void {
this._unload?.();
}
}

/** Update the span with data we need. */
function _updateSpan(span: Span): void {
addOriginToSpan(span, 'auto.http.otel.node_fetch');
Expand Down
9 changes: 0 additions & 9 deletions packages/node-experimental/src/sdk/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
startSession,
} from '@sentry/core';
import {
defaultIntegrations as defaultNodeIntegrations,
defaultStackParser,
getDefaultIntegrations as getDefaultNodeIntegrations,
getSentryRelease,
Expand All @@ -34,14 +33,6 @@ import { initOtel } from './initOtel';

const ignoredDefaultIntegrations = ['Http', 'Undici'];

/** @deprecated Use `getDefaultIntegrations(options)` instead. */
export const defaultIntegrations: Integration[] = [
// eslint-disable-next-line deprecation/deprecation
...defaultNodeIntegrations.filter(i => !ignoredDefaultIntegrations.includes(i.name)),
httpIntegration(),
nativeNodeFetchIntegration(),
];

/** Get the default integrations for the Node Experimental SDK. */
export function getDefaultIntegrations(options: Options): Integration[] {
return [
Expand Down
Loading