Added Http4SpanDecorator to apache-camel (#4650)

* Added Http4SpanDecorator to apache-camel

* Fixed CR

* After spotless
This commit is contained in:
Osher Vaknin 2021-12-02 18:24:02 +02:00 committed by GitHub
parent cd23a72767
commit 32d5ffde2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 2 deletions

View File

@ -31,7 +31,8 @@ public class DecoratorRegistry {
result.put("disruptor", new InternalSpanDecorator());
result.put("disruptor-vm", new InternalSpanDecorator());
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("ironmq", new MessagingSpanDecorator("ironmq"));
result.put("jdbc", new DbSpanDecorator("jdbc", DbSystemValues.OTHER_SQL));

View File

@ -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;
}
}

View File

@ -39,6 +39,10 @@ class HttpSpanDecorator extends BaseSpanDecorator {
private static final String POST_METHOD = "POST";
private static final String GET_METHOD = "GET";
protected String getProtocol() {
return "http";
}
protected static String getHttpMethod(Exchange exchange, Endpoint endpoint) {
// 1. Use method provided in header.
Object method = exchange.getIn().getHeader(Exchange.HTTP_METHOD);
@ -131,7 +135,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
return (String) uri;
} else {
// Try to obtain from endpoint
int index = endpoint.getEndpointUri().lastIndexOf("http:");
int index = endpoint.getEndpointUri().lastIndexOf(getProtocol() + ":");
if (index != -1) {
return endpoint.getEndpointUri().substring(index);
}

View File

@ -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";
}
}