Skip to content

Commit

Permalink
Add custom sentry tags (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster authored and freyacodes committed May 20, 2018
1 parent 315804f commit 8e0e26e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
7 changes: 6 additions & 1 deletion LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ lavalink:
mixer: true
http: true
local: false
sentryDsn: ""
bufferDurationMs: 400
youtubePlaylistLoadLimit: 600

sentry:
dsn: ""
# tags:
# some_key: some_value
# another_key: another_value

logging:
file:
max-history: 30
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package lavalink.server.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
* Created by napster on 20.05.18.
*/
@Component
@ConfigurationProperties(prefix = "sentry")
public class SentryConfigProperties {

private String dsn = "";
private Map<String, String> tags = new HashMap<>();

public String getDsn() {
return dsn;
}

public void setDsn(String dsn) {
this.dsn = dsn;
}

public Map<String, String> getTags() {
return tags;
}

public void setTags(Map<String, String> tags) {
this.tags = tags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.Map;
import java.util.Properties;

/**
Expand All @@ -23,20 +24,36 @@ public class SentryConfiguration {
private static final Logger log = LoggerFactory.getLogger(SentryConfiguration.class);
private static final String SENTRY_APPENDER_NAME = "SENTRY";

public SentryConfiguration(ServerConfig serverConfig) {
String sentryDsn = serverConfig.getSentryDsn();
if (sentryDsn != null && !sentryDsn.isEmpty()) {
turnOn(sentryDsn);
public SentryConfiguration(ServerConfig serverConfig, SentryConfigProperties sentryConfig) {

String dsn = sentryConfig.getDsn();
boolean warnDeprecatedDsnConfig = false;
if (dsn == null || dsn.isEmpty()) {
//try deprecated config location
dsn = serverConfig.getSentryDsn();
warnDeprecatedDsnConfig = true;
}

if (dsn != null && !dsn.isEmpty()) {
turnOn(dsn, sentryConfig.getTags());
if (warnDeprecatedDsnConfig) {
log.warn("Please update the location of the sentry dsn in lavalinks config file / your environment "
+ "vars, it is now located under 'sentry.dsn' instead of 'lavalink.server.sentryDsn'.");
}
} else {
turnOff();
}
}


public void turnOn(String dsn) {
public void turnOn(String dsn, Map<String, String> tags) {
log.info("Turning on sentry");
SentryClient sentryClient = Sentry.init(dsn);

if (tags != null) {
tags.forEach(sentryClient::addTag);
}

// set the git commit hash this was build on as the release
Properties gitProps = new Properties();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public void setPassword(String password) {

private String sentryDsn = "";

/**
* @deprecated use {@link SentryConfigProperties} instead.
*/
@Deprecated(since = "3")
public String getSentryDsn() {
return sentryDsn;
}
Expand Down

0 comments on commit 8e0e26e

Please sign in to comment.