Skip to content

Commit 1cc6c5f

Browse files
committed
Resolved PR comments
1 parent b52c49d commit 1cc6c5f

13 files changed

+80
-222
lines changed

.fossa.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ targets:
5151
target: ':testing:agent-for-testing'
5252
- type: gradle
5353
path: ./
54-
target: ':instrumentation:activej-http:javaagent'
54+
target: ':instrumentation:activej-http-6.0:javaagent'
5555
- type: gradle
5656
path: ./
5757
target: ':instrumentation:alibaba-druid-1.0:javaagent'

instrumentation/activej-http/javaagent/build.gradle.kts instrumentation/activej-http-6.0/javaagent/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ muzzle {
77
group.set("io.activej:activej-http")
88
module.set("activej-http")
99

10-
versions.set("[1.0,)")
10+
versions.set("[6.0,)")
1111
}
1212
}
1313

1414
dependencies {
15-
library("io.activej:activej-http:6.0-beta2")
15+
library("io.activej:activej-http:6.0-rc2")
1616
}
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,14 @@
3434
* {@code serve} method of classes that extend {@code io.activej.http.AsyncServlet}. The
3535
* instrumentation is designed to integrate with OpenTelemetry for distributed tracing, capturing
3636
* and propagating trace context through HTTP requests and responses.
37-
*
38-
* @author Krishna Chaitanya Surapaneni
3937
*/
4038
public class ActiveJHttpServerConnectionInstrumentation implements TypeInstrumentation {
4139

42-
/**
43-
* Matches classes that extend {@code io.activej.http.AsyncServlet} but are not interfaces.
44-
*
45-
* @return An {@code ElementMatcher} that identifies target classes for instrumentation.
46-
*/
4740
@Override
4841
public ElementMatcher<TypeDescription> typeMatcher() {
4942
return hasSuperType(named("io.activej.http.AsyncServlet")).and(not(isInterface()));
5043
}
5144

52-
/**
53-
* Applies advice to the {@code serve} method of the matched classes. The advice captures trace
54-
* context at the start of the method and propagates it through the response.
55-
*
56-
* @param transformer The {@code TypeTransformer} used to apply the advice.
57-
*/
5845
@Override
5946
public void transform(TypeTransformer transformer) {
6047
transformer.applyAdviceToMethod(
@@ -64,28 +51,9 @@ public void transform(TypeTransformer transformer) {
6451
this.getClass().getName() + "$ServeAdvice");
6552
}
6653

67-
/**
68-
* Inner class containing the advice logic for the {@code serve} method. This class defines two
69-
* methods:
70-
*
71-
* <ul>
72-
* <li>{@code methodEnter}: Captures the trace context at the start of the method.
73-
* <li>{@code methodExit}: Propagates the trace context to the response and ends the span.
74-
* </ul>
75-
*/
7654
@SuppressWarnings("unused")
7755
public static class ServeAdvice {
7856

79-
/**
80-
* Advice executed at the start of the {@code serve} method. Captures the current trace context
81-
* and starts a new span if tracing is enabled for the request.
82-
*
83-
* @param asyncServlet The {@code AsyncServlet} instance handling the request.
84-
* @param request The incoming HTTP request.
85-
* @param context Local variable to store the OpenTelemetry context.
86-
* @param scope Local variable to store the OpenTelemetry scope.
87-
* @param httpRequest Local variable to store the HTTP request.
88-
*/
8957
@Advice.OnMethodEnter(suppress = Throwable.class)
9058
public static void methodEnter(
9159
@Advice.This AsyncServlet asyncServlet,
@@ -102,17 +70,6 @@ public static void methodEnter(
10270
scope = context.makeCurrent();
10371
}
10472

105-
/**
106-
* Advice executed at the end of the {@code serve} method. Propagates the trace context to the
107-
* response, handles exceptions, and ends the span.
108-
*
109-
* @param asyncServlet The {@code AsyncServlet} instance handling the request.
110-
* @param responsePromise The promise representing the HTTP response.
111-
* @param throwable Any exception thrown during the execution of the method.
112-
* @param context Local variable storing the OpenTelemetry context.
113-
* @param scope Local variable storing the OpenTelemetry scope.
114-
* @param httpRequest Local variable storing the HTTP request.
115-
*/
11673
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
11774
public static void methodExit(
11875
@Advice.This AsyncServlet asyncServlet,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.activejhttp;
7+
8+
import static java.util.Collections.singletonList;
9+
10+
import com.google.auto.service.AutoService;
11+
import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder;
12+
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
13+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import java.util.List;
15+
16+
@AutoService(InstrumentationModule.class)
17+
public class ActiveJHttpServerConnectionInstrumentationModule extends InstrumentationModule {
18+
19+
public ActiveJHttpServerConnectionInstrumentationModule() {
20+
super("activej-http", "activej-http-server");
21+
}
22+
23+
@Override
24+
public List<TypeInstrumentation> typeInstrumentations() {
25+
return singletonList(new ActiveJHttpServerConnectionInstrumentation());
26+
}
27+
28+
@Override
29+
public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) {
30+
helperResourceBuilder.register(ActiveJHttpServerHelper.class.getName());
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@
1010
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1111
import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters;
1212

13-
/**
14-
* This class provides singleton instances and utilities for ActiveJ HTTP server instrumentation. It
15-
* is designed to centralize the creation and access of OpenTelemetry-related components, such as
16-
* the {@code Instrumenter} used for tracing HTTP requests and responses.
17-
*
18-
* @author Krishna Chaitanya Surapaneni
19-
*/
2013
public class ActiveJHttpServerConnectionSingletons {
2114

22-
/**
23-
* The name of the instrumentation, used to identify this module in the OpenTelemetry framework.
24-
*/
2515
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.activej-http";
2616

2717
private static final Instrumenter<HttpRequest, HttpResponse> INSTRUMENTER;
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
import java.util.Map;
1717
import java.util.stream.Collectors;
1818

19-
/**
20-
* This enum implements the {@code ExtendedTextMapGetter<HttpRequest>} interface and provides
21-
* methods for extracting HTTP headers from an ActiveJ {@code HttpRequest}. It is used in the
22-
* context of OpenTelemetry instrumentation to propagate trace context across service boundaries.
23-
*
24-
* @author Krishna Chaitanya Surapaneni
25-
*/
2619
enum ActiveJHttpServerHeaders implements ExtendedTextMapGetter<HttpRequest> {
2720
INSTANCE;
2821

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.activejhttp;
7+
8+
import io.activej.http.HttpError;
9+
import io.activej.http.HttpHeader;
10+
import io.activej.http.HttpHeaderValue;
11+
import io.activej.http.HttpHeaders;
12+
import io.activej.http.HttpResponse;
13+
import java.util.Map;
14+
15+
public final class ActiveJHttpServerHelper {
16+
17+
private ActiveJHttpServerHelper() {
18+
throw new UnsupportedOperationException();
19+
}
20+
21+
public static HttpResponse createResponse(
22+
Throwable throwable, String traceparent, HttpResponse httpResponse) {
23+
int code = 500;
24+
if (httpResponse != null) {
25+
code = httpResponse.getCode();
26+
} else if (throwable instanceof HttpError) {
27+
HttpError error = (HttpError) throwable;
28+
code = error.getCode();
29+
}
30+
HttpResponse.Builder responseBuilder = HttpResponse.ofCode(code);
31+
if (httpResponse != null) {
32+
if (httpResponse.hasBody()) {
33+
responseBuilder.withBody(httpResponse.getBody());
34+
}
35+
for (Map.Entry<HttpHeader, HttpHeaderValue> entry : httpResponse.getHeaders()) {
36+
responseBuilder.withHeader(entry.getKey(), entry.getValue());
37+
}
38+
}
39+
if (throwable != null) {
40+
responseBuilder.withPlainText(throwable.getMessage());
41+
}
42+
return responseBuilder.withHeader(HttpHeaders.of("traceparent"), traceparent).build();
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
import java.util.List;
1313
import javax.annotation.Nullable;
1414

15-
/**
16-
* This class implements the {@code HttpServerAttributesGetter<HttpRequest, HttpResponse>} interface
17-
* and provides methods for extracting HTTP-related attributes from ActiveJ {@code HttpRequest} and
18-
* {@code HttpResponse} objects. These attributes are used by OpenTelemetry to enrich telemetry
19-
* data, such as spans, with detailed information about HTTP requests and responses.
20-
*
21-
* @author Krishna Chaitanya Surapaneni
22-
*/
2315
final class ActiveJHttpServerHttpAttributesGetter
2416
implements HttpServerAttributesGetter<HttpRequest, HttpResponse> {
2517

Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
import java.util.stream.Collectors;
1616
import javax.annotation.Nullable;
1717

18-
/**
19-
* This utility class provides helper methods for extracting and manipulating HTTP-related
20-
* attributes from ActiveJ {@code HttpRequest} and {@code HttpResponse} objects. It is designed to
21-
* simplify the process of retrieving information such as HTTP methods, headers, status codes, and
22-
* other metadata, which are essential for OpenTelemetry instrumentation and distributed tracing.
23-
*
24-
* @author Krishna Chaitanya Surapaneni
25-
*/
2618
public final class ActiveJHttpServerUtil {
2719

2820
private ActiveJHttpServerUtil() {

instrumentation/activej-http/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/activejhttp/ActiveJHttpServerConnectionInstrumentationModule.java

-66
This file was deleted.

instrumentation/activej-http/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/activejhttp/ActiveJHttpServerHelper.java

-76
This file was deleted.

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ include(":smoke-tests-otel-starter:spring-boot-reactive-2")
128128
include(":smoke-tests-otel-starter:spring-boot-reactive-3")
129129
include(":smoke-tests-otel-starter:spring-boot-reactive-common")
130130

131-
include(":instrumentation:activej-http:javaagent")
131+
include(":instrumentation:activej-http-6.0:javaagent")
132132
include(":instrumentation:akka:akka-actor-2.3:javaagent")
133133
include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent")
134134
include(":instrumentation:akka:akka-http-10.0:javaagent")

0 commit comments

Comments
 (0)