Added Http4SpanDecorator to apache-camel (#4650)
* Added Http4SpanDecorator to apache-camel * Fixed CR * After spotless
This commit is contained in:
parent
cd23a72767
commit
32d5ffde2f
|
@ -31,7 +31,8 @@ public class DecoratorRegistry {
|
||||||
result.put("disruptor", new InternalSpanDecorator());
|
result.put("disruptor", new InternalSpanDecorator());
|
||||||
result.put("disruptor-vm", new InternalSpanDecorator());
|
result.put("disruptor-vm", new InternalSpanDecorator());
|
||||||
result.put("elasticsearch", new DbSpanDecorator("elasticsearch", "elasticsearch"));
|
result.put("elasticsearch", new DbSpanDecorator("elasticsearch", "elasticsearch"));
|
||||||
result.put("http4", new HttpSpanDecorator());
|
result.put("http4", new Http4SpanDecorator());
|
||||||
|
result.put("https4", new Https4SpanDecorator());
|
||||||
result.put("http", new HttpSpanDecorator());
|
result.put("http", new HttpSpanDecorator());
|
||||||
result.put("ironmq", new MessagingSpanDecorator("ironmq"));
|
result.put("ironmq", new MessagingSpanDecorator("ironmq"));
|
||||||
result.put("jdbc", new DbSpanDecorator("jdbc", DbSystemValues.OTHER_SQL));
|
result.put("jdbc", new DbSpanDecorator("jdbc", DbSystemValues.OTHER_SQL));
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import org.apache.camel.Endpoint;
|
||||||
|
import org.apache.camel.Exchange;
|
||||||
|
|
||||||
|
class Http4SpanDecorator extends HttpSpanDecorator {
|
||||||
|
@Override
|
||||||
|
protected String getProtocol() {
|
||||||
|
return "http4";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
protected String getHttpUrl(Exchange exchange, Endpoint endpoint) {
|
||||||
|
String url = super.getHttpUrl(exchange, endpoint);
|
||||||
|
if (url != null) {
|
||||||
|
return url.replace(getProtocol(), getProtocol().substring(0, getProtocol().length() - 1));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,10 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
||||||
private static final String POST_METHOD = "POST";
|
private static final String POST_METHOD = "POST";
|
||||||
private static final String GET_METHOD = "GET";
|
private static final String GET_METHOD = "GET";
|
||||||
|
|
||||||
|
protected String getProtocol() {
|
||||||
|
return "http";
|
||||||
|
}
|
||||||
|
|
||||||
protected static String getHttpMethod(Exchange exchange, Endpoint endpoint) {
|
protected static String getHttpMethod(Exchange exchange, Endpoint endpoint) {
|
||||||
// 1. Use method provided in header.
|
// 1. Use method provided in header.
|
||||||
Object method = exchange.getIn().getHeader(Exchange.HTTP_METHOD);
|
Object method = exchange.getIn().getHeader(Exchange.HTTP_METHOD);
|
||||||
|
@ -131,7 +135,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
||||||
return (String) uri;
|
return (String) uri;
|
||||||
} else {
|
} else {
|
||||||
// Try to obtain from endpoint
|
// Try to obtain from endpoint
|
||||||
int index = endpoint.getEndpointUri().lastIndexOf("http:");
|
int index = endpoint.getEndpointUri().lastIndexOf(getProtocol() + ":");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
return endpoint.getEndpointUri().substring(index);
|
return endpoint.getEndpointUri().substring(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;
|
||||||
|
|
||||||
|
class Https4SpanDecorator extends Http4SpanDecorator {
|
||||||
|
@Override
|
||||||
|
protected String getProtocol() {
|
||||||
|
return "https4";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue