Skip to content

ref(nextjs): Remove metadata builder class #4263

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 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions packages/nextjs/src/index.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { configureScope, init as reactInit, Integrations as BrowserIntegrations
import { BrowserTracing, defaultRequestInstrumentationOptions } from '@sentry/tracing';

import { nextRouterInstrumentation } from './performance/client';
import { MetadataBuilder } from './utils/metadataBuilder';
import { buildMetadata } from './utils/metadata';
import { NextjsOptions } from './utils/nextjsOptions';
import { addIntegration, UserIntegrations } from './utils/userIntegrations';

Expand All @@ -13,8 +13,7 @@ export const Integrations = { ...BrowserIntegrations, BrowserTracing };

/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
export function init(options: NextjsOptions): void {
const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'react']);
metadataBuilder.addSdkMetadata();
buildMetadata(options, ['nextjs', 'react']);
options.environment = options.environment || process.env.NODE_ENV;

// Only add BrowserTracing if a tracesSampleRate or tracesSampler is set
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { escapeStringForRegex, logger } from '@sentry/utils';
import * as domainModule from 'domain';
import * as path from 'path';

import { MetadataBuilder } from './utils/metadataBuilder';
import { buildMetadata } from './utils/metadata';
import { NextjsOptions } from './utils/nextjsOptions';
import { addIntegration } from './utils/userIntegrations';

Expand Down Expand Up @@ -43,8 +43,7 @@ export function init(options: NextjsOptions): void {
return;
}

const metadataBuilder = new MetadataBuilder(options, ['nextjs', 'node']);
metadataBuilder.addSdkMetadata();
buildMetadata(options, ['nextjs', 'node']);
options.environment = options.environment || process.env.NODE_ENV;
addServerIntegrations(options);
// Right now we only capture frontend sessions for Next.js
Expand Down
23 changes: 23 additions & 0 deletions packages/nextjs/src/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SDK_VERSION } from '@sentry/core';
import { Options, SdkInfo } from '@sentry/types';

const PACKAGE_NAME_PREFIX = 'npm:@sentry/';

/**
* A builder for the SDK metadata in the options for the SDK initialization.
* @param options sdk options object that gets mutated
* @param names list of package names
*/
export function buildMetadata(options: Options, names: string[]): void {
options._metadata = options._metadata || {};
options._metadata.sdk =
options._metadata.sdk ||
({
name: 'sentry.javascript.nextjs',
packages: names.map(name => ({
name: `${PACKAGE_NAME_PREFIX}${name}`,
version: SDK_VERSION,
})),
version: SDK_VERSION,
} as SdkInfo);
}
45 changes: 0 additions & 45 deletions packages/nextjs/src/utils/metadataBuilder.ts

This file was deleted.

11 changes: 10 additions & 1 deletion packages/nextjs/test/index.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ describe('Client init()', () => {
sdk: {
name: 'sentry.javascript.nextjs',
version: expect.any(String),
packages: expect.any(Array),
packages: [
{
name: 'npm:@sentry/nextjs',
version: expect.any(String),
},
{
name: 'npm:@sentry/react',
version: expect.any(String),
},
],
},
},
environment: 'test',
Expand Down
11 changes: 10 additions & 1 deletion packages/nextjs/test/index.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ describe('Server init()', () => {
sdk: {
name: 'sentry.javascript.nextjs',
version: expect.any(String),
packages: expect.any(Array),
packages: [
{
name: 'npm:@sentry/nextjs',
version: expect.any(String),
},
{
name: 'npm:@sentry/node',
version: expect.any(String),
},
],
},
},
autoSessionTracking: false,
Expand Down
52 changes: 0 additions & 52 deletions packages/nextjs/test/utils/metadataBuilder.test.ts

This file was deleted.