use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.
the class TracingStatementInterceptor method parseServerAddress.
/**
* MySQL exposes the host connecting to, but not the port. This attempts to get the port from the
* JDBC URL. Ex. 5555 from {@code jdbc:mysql://localhost:5555/database}, or 3306 if absent.
*/
static void parseServerAddress(Connection connection, Span span) {
try {
// strip "jdbc:"
URI url = URI.create(connection.getMetaData().getURL().substring(5));
int port = url.getPort() == -1 ? 3306 : url.getPort();
String remoteServiceName = connection.getProperties().getProperty("zipkinServiceName");
if (remoteServiceName == null || "".equals(remoteServiceName)) {
String databaseName = connection.getCatalog();
if (databaseName != null && !databaseName.isEmpty()) {
remoteServiceName = "mysql-" + databaseName;
} else {
remoteServiceName = "mysql";
}
}
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(remoteServiceName).port(port);
if (!builder.parseIp(connection.getHost()))
return;
span.remoteEndpoint(builder.build());
} catch (Exception e) {
// remote address is optional
}
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.
the class TracingJdbcEventListener method parseServerAddress.
/**
* This attempts to get the ip and port from the JDBC URL. Ex. localhost and 5555 from {@code
* jdbc:mysql://localhost:5555/mydatabase}.
*/
void parseServerAddress(Connection connection, Span span) {
try {
// strip "jdbc:"
final String urlAsString = connection.getMetaData().getURL().substring(5);
// Remove all white space according to RFC 2396
URI url = URI.create(urlAsString.replace(" ", ""));
String defaultRemoteServiceName = remoteServiceName;
Matcher matcher = URL_SERVICE_NAME_FINDER.matcher(url.toString());
if (matcher.find() && matcher.groupCount() == 1) {
String parsedServiceName = matcher.group(1);
if (parsedServiceName != null && !parsedServiceName.isEmpty()) {
// Do not override global service name if parsed service name is invalid
defaultRemoteServiceName = parsedServiceName;
}
}
Endpoint.Builder builder = Endpoint.newBuilder();
int port = url.getPort();
if (port > 0)
builder.port(port);
boolean parsed = builder.parseIp(url.getHost());
if (defaultRemoteServiceName == null || "".equals(defaultRemoteServiceName)) {
String databaseName = connection.getCatalog();
if (databaseName != null && !databaseName.isEmpty()) {
builder.serviceName(databaseName);
} else {
if (!parsed)
return;
}
} else {
builder.serviceName(defaultRemoteServiceName);
}
span.remoteEndpoint(builder.build());
} catch (Exception e) {
// remote address is optional
}
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project brave by openzipkin.
the class Platform method produceEndpoint.
Endpoint produceEndpoint() {
Endpoint.Builder builder = Endpoint.newBuilder().serviceName("unknown");
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
if (nics == null)
return builder.build();
while (nics.hasMoreElements()) {
NetworkInterface nic = nics.nextElement();
Enumeration<InetAddress> addresses = nic.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (address.isSiteLocalAddress()) {
builder.ip(address);
break;
}
}
}
} catch (Exception e) {
// don't crash the caller if there was a problem reading nics.
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "error reading nics", e);
}
}
return builder.build();
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandler method produceLocalEndpoint.
/**
* Logic borrowed from brave.internal.Platform.produceLocalEndpoint
*/
static Endpoint produceLocalEndpoint(String serviceName) {
Endpoint.Builder builder = Endpoint.newBuilder().serviceName(serviceName);
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
if (nics == null) {
return builder.build();
}
while (nics.hasMoreElements()) {
NetworkInterface nic = nics.nextElement();
Enumeration<InetAddress> addresses = nic.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (address.isSiteLocalAddress()) {
builder.ip(address);
break;
}
}
}
} catch (Exception e) {
// don't crash the caller if there was a problem reading nics.
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "error reading nics", e);
}
}
return builder.build();
}
use of zipkin2.elasticsearch.ElasticsearchStorage.Builder in project zipkin by openzipkin.
the class ITActiveMQCollector method skipsOnSpanStorageException.
/**
* Guards against errors that leak from storage, such as InvalidQueryException
*/
@Test
public void skipsOnSpanStorageException() throws Exception {
collector.close();
AtomicInteger counter = new AtomicInteger();
consumer = (input) -> new Call.Base<Void>() {
@Override
protected Void doExecute() {
throw new AssertionError();
}
@Override
protected void doEnqueue(Callback<Void> callback) {
if (counter.getAndIncrement() == 1) {
callback.onError(new RuntimeException("storage fell over"));
} else {
receivedSpans.add(spans);
callback.onSuccess(null);
}
}
@Override
public Call<Void> clone() {
throw new AssertionError();
}
};
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
// tossed on error
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
activemq.pushMessage(collector.queue, PROTO3.encodeList(spans));
collector = builder().storage(buildStorage(consumer)).build().start();
assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
// the only way we could read this, is if the malformed span was skipped.
assertThat(receivedSpans.take()).containsExactlyElementsOf(spans);
assertThat(activemqMetrics.messages()).isEqualTo(3);
// storage failure not message failure
assertThat(activemqMetrics.messagesDropped()).isZero();
assertThat(activemqMetrics.bytes()).isEqualTo(PROTO3.encodeList(spans).length * 3);
assertThat(activemqMetrics.spans()).isEqualTo(spans.size() * 3);
// only one dropped
assertThat(activemqMetrics.spansDropped()).isEqualTo(spans.size());
}
Aggregations