Skip to content

Commit

Permalink
ref(v8): Remove addRequestDataToTransaction util (getsentry#11369)
Browse files Browse the repository at this point in the history
See getsentry#11368, where
this is deprecated on v7.
  • Loading branch information
mydea authored and cadesalaberry committed Apr 19, 2024
1 parent 4fcfedf commit 353d62a
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions packages/utils/src/requestdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
Event,
ExtractedNodeRequestData,
PolymorphicRequest,
Transaction,
TransactionSource,
WebFetchHeaders,
WebFetchRequest,
Expand All @@ -24,17 +23,6 @@ const DEFAULT_INCLUDES = {
const DEFAULT_REQUEST_INCLUDES = ['cookies', 'data', 'headers', 'method', 'query_string', 'url'];
export const DEFAULT_USER_INCLUDES = ['id', 'username', 'email'];

type InjectedNodeDeps = {
cookie: {
parse: (cookieStr: string) => Record<string, string>;
};
url: {
parse: (urlStr: string) => {
query: string | null;
};
};
};

/**
* Options deciding what parts of the request to use when enhancing an event
*/
Expand Down Expand Up @@ -62,45 +50,6 @@ export type AddRequestDataToEventOptions = {

export type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';

/**
* Sets parameterized route as transaction name e.g.: `GET /users/:id`
* Also adds more context data on the transaction from the request
*/
export function addRequestDataToTransaction(
transaction: Transaction | undefined,
req: PolymorphicRequest,
// TODO(v8): Remove this parameter in v8
_deps?: InjectedNodeDeps,
): void {
if (!transaction) return;

// TODO(v8): SEMANTIC_ATTRIBUTE_SENTRY_SOURCE is in core, align this once we merge utils & core
// eslint-disable-next-line deprecation/deprecation
if (!transaction.attributes['sentry.source'] || transaction.attributes['sentry.source'] === 'url') {
// Attempt to grab a parameterized route off of the request
const [name, source] = extractPathForTransaction(req, { path: true, method: true });
transaction.updateName(name);
// TODO(v8): SEMANTIC_ATTRIBUTE_SENTRY_SOURCE is in core, align this once we merge utils & core
transaction.setAttribute('sentry.source', source);
}
transaction.setAttribute('url', req.originalUrl || req.url);
if (req.baseUrl) {
transaction.setAttribute('baseUrl', req.baseUrl);
}

const query = extractQueryParams(req);
if (typeof query === 'string') {
transaction.setAttribute('query', query);
} else if (query) {
Object.keys(query).forEach(key => {
const val = query[key];
if (typeof val === 'string' || typeof val === 'number') {
transaction.setAttribute(`query.${key}`, val);
}
});
}
}

/**
* Extracts a complete and parameterized path from the request object and uses it to construct transaction name.
* If the parameterized transaction name cannot be extracted, we fall back to the raw URL.
Expand Down

0 comments on commit 353d62a

Please sign in to comment.