Skip to content

Commit

Permalink
Merge pull request #12082 from chamikasudusinghe/zipkins
Browse files Browse the repository at this point in the history
Added reconfigurable newrelic endpoint url
  • Loading branch information
npamudika authored Jul 13, 2023
2 parents 3b275a2 + 5721da1 commit d39d62f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

@Deprecated
class TracingConstants {

/**
* OpenTracer Constants
* */
Expand Down Expand Up @@ -65,6 +64,11 @@ class TracingConstants {
static final String ZIPKIN = "ZIPKIN";
static final String ZIPKIN_CONFIG_PORT = "OpenTracer.RemoteTracer.Properties.Port";
static final String ZIPKIN_CONFIG_HOST = "OpenTracer.RemoteTracer.Properties.HostName";
static final String ZIPKIN_CONFIG_PROXY_HOST = "OpenTracer.RemoteTracer.Properties.ProxyHost";
static final String ZIPKIN_CONFIG_PROXY_PORT = "OpenTracer.RemoteTracer.Properties.ProxyPort";
static final String ZIPKIN_CONFIG_ENDPOINT_URL
= "OpenTracer.RemoteTracer.Properties.EndpointUrl";

static final String REQUEST_ID = "request-id";

static final int ZIPKIN_DEFAULT_PORT = 9411;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.okhttp3.OkHttpSender;

import java.net.InetSocketAddress;
import java.net.Proxy;

/**
* Class for getting Zipkin tracer from reading configuration file
* @deprecated
Expand All @@ -49,21 +52,38 @@ public class ZipkinTracer implements OpenTracer {
@Override
public Tracer getTracer(String serviceName) {

String hostname = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) != null ?
configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST)
: TracingConstants.ZIPKIN_DEFAULT_HOST;

int port = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT) != null ?
Integer.parseInt(configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT))
: TracingConstants.ZIPKIN_DEFAULT_PORT;

boolean tracerLogEnabled =
Boolean.parseBoolean(configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED) != null
? configuration.getFirstProperty(TracingConstants.CONFIG_TRACER_LOG_ENABLED)
: TracingConstants.DEFAULT_TRACER_LOG_ENABLED);

OkHttpSender sender =
OkHttpSender.create("http://" + hostname + ":" + port + TracingConstants.ZIPKIN_API_CONTEXT);
String hostname = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST) != null
? configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_HOST)
: TracingConstants.ZIPKIN_DEFAULT_HOST;

int port = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT) != null
? Integer.parseInt(configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PORT))
: TracingConstants.ZIPKIN_DEFAULT_PORT;

// Read the configurable endpoint and format the endpoint based on whether is configurable or not
String endpoint = configuration
.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_ENDPOINT_URL) != null
? configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_ENDPOINT_URL)
: "http://" + hostname + ":" + port + TracingConstants.ZIPKIN_API_CONTEXT;

// Read proxy configurations from the configuration file.
String proxyHost = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PROXY_HOST);
String proxyPort = configuration.getFirstProperty(TracingConstants.ZIPKIN_CONFIG_PROXY_PORT);
OkHttpSender sender;
if (proxyHost != null && !proxyHost.isEmpty() && proxyPort != null && !proxyPort.isEmpty()) {
// Configure proxy if the proxy configurations are available.
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
OkHttpSender.Builder builder = OkHttpSender.newBuilder().endpoint(endpoint);
builder.clientBuilder().proxy(proxy);
sender = builder.build();
} else {
sender = OkHttpSender.create(endpoint);
}
Tracer tracer = BraveTracer.create(Tracing.newBuilder()
.localServiceName(serviceName)
.spanReporter(AsyncReporter.builder(sender).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
"apim.open_tracer.remote_tracer.name": "zipkin",
"apim.open_tracer.remote_tracer.properties.hostname": "localhost",
"apim.open_tracer.remote_tracer.properties.port": "9411",
"apim.open_tracer.remote_tracer.properties.proxy_host": "",
"apim.open_tracer.remote_tracer.properties.proxy_port": "",
"apim.open_tracer.remote_tracer.properties.endpoint_url": "",
"apim.open_tracer.log_tracer.enable": false,
"apim.sdk.group_id": "org.wso2",
"apim.sdk.artifact_id": "org.wso2.client.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,14 @@
{% endif %}
{% if apim.open_tracer.remote_tracer.properties.sampler_param is defined %}
<SamplerParam>{{apim.open_tracer.remote_tracer.properties.sampler_param}}</SamplerParam>
{% if apim.open_tracer.remote_tracer.properties.proxy_host is defined %}
<ProxyHost>{{apim.open_tracer.remote_tracer.properties.proxy_host}}</ProxyHost>
{% endif %}
{% if apim.open_tracer.remote_tracer.properties.proxy_port is defined %}
<ProxyPort>{{apim.open_tracer.remote_tracer.properties.proxy_port}}</ProxyPort>
{% endif %}
{% if apim.open_tracer.remote_tracer.properties.endpoint_url is defined %}
<EndpointUrl>{{apim.open_tracer.remote_tracer.properties.endpoint_url}}</EndpointUrl>
{% endif %}
</Properties>
</RemoteTracer>
Expand Down

0 comments on commit d39d62f

Please sign in to comment.