Last instrumentation conversion to OpenTelemetry API and remove prior agent API (#128)
* Convert OkHttp3 to use OpenTelemetry API directly * Remove Agent API
This commit is contained in:
parent
3a4b2a9b95
commit
1440d95fb5
|
@ -1,19 +0,0 @@
|
||||||
package io.opentelemetry.auto.instrumentation.api;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public interface AgentPropagation {
|
|
||||||
|
|
||||||
<C> void inject(AgentSpan span, C carrier, Setter<C> setter);
|
|
||||||
|
|
||||||
interface Setter<C> {
|
|
||||||
void set(C carrier, String key, String value);
|
|
||||||
}
|
|
||||||
|
|
||||||
<C> AgentSpan.Context extract(C carrier, Getter<C> getter);
|
|
||||||
|
|
||||||
interface Getter<C> {
|
|
||||||
Iterable<String> keys(C carrier);
|
|
||||||
|
|
||||||
String get(C carrier, String key);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package io.opentelemetry.auto.instrumentation.api;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public interface AgentScope extends Closeable {
|
|
||||||
AgentSpan span();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void close();
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package io.opentelemetry.auto.instrumentation.api;
|
|
||||||
|
|
||||||
import io.opentelemetry.trace.Span;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public interface AgentSpan {
|
|
||||||
AgentSpan setAttribute(String key, boolean value);
|
|
||||||
|
|
||||||
AgentSpan setAttribute(String key, int value);
|
|
||||||
|
|
||||||
AgentSpan setAttribute(String key, long value);
|
|
||||||
|
|
||||||
AgentSpan setAttribute(String key, double value);
|
|
||||||
|
|
||||||
AgentSpan setAttribute(String key, String value);
|
|
||||||
|
|
||||||
AgentSpan setError(boolean error);
|
|
||||||
|
|
||||||
AgentSpan setErrorMessage(String errorMessage);
|
|
||||||
|
|
||||||
AgentSpan addThrowable(Throwable throwable);
|
|
||||||
|
|
||||||
Context context();
|
|
||||||
|
|
||||||
void finish();
|
|
||||||
|
|
||||||
String getSpanName();
|
|
||||||
|
|
||||||
void setSpanName(String spanName);
|
|
||||||
|
|
||||||
Span getSpan();
|
|
||||||
|
|
||||||
interface Context {}
|
|
||||||
}
|
|
|
@ -1,219 +0,0 @@
|
||||||
package io.opentelemetry.auto.instrumentation.api;
|
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan.Context;
|
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
|
||||||
import io.opentelemetry.trace.Span;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class AgentTracer {
|
|
||||||
|
|
||||||
// Implicit parent
|
|
||||||
public static AgentSpan startSpan(final String spanName) {
|
|
||||||
return get().startSpan(spanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implicit parent
|
|
||||||
public static AgentSpan startSpan(final String spanName, final long startTimeMicros) {
|
|
||||||
return get().startSpan(spanName, startTimeMicros);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit parent
|
|
||||||
public static AgentSpan startSpan(final String spanName, final AgentSpan.Context parent) {
|
|
||||||
return get().startSpan(spanName, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit parent
|
|
||||||
public static AgentSpan startSpan(
|
|
||||||
final String spanName, final AgentSpan.Context parent, final long startTimeMicros) {
|
|
||||||
return get().startSpan(spanName, parent, startTimeMicros);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AgentScope activateSpan(final AgentSpan span, final boolean finishSpanOnClose) {
|
|
||||||
return get().activateSpan(span, finishSpanOnClose);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AgentSpan activeSpan() {
|
|
||||||
return get().activeSpan();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AgentPropagation propagate() {
|
|
||||||
return get().propagate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AgentSpan noopSpan() {
|
|
||||||
return get().noopSpan();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final TracerAPI DEFAULT = new NoopTracerAPI();
|
|
||||||
|
|
||||||
private static final AtomicReference<TracerAPI> provider = new AtomicReference<>(DEFAULT);
|
|
||||||
|
|
||||||
public static void registerIfAbsent(final TracerAPI trace) {
|
|
||||||
provider.compareAndSet(DEFAULT, trace);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TracerAPI get() {
|
|
||||||
return provider.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not intended to be constructed.
|
|
||||||
private AgentTracer() {}
|
|
||||||
|
|
||||||
public interface TracerAPI {
|
|
||||||
AgentSpan startSpan(String spanName);
|
|
||||||
|
|
||||||
AgentSpan startSpan(String spanName, long startTimeMicros);
|
|
||||||
|
|
||||||
AgentSpan startSpan(String spanName, AgentSpan.Context parent);
|
|
||||||
|
|
||||||
AgentSpan startSpan(String spanName, AgentSpan.Context parent, long startTimeMicros);
|
|
||||||
|
|
||||||
AgentScope activateSpan(AgentSpan span, boolean finishSpanOnClose);
|
|
||||||
|
|
||||||
AgentSpan activeSpan();
|
|
||||||
|
|
||||||
AgentPropagation propagate();
|
|
||||||
|
|
||||||
AgentSpan noopSpan();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class NoopTracerAPI implements TracerAPI {
|
|
||||||
|
|
||||||
protected NoopTracerAPI() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName) {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName, final long startTimeMicros) {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName, final Context parent) {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(
|
|
||||||
final String spanName, final Context parent, final long startTimeMicros) {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentScope activateSpan(final AgentSpan span, final boolean finishSpanOnClose) {
|
|
||||||
return NoopAgentScope.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan activeSpan() {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentPropagation propagate() {
|
|
||||||
return NoopAgentPropagation.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan noopSpan() {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class NoopAgentSpan implements AgentSpan {
|
|
||||||
static final NoopAgentSpan INSTANCE = new NoopAgentSpan();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final boolean value) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final int value) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final long value) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final double value) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final String value) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setError(final boolean error) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setErrorMessage(final String errorMessage) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan addThrowable(final Throwable throwable) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Context context() {
|
|
||||||
return NoopContext.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finish() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSpanName() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSpanName(final String spanName) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Span getSpan() {
|
|
||||||
return DefaultSpan.getInvalid();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NoopAgentScope implements AgentScope {
|
|
||||||
public static final NoopAgentScope INSTANCE = new NoopAgentScope();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan span() {
|
|
||||||
return NoopAgentSpan.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class NoopAgentPropagation implements AgentPropagation {
|
|
||||||
static final NoopAgentPropagation INSTANCE = new NoopAgentPropagation();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <C> void inject(final AgentSpan span, final C carrier, final Setter<C> setter) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <C> Context extract(final C carrier, final Getter<C> getter) {
|
|
||||||
return NoopContext.INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class NoopContext implements Context {
|
|
||||||
static final NoopContext INSTANCE = new NoopContext();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,5 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentScope;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
@ -23,12 +21,6 @@ public abstract class BaseDecorator {
|
||||||
|
|
||||||
protected abstract String getComponentName();
|
protected abstract String getComponentName();
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan afterStart(final AgentSpan span) {
|
|
||||||
afterStart(span.getSpan());
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span afterStart(final Span span) {
|
public Span afterStart(final Span span) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
final String spanType = getSpanType();
|
final String spanType = getSpanType();
|
||||||
|
@ -42,37 +34,11 @@ public abstract class BaseDecorator {
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentScope beforeFinish(final AgentScope scope) {
|
|
||||||
assert scope != null;
|
|
||||||
beforeFinish(scope.span());
|
|
||||||
return scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan beforeFinish(final AgentSpan span) {
|
|
||||||
beforeFinish(span.getSpan());
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span beforeFinish(final Span span) {
|
public Span beforeFinish(final Span span) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentScope onError(final AgentScope scope, final Throwable throwable) {
|
|
||||||
assert scope != null;
|
|
||||||
onError(scope.span(), throwable);
|
|
||||||
return scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onError(final AgentSpan span, final Throwable throwable) {
|
|
||||||
onError(span.getSpan(), throwable);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onError(final Span span, final Throwable throwable) {
|
public Span onError(final Span span, final Throwable throwable) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
|
@ -83,13 +49,6 @@ public abstract class BaseDecorator {
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onPeerConnection(
|
|
||||||
final AgentSpan span, final InetSocketAddress remoteConnection) {
|
|
||||||
onPeerConnection(span.getSpan(), remoteConnection);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onPeerConnection(final Span span, final InetSocketAddress remoteConnection) {
|
public Span onPeerConnection(final Span span, final InetSocketAddress remoteConnection) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (remoteConnection != null) {
|
if (remoteConnection != null) {
|
||||||
|
@ -101,12 +60,6 @@ public abstract class BaseDecorator {
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onPeerConnection(final AgentSpan span, final InetAddress remoteAddress) {
|
|
||||||
onPeerConnection(span.getSpan(), remoteAddress);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onPeerConnection(final Span span, final InetAddress remoteAddress) {
|
public Span onPeerConnection(final Span span, final InetAddress remoteAddress) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (remoteAddress != null) {
|
if (remoteAddress != null) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
@ -13,13 +12,6 @@ public abstract class ClientDecorator extends BaseDecorator {
|
||||||
return Tags.SPAN_KIND_CLIENT;
|
return Tags.SPAN_KIND_CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public AgentSpan afterStart(final AgentSpan span) {
|
|
||||||
afterStart(span.getSpan());
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Span afterStart(final Span span) {
|
public Span afterStart(final Span span) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.config.Config;
|
import io.opentelemetry.auto.config.Config;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
@ -14,13 +13,6 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
||||||
|
|
||||||
protected abstract String dbInstance(CONNECTION connection);
|
protected abstract String dbInstance(CONNECTION connection);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public AgentSpan afterStart(final AgentSpan span) {
|
|
||||||
afterStart(span.getSpan());
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Span afterStart(final Span span) {
|
public Span afterStart(final Span span) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
|
@ -38,12 +30,6 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
||||||
* @param connection
|
* @param connection
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onConnection(final AgentSpan span, final CONNECTION connection) {
|
|
||||||
onConnection(span.getSpan(), connection);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onConnection(final Span span, final CONNECTION connection) {
|
public Span onConnection(final Span span, final CONNECTION connection) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
@ -63,12 +49,6 @@ public abstract class DatabaseClientDecorator<CONNECTION> extends ClientDecorato
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onStatement(final AgentSpan span, final String statement) {
|
|
||||||
onStatement(span.getSpan(), statement);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onStatement(final Span span, final String statement) {
|
public Span onStatement(final Span span, final String statement) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
span.setAttribute(Tags.DB_STATEMENT, statement);
|
span.setAttribute(Tags.DB_STATEMENT, statement);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.config.Config;
|
import io.opentelemetry.auto.config.Config;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.auto.instrumentation.api.SpanTypes;
|
import io.opentelemetry.auto.instrumentation.api.SpanTypes;
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
|
@ -34,12 +33,6 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
|
|
||||||
onRequest(span.getSpan(), request);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onRequest(final Span span, final REQUEST request) {
|
public Span onRequest(final Span span, final REQUEST request) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
|
@ -105,12 +98,6 @@ public abstract class HttpClientDecorator<REQUEST, RESPONSE> extends ClientDecor
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onResponse(final AgentSpan span, final RESPONSE response) {
|
|
||||||
onResponse(span.getSpan(), response);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onResponse(final Span span, final RESPONSE response) {
|
public Span onResponse(final Span span, final RESPONSE response) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.config.Config;
|
import io.opentelemetry.auto.config.Config;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.auto.instrumentation.api.SpanTypes;
|
import io.opentelemetry.auto.instrumentation.api.SpanTypes;
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
|
@ -38,12 +37,6 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
||||||
return SpanTypes.HTTP_SERVER;
|
return SpanTypes.HTTP_SERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
|
|
||||||
onRequest(span.getSpan(), request);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onRequest(final Span span, final REQUEST request) {
|
public Span onRequest(final Span span, final REQUEST request) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
|
@ -91,12 +84,6 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onConnection(final AgentSpan span, final CONNECTION connection) {
|
|
||||||
onConnection(span.getSpan(), connection);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onConnection(final Span span, final CONNECTION connection) {
|
public Span onConnection(final Span span, final CONNECTION connection) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
|
@ -121,12 +108,6 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE> extends
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onResponse(final AgentSpan span, final RESPONSE response) {
|
|
||||||
onResponse(span.getSpan(), response);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onResponse(final Span span, final RESPONSE response) {
|
public Span onResponse(final Span span, final RESPONSE response) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
|
||||||
|
@ -8,12 +7,6 @@ public abstract class OrmClientDecorator extends DatabaseClientDecorator {
|
||||||
|
|
||||||
public abstract String entityName(final Object entity);
|
public abstract String entityName(final Object entity);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public AgentSpan onOperation(final AgentSpan span, final Object entity) {
|
|
||||||
onOperation(span.getSpan(), entity);
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Span onOperation(final Span span, final Object entity) {
|
public Span onOperation(final Span span, final Object entity) {
|
||||||
|
|
||||||
assert span != null;
|
assert span != null;
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package io.opentelemetry.auto.decorator;
|
package io.opentelemetry.auto.decorator;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags;
|
import io.opentelemetry.auto.instrumentation.api.Tags;
|
||||||
import io.opentelemetry.trace.Span;
|
import io.opentelemetry.trace.Span;
|
||||||
|
|
||||||
public abstract class ServerDecorator extends BaseDecorator {
|
public abstract class ServerDecorator extends BaseDecorator {
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public AgentSpan afterStart(final AgentSpan span) {
|
|
||||||
afterStart(span.getSpan());
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Span afterStart(final Span span) {
|
public Span afterStart(final Span span) {
|
||||||
assert span != null;
|
assert span != null;
|
||||||
|
|
|
@ -1,327 +0,0 @@
|
||||||
package io.opentelemetry.auto.tooling;
|
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MICROSECONDS;
|
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentPropagation;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentPropagation.Getter;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentScope;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentTracer.TracerAPI;
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags;
|
|
||||||
import io.opentelemetry.context.Scope;
|
|
||||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
|
||||||
import io.opentelemetry.sdk.trace.ReadableSpan;
|
|
||||||
import io.opentelemetry.trace.DefaultSpan;
|
|
||||||
import io.opentelemetry.trace.Span;
|
|
||||||
import io.opentelemetry.trace.SpanContext;
|
|
||||||
import io.opentelemetry.trace.Status;
|
|
||||||
import io.opentelemetry.trace.Tracer;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
|
|
||||||
public final class AgentTracerImpl implements TracerAPI {
|
|
||||||
|
|
||||||
private final Tracer tracer;
|
|
||||||
private final AgentPropagationImpl propagation = new AgentPropagationImpl();
|
|
||||||
|
|
||||||
private final AgentSpanImpl noopSpan;
|
|
||||||
|
|
||||||
public AgentTracerImpl(final Tracer tracer) {
|
|
||||||
this.tracer = tracer;
|
|
||||||
noopSpan = new AgentSpanImpl(DefaultSpan.getInvalid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName) {
|
|
||||||
return new AgentSpanImpl(spanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName, final long startTimeMicros) {
|
|
||||||
return new AgentSpanImpl(spanName, startTimeMicros);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(final String spanName, final AgentSpan.Context parent) {
|
|
||||||
return new AgentSpanImpl(spanName, (AgentContextImpl) parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan startSpan(
|
|
||||||
final String spanName, final AgentSpan.Context parent, final long startTimeMicros) {
|
|
||||||
return new AgentSpanImpl(spanName, parent, startTimeMicros);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentScope activateSpan(final AgentSpan span, final boolean finishSpanOnClose) {
|
|
||||||
final Scope scope = tracer.withSpan(((AgentSpanImpl) span).span);
|
|
||||||
return new AgentScopeImpl(span, scope, finishSpanOnClose);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan activeSpan() {
|
|
||||||
final Span span = tracer.getCurrentSpan();
|
|
||||||
if (!span.getContext().isValid()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new AgentSpanImpl(span);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentPropagation propagate() {
|
|
||||||
return propagation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan noopSpan() {
|
|
||||||
return noopSpan;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class AgentSpanImpl implements AgentSpan {
|
|
||||||
|
|
||||||
private final Span span;
|
|
||||||
|
|
||||||
private AgentSpanImpl(final String spanName) {
|
|
||||||
this(tracer.spanBuilder(spanName).startSpan());
|
|
||||||
}
|
|
||||||
|
|
||||||
private AgentSpanImpl(final String spanName, final long startTimeMicros) {
|
|
||||||
this(
|
|
||||||
tracer
|
|
||||||
.spanBuilder(spanName)
|
|
||||||
.setStartTimestamp(MICROSECONDS.toNanos(startTimeMicros))
|
|
||||||
.startSpan());
|
|
||||||
}
|
|
||||||
|
|
||||||
private AgentSpanImpl(final String spanName, final AgentContextImpl parent) {
|
|
||||||
final SpanContext context = parent.context;
|
|
||||||
final Span.Builder spanBuilder = tracer.spanBuilder(spanName);
|
|
||||||
if (context == null) {
|
|
||||||
spanBuilder.setNoParent();
|
|
||||||
} else {
|
|
||||||
spanBuilder.setParent(context);
|
|
||||||
}
|
|
||||||
span = spanBuilder.startSpan();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AgentSpanImpl(final String spanName, final Context parent, final long startTimeMicros) {
|
|
||||||
final SpanContext context = ((AgentContextImpl) parent).context;
|
|
||||||
final Span.Builder spanBuilder =
|
|
||||||
tracer.spanBuilder(spanName).setStartTimestamp(MICROSECONDS.toNanos(startTimeMicros));
|
|
||||||
if (context == null) {
|
|
||||||
spanBuilder.setNoParent();
|
|
||||||
} else {
|
|
||||||
spanBuilder.setParent(context);
|
|
||||||
}
|
|
||||||
span = spanBuilder.startSpan();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AgentSpanImpl(final Span span) {
|
|
||||||
this.span = span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final boolean value) {
|
|
||||||
span.setAttribute(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final int value) {
|
|
||||||
span.setAttribute(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final long value) {
|
|
||||||
span.setAttribute(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final double value) {
|
|
||||||
span.setAttribute(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setAttribute(final String key, final String value) {
|
|
||||||
if (value != null && !value.isEmpty()) {
|
|
||||||
span.setAttribute(key, value);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setError(final boolean error) {
|
|
||||||
span.setStatus(Status.UNKNOWN);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan setErrorMessage(final String errorMessage) {
|
|
||||||
span.setAttribute(MoreTags.ERROR_MSG, errorMessage);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan addThrowable(final Throwable throwable) {
|
|
||||||
final String message = throwable.getMessage();
|
|
||||||
if (message != null) {
|
|
||||||
span.setAttribute(MoreTags.ERROR_MSG, message);
|
|
||||||
}
|
|
||||||
span.setAttribute(MoreTags.ERROR_TYPE, throwable.getClass().getName());
|
|
||||||
|
|
||||||
final StringWriter errorString = new StringWriter();
|
|
||||||
throwable.printStackTrace(new PrintWriter(errorString));
|
|
||||||
span.setAttribute(MoreTags.ERROR_STACK, errorString.toString());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentContextImpl context() {
|
|
||||||
final SpanContext context = span.getContext();
|
|
||||||
return new AgentContextImpl(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finish() {
|
|
||||||
span.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSpanName() {
|
|
||||||
if (span instanceof ReadableSpan) {
|
|
||||||
return ((ReadableSpan) span).getName();
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSpanName(final String spanName) {
|
|
||||||
span.updateName(spanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Span getSpan() {
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return span.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object obj) {
|
|
||||||
if (!(obj instanceof AgentSpanImpl)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final AgentSpanImpl other = (AgentSpanImpl) obj;
|
|
||||||
return span.equals(other.span);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class AgentScopeImpl implements AgentScope {
|
|
||||||
|
|
||||||
private final AgentSpanImpl span;
|
|
||||||
private final Scope scope;
|
|
||||||
private final boolean finishSpanOnClose;
|
|
||||||
|
|
||||||
private AgentScopeImpl(
|
|
||||||
final AgentSpan span, final Scope scope, final boolean finishSpanOnClose) {
|
|
||||||
assert span instanceof AgentSpanImpl;
|
|
||||||
this.span = (AgentSpanImpl) span;
|
|
||||||
this.scope = scope;
|
|
||||||
this.finishSpanOnClose = finishSpanOnClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
scope.close();
|
|
||||||
if (finishSpanOnClose) {
|
|
||||||
span.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentSpan span() {
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return scope.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object obj) {
|
|
||||||
if (!(obj instanceof AgentScopeImpl)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final AgentScopeImpl other = (AgentScopeImpl) obj;
|
|
||||||
return scope.equals(other.scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class AgentPropagationImpl implements AgentPropagation {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <C> void inject(final AgentSpan span, final C carrier, final Setter<C> setter) {
|
|
||||||
assert span instanceof AgentSpanImpl;
|
|
||||||
tracer
|
|
||||||
.getHttpTextFormat()
|
|
||||||
.inject(
|
|
||||||
((AgentSpanImpl) span).getSpan().getContext(),
|
|
||||||
carrier,
|
|
||||||
new AgentPropagationImpl.Injector<>(setter));
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class Injector<C> implements HttpTextFormat.Setter<C> {
|
|
||||||
private final Setter<C> setter;
|
|
||||||
|
|
||||||
private Injector(final Setter<C> setter) {
|
|
||||||
this.setter = setter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put(final C carrier, final String key, final String value) {
|
|
||||||
setter.set(carrier, key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <C> AgentSpan.Context extract(final C carrier, final Getter<C> getter) {
|
|
||||||
SpanContext extract;
|
|
||||||
try {
|
|
||||||
extract = tracer.getHttpTextFormat().extract(carrier, new Extractor<>(getter));
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
extract = null;
|
|
||||||
}
|
|
||||||
return new AgentContextImpl(extract);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class Extractor<C> implements HttpTextFormat.Getter<C> {
|
|
||||||
|
|
||||||
private final Getter<C> getter;
|
|
||||||
|
|
||||||
private Extractor(final Getter<C> getter) {
|
|
||||||
this.getter = getter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get(final C carrier, final String key) {
|
|
||||||
return getter.get(carrier, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class AgentContextImpl implements AgentSpan.Context {
|
|
||||||
private final SpanContext context;
|
|
||||||
|
|
||||||
private AgentContextImpl(final SpanContext context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,11 @@
|
||||||
package io.opentelemetry.auto.tooling;
|
package io.opentelemetry.auto.tooling;
|
||||||
|
|
||||||
import io.opentelemetry.OpenTelemetry;
|
|
||||||
import io.opentelemetry.auto.config.Config;
|
import io.opentelemetry.auto.config.Config;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentTracer;
|
|
||||||
import io.opentelemetry.auto.tooling.exporter.ExporterConfigException;
|
import io.opentelemetry.auto.tooling.exporter.ExporterConfigException;
|
||||||
import io.opentelemetry.auto.tooling.exporter.ExporterRegistry;
|
import io.opentelemetry.auto.tooling.exporter.ExporterRegistry;
|
||||||
import io.opentelemetry.auto.tooling.exporter.SpanExporterFactory;
|
import io.opentelemetry.auto.tooling.exporter.SpanExporterFactory;
|
||||||
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
import io.opentelemetry.sdk.trace.export.SimpleSpansProcessor;
|
import io.opentelemetry.sdk.trace.export.SimpleSpansProcessor;
|
||||||
import io.opentelemetry.trace.Tracer;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -32,13 +29,6 @@ public class TracerInstaller {
|
||||||
} else {
|
} else {
|
||||||
log.warn("No exporter is specified. Tracing will run but spans are dropped");
|
log.warn("No exporter is specified. Tracing will run but spans are dropped");
|
||||||
}
|
}
|
||||||
final Tracer tracer = OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto");
|
|
||||||
try {
|
|
||||||
AgentTracer.registerIfAbsent(new AgentTracerImpl(tracer));
|
|
||||||
} catch (final RuntimeException re) {
|
|
||||||
log.warn("Failed to register tracer '" + tracer + "'", re);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.debug("Tracing is disabled.");
|
log.debug("Tracing is disabled.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package io.opentelemetry.auto.instrumentation.okhttp3;
|
package io.opentelemetry.auto.instrumentation.okhttp3;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentPropagation;
|
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,12 +8,12 @@ import okhttp3.Request;
|
||||||
*
|
*
|
||||||
* @author Pavol Loffay
|
* @author Pavol Loffay
|
||||||
*/
|
*/
|
||||||
public class RequestBuilderInjectAdapter implements AgentPropagation.Setter<Request.Builder> {
|
public class RequestBuilderInjectAdapter implements HttpTextFormat.Setter<Request.Builder> {
|
||||||
|
|
||||||
public static final RequestBuilderInjectAdapter SETTER = new RequestBuilderInjectAdapter();
|
public static final RequestBuilderInjectAdapter SETTER = new RequestBuilderInjectAdapter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(final Request.Builder carrier, final String key, final String value) {
|
public void put(final Request.Builder carrier, final String key, final String value) {
|
||||||
carrier.addHeader(key, value);
|
carrier.addHeader(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package io.opentelemetry.auto.instrumentation.okhttp3;
|
package io.opentelemetry.auto.instrumentation.okhttp3;
|
||||||
|
|
||||||
import static io.opentelemetry.auto.instrumentation.api.AgentTracer.activateSpan;
|
|
||||||
import static io.opentelemetry.auto.instrumentation.api.AgentTracer.propagate;
|
|
||||||
import static io.opentelemetry.auto.instrumentation.api.AgentTracer.startSpan;
|
|
||||||
import static io.opentelemetry.auto.instrumentation.okhttp3.OkHttpClientDecorator.DECORATE;
|
import static io.opentelemetry.auto.instrumentation.okhttp3.OkHttpClientDecorator.DECORATE;
|
||||||
import static io.opentelemetry.auto.instrumentation.okhttp3.RequestBuilderInjectAdapter.SETTER;
|
import static io.opentelemetry.auto.instrumentation.okhttp3.RequestBuilderInjectAdapter.SETTER;
|
||||||
|
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentScope;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentSpan;
|
import io.opentelemetry.context.Scope;
|
||||||
|
import io.opentelemetry.trace.Span;
|
||||||
|
import io.opentelemetry.trace.Tracer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
|
@ -16,27 +15,31 @@ import okhttp3.Response;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TracingInterceptor implements Interceptor {
|
public class TracingInterceptor implements Interceptor {
|
||||||
|
public static final Tracer TRACER = OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response intercept(final Chain chain) throws IOException {
|
public Response intercept(final Chain chain) throws IOException {
|
||||||
final AgentSpan span = startSpan("okhttp.request");
|
final Span span = TRACER.spanBuilder("okhttp.request").startSpan();
|
||||||
|
|
||||||
try (final AgentScope scope = activateSpan(span, true)) {
|
try (final Scope scope = TRACER.withSpan(span)) {
|
||||||
DECORATE.afterStart(span);
|
DECORATE.afterStart(span);
|
||||||
DECORATE.onRequest(span, chain.request());
|
DECORATE.onRequest(span, chain.request());
|
||||||
|
|
||||||
final Request.Builder requestBuilder = chain.request().newBuilder();
|
final Request.Builder requestBuilder = chain.request().newBuilder();
|
||||||
propagate().inject(span, requestBuilder, SETTER);
|
TRACER.getHttpTextFormat().inject(span.getContext(), requestBuilder, SETTER);
|
||||||
|
|
||||||
final Response response;
|
final Response response;
|
||||||
try {
|
try {
|
||||||
response = chain.proceed(requestBuilder.build());
|
response = chain.proceed(requestBuilder.build());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
DECORATE.onError(span, e);
|
DECORATE.onError(span, e);
|
||||||
|
span.end();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECORATE.onResponse(span, response);
|
DECORATE.onResponse(span, response);
|
||||||
DECORATE.beforeFinish(span);
|
DECORATE.beforeFinish(span);
|
||||||
|
span.end();
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||||
|
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentTracer;
|
|
||||||
import io.opentelemetry.auto.tooling.Constants;
|
import io.opentelemetry.auto.tooling.Constants;
|
||||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -19,9 +18,8 @@ import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instrument Tomcat's web app classloader so it loads agent bootstrap classes from parent
|
* Instrument Tomcat's web app classloader so it loads agent bootstrap classes from parent
|
||||||
* classloader. Without this change web apps get their own versions of agent classes leading to
|
* classloader. Without this change web apps get their own versions of agent classes. This is really
|
||||||
* there being multiple {@link AgentTracer}s in existence, some of them not configured properly.
|
* the same idea we have for OSGi and JBoss.
|
||||||
* This is really the same idea we have for OSGi and JBoss.
|
|
||||||
*/
|
*/
|
||||||
@AutoService(Instrumenter.class)
|
@AutoService(Instrumenter.class)
|
||||||
public final class TomcatClassloadingInstrumentation extends Instrumenter.Default {
|
public final class TomcatClassloadingInstrumentation extends Instrumenter.Default {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentTracer
|
import io.opentelemetry.auto.instrumentation.api.Tags
|
||||||
import io.opentelemetry.auto.test.AgentTestRunner
|
import io.opentelemetry.auto.test.AgentTestRunner
|
||||||
import org.apache.catalina.WebResource
|
import org.apache.catalina.WebResource
|
||||||
import org.apache.catalina.WebResourceRoot
|
import org.apache.catalina.WebResourceRoot
|
||||||
|
@ -22,9 +22,9 @@ class TomcatClassloadingTest extends AgentTestRunner {
|
||||||
|
|
||||||
when:
|
when:
|
||||||
// If instrumentation didn't work this would blow up with NPE due to incomplete resources mocking
|
// If instrumentation didn't work this would blow up with NPE due to incomplete resources mocking
|
||||||
def clazz = classloader.loadClass("io.opentelemetry.auto.instrumentation.api.AgentTracer")
|
def clazz = classloader.loadClass("io.opentelemetry.auto.instrumentation.api.Tags")
|
||||||
|
|
||||||
then:
|
then:
|
||||||
clazz == AgentTracer
|
clazz == Tags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,8 @@ import groovy.lang.DelegatesTo;
|
||||||
import groovy.transform.stc.ClosureParams;
|
import groovy.transform.stc.ClosureParams;
|
||||||
import groovy.transform.stc.SimpleType;
|
import groovy.transform.stc.SimpleType;
|
||||||
import io.opentelemetry.OpenTelemetry;
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.auto.instrumentation.api.AgentTracer;
|
|
||||||
import io.opentelemetry.auto.test.asserts.ListWriterAssert;
|
import io.opentelemetry.auto.test.asserts.ListWriterAssert;
|
||||||
import io.opentelemetry.auto.tooling.AgentInstaller;
|
import io.opentelemetry.auto.tooling.AgentInstaller;
|
||||||
import io.opentelemetry.auto.tooling.AgentTracerImpl;
|
|
||||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
import io.opentelemetry.auto.tooling.Instrumenter;
|
||||||
import io.opentelemetry.auto.util.test.AgentSpecification;
|
import io.opentelemetry.auto.util.test.AgentSpecification;
|
||||||
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
|
@ -84,8 +82,6 @@ public abstract class AgentTestRunner extends AgentSpecification {
|
||||||
TEST_WRITER = new ListWriter();
|
TEST_WRITER = new ListWriter();
|
||||||
OpenTelemetrySdk.getTracerFactory().addSpanProcessor(TEST_WRITER);
|
OpenTelemetrySdk.getTracerFactory().addSpanProcessor(TEST_WRITER);
|
||||||
TEST_TRACER = OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto");
|
TEST_TRACER = OpenTelemetry.getTracerFactory().get("io.opentelemetry.auto");
|
||||||
|
|
||||||
AgentTracer.registerIfAbsent(new AgentTracerImpl(TEST_TRACER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Tracer getTestTracer() {
|
protected static Tracer getTestTracer() {
|
||||||
|
|
Loading…
Reference in New Issue