Skip to content

Commit e078b80

Browse files
author
farfromrefuge
committed
chore(demo): show new way of uploading source maps
1 parent e2e3b07 commit e078b80

File tree

5 files changed

+56
-56
lines changed

5 files changed

+56
-56
lines changed

demo-vue/app/App_Resources/Android/app.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ android {
22
defaultConfig {
33
compileSdkVersion 33
44
multiDexEnabled true
5-
minSdkVersion 18
5+
minSdkVersion 19
66
targetSdkVersion 33
77
versionCode 104
88
versionName "2.0"

demo-vue/app/main.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as Sentry from '@nativescript-community/sentry';
2-
import { Application } from '@nativescript/core';
2+
import { Application, Trace, Utils } from '@nativescript/core';
33
import { on as applicationOn, launchEvent } from '@nativescript/core/application';
44
import Vue from 'nativescript-vue';
55
import Home from './views/Home';
66

7+
Trace.addCategories(Sentry.SentryTraceCategory);
8+
Trace.enable();
79

810

911
async function startSentry() {
@@ -15,25 +17,27 @@ async function startSentry() {
1517
enableNativeCrashHandling: true,
1618
enableAutoPerformanceTracking: false,
1719
enableAutoSessionTracking: false,
18-
attachScreenshot:true
20+
attachScreenshot: true,
21+
release: `${__APP_ID__}@${__APP_VERSION__}+${__APP_BUILD_NUMBER__}`,
22+
dist: `${__APP_BUILD_NUMBER__}.${__ANDROID__ ? 'android' : 'ios'}`
1923
});
2024
setTimeout(()=>{
21-
// Sentry.withScope(scope => {
22-
// try {
23-
// scope.setTag('myTag', 'tag-value');
24-
// scope.setExtra('myExtra', 'extra-value');
25-
// scope.addBreadcrumb({ message: 'test' });
26-
// Sentry.captureMessage('Hello Sentry!');
27-
// } catch (error) {
28-
// console.error(error);
29-
// }
30-
// });
25+
Sentry.withScope(scope => {
26+
try {
27+
scope.setTag('myTag', 'tag-value');
28+
scope.setExtra('myExtra', 'extra-value');
29+
scope.addBreadcrumb({ message: 'test' });
30+
Sentry.captureMessage('Hello Sentry!');
31+
} catch (error) {
32+
console.error(error);
33+
}
34+
});
3135
}, 1000);
3236
} catch(err){console.error(err, err.stack);}
3337

3438
}
3539

36-
if (!__ANDROID__ || Application.android.context) {
40+
if (!__ANDROID__ || Utils.android.getApplicationContext()) {
3741
startSentry();
3842
} else {
3943
applicationOn(launchEvent, startSentry);

demo-vue/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"readme": "README.md",
55
"repository": "http://www.github.com/nativescript-community/sentry.git",
66
"dependencies": {
7-
"@nativescript-community/sentry": "link:../plugin",
7+
"@nativescript-community/sentry": "portal:../plugin",
88
"@nativescript/core": "8.4.1",
99
"nativescript-vue": "2.9.3"
1010
},
@@ -13,9 +13,9 @@
1313
"@babel/preset-env": "~7.20.2",
1414
"@nativescript/android": "8.4.0",
1515
"@nativescript/ios": "8.4.0",
16-
"@nativescript/webpack": "~5.0.12",
17-
"@sentry/cli": "2.10.0",
18-
"@sentry/webpack-plugin": "2.2.2",
16+
"@nativescript/webpack": "~5.0.18",
17+
"@sentry/cli": "2.23.0",
18+
"@sentry/webpack-plugin": "2.10.2",
1919
"babel-loader": "~9.1.0",
2020
"cross-var": "^1.1.0",
2121
"nativescript-vue-template-compiler": "~2.9.3",

demo-vue/references.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ declare module '*.vue' {
99

1010
declare const SENTRY_DSN: string;
1111
declare const SENTRY_PREFIX: string;
12+
declare const __APP_ID__: string;
13+
declare const __APP_VERSION__: string;
14+
declare const __APP_BUILD_NUMBER__: string;

demo-vue/webpack.config.js

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,10 @@ const { readdirSync, readFileSync } = require('fs');
55
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
66
module.exports = (env, params = {}) => {
77
nsWebpack.init(env);
8-
nsWebpack.chainWebpack(config=>{
9-
config.entry('bundle').prepend('@nativescript-community/sentry/process');
10-
});
11-
const config = nsWebpack.resolveConfig();
12-
// Object.assign(config, {
13-
// snapshot: {
14-
// // detect changes in "node_modules"
15-
// managedPaths: [],
16-
// }
17-
// });
18-
const definitions =config.plugins.find((p) => p.constructor.name === 'DefinePlugin').definitions;
19-
delete definitions['process'];
20-
const SENTRY_PREFIX = 'app:///';
21-
Object.assign(definitions, {
22-
'SENTRY_DSN': '"https://[email protected]/2"',
23-
'SENTRY_PREFIX': `"${SENTRY_PREFIX}"`,
24-
});
25-
268
const nconfig = require('./nativescript.config');
9+
2710
const platform = env && ((env.android && 'android') || (env.ios && 'ios'));
2811
const dist = nsWebpack.Utils.platform.getDistPath();
29-
const SOURCEMAP_REL_DIR = '../../sourcemaps';
3012
const projectRoot = params.projectRoot || __dirname;
3113
const appResourcesPath = nconfig.appResourcesPath;
3214
let appVersion;
@@ -42,28 +24,39 @@ module.exports = (env, params = {}) => {
4224
appVersion = plistData.match(/<key>CFBundleShortVersionString<\/key>[\s\n]*<string>(.*?)<\/string>/)[1];
4325
buildNumber = plistData.match(/<key>CFBundleVersion<\/key>[\s\n]*<string>([0-9]*)<\/string>/)[1];
4426
}
27+
// nsWebpack.chainWebpack(config=>{
28+
// config.entry('bundle').prepend('@nativescript-community/sentry/process');
29+
// });
30+
const config = nsWebpack.resolveConfig();
31+
const definitions = config.plugins.find((p) => p.constructor.name === 'DefinePlugin').definitions;
32+
delete definitions['process'];
33+
Object.assign(definitions, {
34+
SENTRY_DSN: `"${process.env.SENTRY_DSN}"`,
35+
SENTRY_PREFIX: `"${process.env.SENTRY_PREFIX}"`,
36+
__APP_ID__: `"${config.id}"`,
37+
__APP_VERSION__: `"${appVersion}"`,
38+
__APP_BUILD_NUMBER__: `"${buildNumber}"`
39+
});
40+
4541
config.resolve.symlinks = false;
46-
config.devtool = false;
42+
config.devtool = 'source-map';
4743
config.plugins.push(
48-
new webpack.SourceMapDevToolPlugin({
49-
append: `\n//# sourceMappingURL=${SENTRY_PREFIX}[file].map`,
50-
filename: join(SOURCEMAP_REL_DIR, '[file].map')
44+
sentryWebpackPlugin({
45+
org: process.env.SENTRY_ORG,
46+
url: process.env.SENTRY_URL,
47+
project: process.env.SENTRY_PROJECT,
48+
authToken: process.env.SENTRY_AUTH_TOKEN,
49+
release: {
50+
create: true,
51+
cleanArtifacts: true,
52+
name: `${nconfig.id}@${appVersion}+${buildNumber}`,
53+
dist: `${buildNumber}.${platform}`,
54+
},
55+
sourcemaps: {
56+
ignore: ['tns-java-classes', 'hot-update'],
57+
assets: [dist + '/**/*.js', join(dist, process.env.SOURCEMAP_REL_DIR) + '/*.map']
58+
}
5159
})
5260
);
53-
// config.plugins.push(
54-
// sentryWebpackPlugin({
55-
// release: appVersion,
56-
// urlPrefix: SENTRY_PREFIX,
57-
// rewrite: true,
58-
// release: {
59-
// name: `${nconfig.id}@${appVersion}+${buildNumber}`,
60-
// dist: `${buildNumber}.${platform}`,
61-
// uploadLegacySourcemaps: {
62-
// ignoreFile: '.sentrycliignore',
63-
// paths: [dist, join(dist, SOURCEMAP_REL_DIR)]
64-
// },
65-
// },
66-
// })
67-
// );
6861
return config;
6962
};

0 commit comments

Comments
 (0)