Skip to content

Commit 6ee8f6e

Browse files
author
Mateusz Rzeszutek
committed
Enable sending traces directly to ingest
1 parent cfe687f commit 6ee8f6e

File tree

6 files changed

+131
-10
lines changed

6 files changed

+131
-10
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ System property values take priority over corresponding environment variables.
8989

9090
A simple wrapper for the Jaeger exporter of opentelemetry-java. gRPC is currently the only supported communications protocol.
9191

92-
| System property | Environment variable | Description |
93-
|-----------------------------------|-----------------------------------|----------------------------------------------------------------------------------------------------|
94-
| otel.exporter=jaeger | OTEL_EXPORTER=jaeger | Select the Jaeger exporter |
95-
| otel.exporter.jaeger.endpoint | OTEL_EXPORTER_JAEGER_ENDPOINT | The Jaeger endpoint to connect to. Default is `localhost:14250`. Currently only gRPC is supported. |
96-
| otel.exporter.jaeger.service.name | OTEL_EXPORTER_JAEGER_SERVICE_NAME | The service name of this JVM instance. Default is `unknown`. |
92+
| System property | Environment variable | Description |
93+
|-----------------------------------|-----------------------------------|---------------------------------------------------------------------------------------------------------------------|
94+
| otel.exporter=jaeger | OTEL_EXPORTER=jaeger | Select the Jaeger exporter |
95+
| otel.exporter.jaeger.endpoint | OTEL_EXPORTER_JAEGER_ENDPOINT | The Jaeger endpoint to connect to. Default is `localhost:14250`. Currently only gRPC is supported. |
96+
| otel.exporter.jaeger.service.name | OTEL_EXPORTER_JAEGER_SERVICE_NAME | The service name of this JVM instance. Default is `unknown`. |
97+
| signalfx.auth.token | SIGNALFX_AUTH_TOKEN | Auth token allowing to communicate directly with the Splunk cloud, passed as `X-SF-TOKEN` header. Default is empty. |
9798

9899
### Trace configuration
99100

agent/src/main/java/com/splunk/opentelemetry/SplunkAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void premain(final String agentArgs, final Instrumentation inst) {
2828
}
2929

3030
public static void agentmain(final String agentArgs, final Instrumentation inst) {
31-
setDefaultConfig("otel.exporter", "jaeger-thrift");
31+
setDefaultConfig("otel.exporter", "jaeger-thrift-splunk");
3232
// http://localhost:9080/v1/trace is the default endpoint for SmartAgent
3333
// http://localhost:14268/api/traces is the default endpoint for otel-collector
3434
setDefaultConfig("otel.exporter.jaeger.endpoint", "http://localhost:9080/v1/trace");

custom/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
implementation("io.opentelemetry:opentelemetry-sdk:${versions["opentelemetry"]}")
1010
implementation("io.opentelemetry:opentelemetry-exporter-jaeger-thrift:${versions["opentelemetry"]}")
1111
implementation("io.opentelemetry.javaagent:opentelemetry-javaagent-spi:${versions["opentelemetryJavaagent"]}")
12+
implementation("io.jaegertracing:jaeger-client:1.5.0")
1213
}
1314

1415
tasks {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.splunk.opentelemetry.jaeger;
18+
19+
import static java.util.Objects.requireNonNull;
20+
21+
import java.io.IOException;
22+
import okhttp3.Interceptor;
23+
import okhttp3.Request;
24+
import okhttp3.Response;
25+
26+
class AuthTokenInterceptor implements Interceptor {
27+
static final String TOKEN_HEADER = "X-SF-TOKEN";
28+
29+
private final String signalfxAuthToken;
30+
31+
AuthTokenInterceptor(String token) {
32+
this.signalfxAuthToken = requireNonNull(token);
33+
}
34+
35+
@Override
36+
public Response intercept(Chain chain) throws IOException {
37+
Request request = chain.request();
38+
request = request.newBuilder().addHeader(TOKEN_HEADER, signalfxAuthToken).build();
39+
return chain.proceed(request);
40+
}
41+
}

custom/src/main/java/com/splunk/opentelemetry/jaeger/JaegerThriftSpanExporterFactory.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,47 @@
1616

1717
package com.splunk.opentelemetry.jaeger;
1818

19+
import io.jaegertracing.thrift.internal.senders.HttpSender;
1920
import io.opentelemetry.exporter.jaeger.thrift.JaegerThriftSpanExporter;
2021
import io.opentelemetry.javaagent.spi.exporter.SpanExporterFactory;
2122
import io.opentelemetry.sdk.trace.export.SpanExporter;
2223
import java.util.Collections;
2324
import java.util.Properties;
2425
import java.util.Set;
26+
import okhttp3.OkHttpClient;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2529

26-
// TODO remove when https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1609
27-
// is implemented
2830
public class JaegerThriftSpanExporterFactory implements SpanExporterFactory {
31+
private static final Logger log = LoggerFactory.getLogger(JaegerThriftSpanExporterFactory.class);
32+
33+
static final String SIGNALFX_AUTH_TOKEN = "signalfx.auth.token";
34+
static final String OTEL_EXPORTER_JAEGER_ENDPOINT = "otel.exporter.jaeger.endpoint";
35+
2936
@Override
3037
public SpanExporter fromConfig(Properties config) {
31-
return JaegerThriftSpanExporter.builder().readProperties(config).build();
38+
JaegerThriftSpanExporter.Builder builder =
39+
JaegerThriftSpanExporter.builder().readProperties(config);
40+
41+
String token = config.getProperty(SIGNALFX_AUTH_TOKEN, "");
42+
if (!token.isEmpty()) {
43+
log.debug("Using authenticated jaeger-thrift exporter");
44+
builder.setThriftSender(
45+
new HttpSender.Builder(config.getProperty(OTEL_EXPORTER_JAEGER_ENDPOINT))
46+
.withClient(
47+
new OkHttpClient.Builder()
48+
.addInterceptor(new AuthTokenInterceptor(token))
49+
.build())
50+
.build());
51+
} else {
52+
log.debug("Using jaeger-thrift exporter without authentication");
53+
}
54+
55+
return builder.build();
3256
}
3357

3458
@Override
3559
public Set<String> getNames() {
36-
return Collections.singleton("jaeger-thrift");
60+
return Collections.singleton("jaeger-thrift-splunk");
3761
}
3862
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Splunk Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.splunk.opentelemetry.jaeger;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.mockito.BDDMockito.given;
21+
import static org.mockito.BDDMockito.then;
22+
23+
import java.io.IOException;
24+
import okhttp3.Interceptor;
25+
import okhttp3.Interceptor.Chain;
26+
import okhttp3.Request;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.extension.ExtendWith;
29+
import org.mockito.ArgumentCaptor;
30+
import org.mockito.Captor;
31+
import org.mockito.Mock;
32+
import org.mockito.junit.jupiter.MockitoExtension;
33+
34+
@ExtendWith(MockitoExtension.class)
35+
class AuthTokenInterceptorTest {
36+
@Mock Chain chain;
37+
@Captor ArgumentCaptor<Request> requestCaptor;
38+
39+
Interceptor interceptor = new AuthTokenInterceptor("token");
40+
41+
@Test
42+
void shouldAddSignalFxToken() throws IOException {
43+
// given
44+
var request = new Request.Builder().url("http://test").build();
45+
given(chain.request()).willReturn(request);
46+
47+
// when
48+
interceptor.intercept(chain);
49+
50+
// then
51+
then(chain).should().proceed(requestCaptor.capture());
52+
assertEquals("token", requestCaptor.getValue().header(AuthTokenInterceptor.TOKEN_HEADER));
53+
}
54+
}

0 commit comments

Comments
 (0)