Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Add custom sentry tags #103

Merged
merged 1 commit into from
May 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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