Skip to content
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

fix: Remove setRelease and setDist, have auto release passed to native #213

Merged
merged 5 commits into from
Mar 22, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fix: Remove setRelease and setDist, have auto release passed to native #213

## v1.0.0-rc.1

- build(ios): Bump `sentry-cocoa` to 6.2.1 (#205)
Expand Down
28 changes: 7 additions & 21 deletions src/ios/SentryCordova.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ - (void)pluginInitialize {
- (void)startWithOptions:(CDVInvokedUrlCommand *)command {
NSDictionary *options = [command.arguments objectAtIndex:0];

SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event) {
[self setReleaseVersionDist:event];
SentryBeforeSendEventCallback beforeSend =
^SentryEvent *(SentryEvent *event) {
[self setEventOriginTag:event];

return event;
Expand Down Expand Up @@ -56,14 +56,17 @@ - (void)setEventOriginTag:(SentryEvent *)event {
if (event.sdk != nil) {
NSString *sdkName = event.sdk[@"name"];

// If the event is from cordova js, it gets set there and we do not handle it here.
// If the event is from cordova js, it gets set there and we do not handle
// it here.
if ([sdkName isEqualToString:@"sentry.cocoa"]) {
[self setEventEnvironmentTag:event origin:@"ios" environment:@"native"];
}
}
}

- (void)setEventEnvironmentTag:(SentryEvent *)event origin:(NSString *)origin environment:(NSString *)environment {
- (void)setEventEnvironmentTag:(SentryEvent *)event
origin:(NSString *)origin
environment:(NSString *)environment {
NSMutableDictionary *newTags = [NSMutableDictionary new];
if (nil != event.tags) {
[newTags addEntriesFromDictionary:event.tags];
Expand All @@ -73,23 +76,6 @@ - (void)setEventEnvironmentTag:(SentryEvent *)event origin:(NSString *)origin en
event.tags = newTags;
}

- (void)setReleaseVersionDist:(SentryEvent *)event {
if (event.extra[@"__sentry_version"]) {
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
event.releaseName =
[NSString stringWithFormat:@"%@-%@", infoDict[@"CFBundleIdentifier"],
event.extra[@"__sentry_version"]];
}
if (event.extra[@"__sentry_release"]) {
event.releaseName =
[NSString stringWithFormat:@"%@", event.extra[@"__sentry_release"]];
}
if (event.extra[@"__sentry_dist"]) {
event.dist =
[NSString stringWithFormat:@"%@", event.extra[@"__sentry_dist"]];
}
}

- (void)captureEnvelope:(CDVInvokedUrlCommand *)command {
NSDictionary *headerDict = [command.arguments objectAtIndex:0];
NSDictionary *payloadDict = [command.arguments objectAtIndex:1];
Expand Down
58 changes: 0 additions & 58 deletions src/js/__tests__/release.ts

This file was deleted.

48 changes: 48 additions & 0 deletions src/js/__tests__/sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getGlobalObject } from '@sentry/utils';

import { CordovaOptions } from '../backend';
import * as Sdk from '../sdk';

const optionsTest: {
current?: CordovaOptions;
} = {
current: undefined,
};

jest.mock('@sentry/core', () => {
const core = jest.requireActual('@sentry/core');

return {
...core,
initAndBind: jest.fn((_, options) => (optionsTest.current = options)),
makeMain: jest.fn(),
};
});

describe('Tests SDK', () => {
describe('init', () => {
it('Uses SENTRY_RELEASE environment variable if present.', () => {
const window = getGlobalObject<any>();
window.SENTRY_RELEASE = {
id: 'test-release',
};

Sdk.init({});

expect(optionsTest.current?.release).toBe('test-release');
});

it('User release has precedence over SENTRY_RELEASE', () => {
const window = getGlobalObject<any>();
window.SENTRY_RELEASE = {
id: 'test-release',
};

Sdk.init({
release: 'user-release',
});

expect(optionsTest.current?.release).toBe('user-release');
});
});
});
1 change: 0 additions & 1 deletion src/js/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { Release } from './release';
export { Cordova } from './cordova';
50 changes: 0 additions & 50 deletions src/js/integrations/release.ts

This file was deleted.

29 changes: 7 additions & 22 deletions src/js/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { defaultIntegrations as defaultBrowserIntegrations } from '@sentry/browser';
import { Hub, initAndBind, makeMain } from '@sentry/core';
import { configureScope } from '@sentry/minimal';
import { Scope } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils';

import { CordovaOptions } from './backend';
import { CordovaClient } from './client';
import { Cordova, Release } from './integrations';
import { Cordova } from './integrations';
import { CordovaScope } from './scope';
import { NATIVE } from './wrapper';

const DEFAULT_INTEGRATIONS = [...defaultBrowserIntegrations, new Cordova(), new Release()];
const DEFAULT_INTEGRATIONS = [...defaultBrowserIntegrations, new Cordova()];

const DEFAULT_OPTIONS: CordovaOptions = {
enableNative: true,
Expand All @@ -23,8 +22,12 @@ const DEFAULT_OPTIONS: CordovaOptions = {
* Inits the SDK
*/
export function init(_options: Partial<CordovaOptions>): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const window = getGlobalObject<{ SENTRY_RELEASE?: { id?: string } }>();

const options = {
...DEFAULT_OPTIONS,
release: window?.SENTRY_RELEASE?.id,
..._options,
};

Expand All @@ -35,24 +38,6 @@ export function init(_options: Partial<CordovaOptions>): void {
initAndBind(CordovaClient, options);
}

/**
* Sets the release on the event.
*/
export function setRelease(release: string): void {
configureScope((scope: Scope) => {
scope.setExtra('__sentry_release', release);
});
}

/**
* Sets the dist on the event.
*/
export function setDist(dist: string): void {
configureScope((scope: Scope) => {
scope.setExtra('__sentry_dist', dist);
});
}

/**
* If native client is available it will trigger a native crash.
* Use this only for testing purposes.
Expand Down
2 changes: 1 addition & 1 deletion src/js/sentry-cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export {
import { Integrations as BrowserIntegrations } from '@sentry/browser';
export { CordovaBackend, CordovaOptions } from './backend';
export { CordovaClient } from './client';
export { init, setDist, setRelease, nativeCrash } from './sdk';
export { init, nativeCrash } from './sdk';
export { SDK_NAME, SDK_VERSION } from './version';

import * as Integrations from './integrations';
Expand Down