Skip to content

Commit

Permalink
feat(core): Add getSdkMetadata to Client (#6643)
Browse files Browse the repository at this point in the history
Add a new method to the `Client` interface: `getSdkMetadata`.
We can use this method in the Replay package to avoid accessing `client.getOptions()._metadata`, which previously caused broken CDN bundles which we hot-fixed with #6600. This change now properly fixes this issue by simply not accessing this "private" field anymore.
  • Loading branch information
Lms24 authored Jan 4, 2023
1 parent b03a32b commit c157f86
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Integration,
IntegrationClass,
Outcome,
SdkMetadata,
Session,
SessionAggregates,
Severity,
Expand Down Expand Up @@ -219,6 +220,15 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
return this._options;
}

/**
* @see SdkMetadata in @sentry/types
*
* @return The metadata of the SDK
*/
public getSdkMetadata(): SdkMetadata | undefined {
return this._options._metadata;
}

/**
* @inheritDoc
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/src/util/getReplayEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function getReplayEvent({
preparedEvent.platform = preparedEvent.platform || 'javascript';

// extract the SDK name because `client._prepareEvent` doesn't add it to the event
const metadata = client.getOptions() && client.getOptions()._metadata;
const { name } = (metadata && metadata.sdk) || {};
const metadata = client.getSdkMetadata && client.getSdkMetadata();
const name = (metadata && metadata.sdk && metadata.sdk.name) || 'sentry.javascript.unknown';

preparedEvent.sdk = {
...preparedEvent.sdk,
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Event, EventHint } from './event';
import { Integration, IntegrationClass } from './integration';
import { ClientOptions } from './options';
import { Scope } from './scope';
import { SdkMetadata } from './sdkmetadata';
import { Session, SessionAggregates } from './session';
import { Severity, SeverityLevel } from './severity';
import { Transport } from './transport';
Expand Down Expand Up @@ -69,6 +70,13 @@ export interface Client<O extends ClientOptions = ClientOptions> {
/** Returns the current options. */
getOptions(): O;

/**
* @inheritdoc
*
* TODO (v8): Make this a required method.
*/
getSdkMetadata?(): SdkMetadata | undefined;

/**
* Returns the transport that is used by the client.
* Please note that the transport gets lazy initialized so it will only be there once the first event has been sent.
Expand Down
2 changes: 0 additions & 2 deletions rollup/plugins/bundlePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export function makeTerserPlugin() {
'_driver',
'_initStorage',
'_support',
// TODO: Get rid of these once we use the SDK to send replay events
'_metadata', // replay uses client.getOptions()._metadata
],
},
},
Expand Down

0 comments on commit c157f86

Please sign in to comment.