From 0e50b13ce2ae4336bf26f848179d97249c9c6b60 Mon Sep 17 00:00:00 2001 From: Dmitry Patsura Date: Mon, 20 May 2019 23:52:46 +0300 Subject: [PATCH] Feature: Introduce setEnvironment method --- lib/RavenClient.js | 8 ++++++-- lib/Sentry.d.ts | 2 ++ lib/Sentry.js | 14 ++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/RavenClient.js b/lib/RavenClient.js index 02b600eb57..32fbd56454 100644 --- a/lib/RavenClient.js +++ b/lib/RavenClient.js @@ -1,5 +1,5 @@ import Raven from 'raven-js'; -import {Sentry, SentryLog} from './Sentry'; +import { Sentry, SentryLog } from './Sentry'; export class RavenClient { constructor(dsn, options) { @@ -52,7 +52,7 @@ export class RavenClient { }); Raven.setBreadcrumbCallback(Sentry._breadcrumbCallback); const oldCaptureBreadcrumb = Raven.captureBreadcrumb; - Raven.captureBreadcrumb = function(obj) { + Raven.captureBreadcrumb = function (obj) { if (obj.data && typeof obj.data === 'object') { obj.data = Object.assign({}, obj.data); } @@ -97,6 +97,10 @@ export class RavenClient { Raven.setRelease(release); } + setEnvironment(environment) { + Raven.setEnvironment(environment); + } + clearContext() { return Raven.clearContext(); } diff --git a/lib/Sentry.d.ts b/lib/Sentry.d.ts index 32a39948de..da26d4c227 100644 --- a/lib/Sentry.d.ts +++ b/lib/Sentry.d.ts @@ -100,6 +100,8 @@ export class Sentry { static setRelease(release: string): void; + static setEnvironment(environment: string): void; + static setDist(dist: string): void; static setVersion(version: string): void; diff --git a/lib/Sentry.js b/lib/Sentry.js index 3f94e9dfbb..87d31db10b 100644 --- a/lib/Sentry.js +++ b/lib/Sentry.js @@ -1,8 +1,8 @@ -import {NativeModules, NativeEventEmitter} from 'react-native'; -const {RNSentry, RNSentryEventEmitter} = NativeModules; +import { NativeModules, NativeEventEmitter } from 'react-native'; +const { RNSentry, RNSentryEventEmitter } = NativeModules; -import {RavenClient} from './RavenClient'; -import {NativeClient} from './NativeClient'; +import { RavenClient } from './RavenClient'; +import { NativeClient } from './NativeClient'; export const SentrySeverity = { Fatal: 'fatal', @@ -176,6 +176,12 @@ export const Sentry = { if (Sentry._ravenClient) Sentry._ravenClient.setRelease(release); }, + setEnvironment(environment) { + Sentry._log('react-native-sentry (setEnvironment)'); + Sentry._setInternalOption('environment', environment); + if (Sentry._ravenClient) Sentry._ravenClient.setEnvironment(environment); + }, + setDist(dist) { Sentry._setInternalOption('dist', dist); },