Skip to content

Commit

Permalink
Merge pull request #126 from jack-blackson/v2.1.4
Browse files Browse the repository at this point in the history
V2.1.4
  • Loading branch information
jack-blackson authored May 28, 2022
2 parents 75695e1 + a1ab723 commit ede698b
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ If you don't find your country, please create an issue on github, and I will be

## Changelog

## 2.1.4 (2022-05-26)
* (jack-blackson) Added breadcrumb for Sentry to see what location created an error
* (jack-blackson) Start tracking in Sentry when XMLs without geocode are sent

## 2.1.3 (2022-05-23)
* (jack-blackson) Handle Warnings that are sent without a geocode -> Sentry IOBROKER-METEOALARM-3B

Expand Down
14 changes: 13 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"common": {
"name": "meteoalarm",
"version": "2.1.3",
"version": "2.1.4",
"news": {
"2.1.4": {
"en": "Add SENTRY event details",
"de": "SENTRY-Ereignisdetails hinzufügen",
"ru": "Добавить информацию о событии SENTRY",
"pt": "Adicionar detalhes do evento SENTRY",
"nl": "Voeg SENTRY-evenementdetails toe",
"fr": "Ajouter les détails de l'événement SENTRY",
"it": "Aggiungi i dettagli dell'evento SENTRY",
"es": "Agregar detalles del evento SENTRY",
"pl": "Dodaj szczegóły wydarzenia SENTRY",
"zh-cn": "添加 SENTRY 事件详细信息"
},
"2.1.3": {
"en": "Bugfixes",
"de": "Fehlerbehebung",
Expand Down
133 changes: 131 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,109 @@ var maxAlarmLevel = 1

var imageSizeSetup = 0

let Sentry;
let SentryIntegrations;
function initSentry(callback) {
if (!adapter.ioPack.common || !adapter.ioPack.common.plugins || !adapter.ioPack.common.plugins.sentry) {
return callback && callback();
}
const sentryConfig = adapter.ioPack.common.plugins.sentry;
if (!sentryConfig.dsn) {
adapter.log.warn('Invalid Sentry definition, no dsn provided. Disable error reporting');
return callback && callback();
}
// Require needed tooling
Sentry = require('@sentry/node');
SentryIntegrations = require('@sentry/integrations');
// By installing source map support, we get the original source
// locations in error messages
require('source-map-support').install();

let sentryPathWhitelist = [];
if (sentryConfig.pathWhitelist && Array.isArray(sentryConfig.pathWhitelist)) {
sentryPathWhitelist = sentryConfig.pathWhitelist;
}
if (adapter.pack.name && !sentryPathWhitelist.includes(adapter.pack.name)) {
sentryPathWhitelist.push(adapter.pack.name);
}
let sentryErrorBlacklist = [];
if (sentryConfig.errorBlacklist && Array.isArray(sentryConfig.errorBlacklist)) {
sentryErrorBlacklist = sentryConfig.errorBlacklist;
}
if (!sentryErrorBlacklist.includes('SyntaxError')) {
sentryErrorBlacklist.push('SyntaxError');
}

Sentry.init({
release: adapter.pack.name + '@' + adapter.pack.version,
dsn: sentryConfig.dsn,
integrations: [
new SentryIntegrations.Dedupe()
]
});
Sentry.configureScope(scope => {
scope.setTag('version', adapter.common.installedVersion || adapter.common.version);
if (adapter.common.installedFrom) {
scope.setTag('installedFrom', adapter.common.installedFrom);
}
else {
scope.setTag('installedFrom', adapter.common.installedVersion || adapter.common.version);
}
scope.addEventProcessor(function(event, hint) {
// Try to filter out some events
if (event.exception && event.exception.values && event.exception.values[0]) {
const eventData = event.exception.values[0];
// if error type is one from blacklist we ignore this error
if (eventData.type && sentryErrorBlacklist.includes(eventData.type)) {
return null;
}
if (eventData.stacktrace && eventData.stacktrace.frames && Array.isArray(eventData.stacktrace.frames) && eventData.stacktrace.frames.length) {
// if last exception frame is from an nodejs internal method we ignore this error
if (eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename && (eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename.startsWith('internal/') || eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename.startsWith('Module.'))) {
return null;
}
// Check if any entry is whitelisted from pathWhitelist
const whitelisted = eventData.stacktrace.frames.find(frame => {
if (frame.function && frame.function.startsWith('Module.')) {
return false;
}
if (frame.filename && frame.filename.startsWith('internal/')) {
return false;
}
if (frame.filename && !sentryPathWhitelist.find(path => path && path.length && frame.filename.includes(path))) {
return false;
}
return true;
});
if (!whitelisted) {
return null;
}
}
}

return event;
});

adapter.getForeignObject('system.config', (err, obj) => {
if (obj && obj.common && obj.common.diag !== 'none') {
adapter.getForeignObject('system.meta.uuid', (err, obj) => {
// create uuid
if (!err && obj) {
Sentry.configureScope(scope => {
scope.setUser({
id: obj.native.uuid
});
});
}
callback && callback();
});
}
else {
callback && callback();
}
});
});
}

//var Interval

Expand All @@ -74,7 +176,18 @@ function startAdapter(options) {
callback && callback();
});


adapter.on('ready', function() {
if (adapter.supportsFeature && adapter.supportsFeature('PLUGINS')) {
const sentryInstance = adapter.getPluginInstance('sentry');
if (sentryInstance) {
Sentry = sentryInstance.getSentryObject();
}
main();
}
else {
initSentry(main);
}
});

return adapter;

Expand Down Expand Up @@ -120,7 +233,15 @@ async function getData(){
}
else{
adapter.log.debug('Setup found: country ' + countryConfig + ' and region ' + regionConfig + ' - ' + regionName )

if (Sentry){
adapter.log.debug('Sentry aktiv - Breadcrumb gesetzt')
Sentry.addBreadcrumb({
category: "info",
message: 'Country ' + countryConfig + ', Region '+ regionConfig + ' - ' + regionName,
level: Sentry.Severity.Info,
});
}

urlAtom = getCountryLink(countryConfig)
xmlLanguage = getXMLLanguage(countryConfig)
if (xmlLanguage == ""){
Expand Down Expand Up @@ -427,11 +548,19 @@ function checkRelevante(entry){
}

var locationRelevant = false

if (element['cap:geocode'] && element['cap:geocode'].valueName ){
locationRelevant = checkLocation(element['cap:geocode'].valueName , element['cap:geocode'].value)
}
else{
adapter.log.debug('4.1.2: Warning without geocode - cannot check')
if(Sentry){
Sentry && Sentry.withScope(scope => {
scope.setLevel('info');
scope.setExtra('Location: ', 'Country ' + countryConfig + ', Region '+ regionConfig + ' - ' + regionName);
Sentry.captureMessage('No geocode included', 'info'); // Level "info"
});
}
}

var statusRelevant = false
Expand Down
Loading

0 comments on commit ede698b

Please sign in to comment.