Skip to content

Commit

Permalink
Add release to sentry for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jobachhu committed Nov 11, 2018
1 parent fd28e1c commit 939c536
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
26 changes: 26 additions & 0 deletions view/src/main/java/org/xcolab/view/theme/ServerVariables.java
@@ -0,0 +1,26 @@
package org.xcolab.view.theme;

import org.xcolab.client.admin.attributes.platform.PlatformAttributeKey;
import org.xcolab.client.admin.enums.ServerEnvironment;
import org.xcolab.commons.servlet.ManifestUtil;

import javax.servlet.ServletContext;

public class ServerVariables {

private final ServerEnvironment environment;
private final String buildCommit;

public ServerVariables(ServletContext servletContext) {
environment = PlatformAttributeKey.SERVER_ENVIRONMENT.get();
buildCommit = ManifestUtil.getBuildCommit(servletContext).orElse("unknown");
}

public ServerEnvironment getEnvironment() {
return environment;
}

public String getBuildCommit() {
return buildCommit;
}
}
18 changes: 7 additions & 11 deletions view/src/main/java/org/xcolab/view/theme/ThemeContext.java
Expand Up @@ -3,7 +3,6 @@
import org.xcolab.client.admin.ContestTypeClient;
import org.xcolab.client.admin.attributes.configuration.ConfigurationAttributeKey;
import org.xcolab.client.admin.attributes.platform.PlatformAttributeKey;
import org.xcolab.client.admin.enums.ServerEnvironment;
import org.xcolab.client.admin.pojo.ContestType;
import org.xcolab.commons.http.servlet.RequestUtil;
import org.xcolab.view.auth.AuthenticationService;
Expand All @@ -20,10 +19,7 @@ public class ThemeContext {
private final MetaVariables metaVariables;
private final MessageVariables messageVariables;
private final SocialMediaVariables socialMediaVariables;

private final ServerEnvironment serverEnvironment;
// public boolean isProductionEnvironment;
// Now use: serverEnvironment.isProduction()
private final ServerVariables serverVariables;

private final String colabName;
private final String colabLongName;
Expand All @@ -38,6 +34,7 @@ public class ThemeContext {

public ThemeContext(AuthenticationService authenticationService, SsoServices ssoServices,
HttpServletRequest request) {

this.i18NVariables = new I18nVariables();
this.authenticationVariables = new AuthenticationVariables(authenticationService,
ssoServices, request);
Expand All @@ -46,8 +43,7 @@ public ThemeContext(AuthenticationService authenticationService, SsoServices sso
this.metaVariables = new MetaVariables(request, this.getI18NVariables());
this.messageVariables = new MessageVariables(request);
this.socialMediaVariables = new SocialMediaVariables(request);

this.serverEnvironment = PlatformAttributeKey.SERVER_ENVIRONMENT.get();
this.serverVariables = new ServerVariables(request.getServletContext());

this.colabName = ConfigurationAttributeKey.COLAB_NAME.get();
this.colabLongName = ConfigurationAttributeKey.COLAB_LONG_NAME.get();
Expand Down Expand Up @@ -95,10 +91,6 @@ public SocialMediaVariables getSocialMediaVariables() {
return socialMediaVariables;
}

public ServerEnvironment getServerEnvironment() {
return serverEnvironment;
}

public String getColabName() {
return colabName;
}
Expand Down Expand Up @@ -134,4 +126,8 @@ public ContestType getDefaultContestType() {
public String getRequestUri() {
return requestUri;
}

public ServerVariables getServerVariables() {
return serverVariables;
}
}
2 changes: 1 addition & 1 deletion view/src/main/webapp/WEB-INF/jsp/error.jspx
Expand Up @@ -67,7 +67,7 @@
</c:otherwise>
</c:choose>

<c:if test="${_themeContext.authenticationVariables.isAdmin or !_themeContext.serverEnvironment.isProduction}">
<c:if test="${_themeContext.authenticationVariables.isAdmin or !_themeContext.serverVariables.environment.isProduction}">
<div class="alert alert-info mt-3" role="alert">
<h2>Admin Error Details:</h2>
<div>Status: ${status}</div>
Expand Down
45 changes: 23 additions & 22 deletions view/src/main/webapp/WEB-INF/tags/layout.tagx
Expand Up @@ -98,7 +98,7 @@
<meta content="${_themeContext.metaVariables.metaPageKeywords}" lang="en-US" name="keywords" />

<c:choose>
<c:when test="${!_themeContext.serverEnvironment.isProduction}">
<c:when test="${!_themeContext.serverVariables.environment.isProduction}">
<!-- Prevent indexing of non-production sites -->
<meta name="robots" content="noindex, nofollow" />
<script>
Expand Down Expand Up @@ -151,7 +151,7 @@
<link rel="canonical" href="${_themeContext.colabUrl}${canonicalUrlRelative}" />
</c:if>

<c:if test="${_themeContext.serverEnvironment.isProduction}">
<c:if test="${_themeContext.serverVariables.environment.isProduction}">
<xcolab-scripts:analyticsScripts googleAnalyticsKey="${_themeContext.credentialVariables.googleAnalyticsKey}"
pingdomRumId="${_themeContext.credentialVariables.pingdomRumId}"
analyticsAttribute="${_themeContext.messageVariables.analyticsAttribute}"
Expand All @@ -160,6 +160,25 @@

<c:if test="${not empty _themeContext.credentialVariables.sentryDsn}">
<script src="https://js.sentry-cdn.com/${_themeContext.credentialVariables.sentryDsn}.min.js" crossorigin="anonymous"><!-- --></script>
<script>
Sentry.onLoad(function() {
var options = {
environment: '${_themeContext.serverVariables.environment.name().toLowerCase()}'
};
var release = '${_themeContext.serverVariables.buildCommit}';
if (release != 'unknown') {
options.release = release;
}
Sentry.init(options);

Sentry.configureScope(function(scope) {
scope.setTag("language", "${_themeContext.i18NVariables.language}");
if (_isLoggedIn) {
scope.setUser({"id": "${_themeContext.authenticationVariables.member.id}"});
}
});
});
</script>
</c:if>
</head>

Expand All @@ -170,7 +189,7 @@
</div>
</c:if>

<c:if test="${!_themeContext.serverEnvironment.isProduction}">
<c:if test="${!_themeContext.serverVariables.environment.isProduction}">
<div class="c-TitleBar__container">
<div class="c-TitleBar c-TitleBar--warning c-TitleBar--fixed">
<div class="container c-TitleBar__content">
Expand Down Expand Up @@ -326,7 +345,7 @@
<!-- Bootstrap -->
<collab:script src="/vendor/popper.js/dist/umd/popper.min.js" />
<c:choose>
<c:when test="${_themeContext.serverEnvironment.isProductionOrStaging}">
<c:when test="${_themeContext.serverVariables.environment.isProductionOrStaging}">
<collab:script src="/vendor/bootstrap/dist/js/bootstrap.min.js" />
</c:when>
<c:otherwise>
Expand Down Expand Up @@ -412,24 +431,6 @@
<!-- Show update notification to outdated browsers -->
<xcolab-scripts:browserUpdate />

<c:if test="${not empty _themeContext.credentialVariables.sentryDsn}">
<script>
Sentry.onLoad(function() {
Sentry.init({
environment: '${_themeContext.serverEnvironment.name().toLowerCase()}',
// release: ''
});

Sentry.configureScope(function(scope) {
scope.setTag("language", "${_themeContext.i18NVariables.language}");
if (_isLoggedIn) {
scope.setUser({"id": "${_themeContext.authenticationVariables.member.id}"});
}
});
});
</script>
</c:if>


<!-- ============ Structured data (schema.org) ============ -->

Expand Down

0 comments on commit 939c536

Please sign in to comment.