Skip to content

ref(v8): Remove addRequestDataToTransaction util #11369

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
Apr 2, 2024
Merged
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
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