Skip to content

Commit

Permalink
Fix ratpack netty version
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalinaspolo committed Dec 3, 2021
1 parent ef21f8a commit 10261ac
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 81 deletions.
27 changes: 3 additions & 24 deletions instrumentation/ratpack-1.4/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,20 @@ muzzle {
pass {
group.set("io.ratpack")
module.set("ratpack-core")
versions.set("[1.4.0,)")
versions.set("[1.7.0,)")
}
}

dependencies {
library("io.ratpack:ratpack-core:1.4.0")
library("io.ratpack:ratpack-core:1.7.0")

implementation(project(":instrumentation:netty:netty-4.1:javaagent"))

testImplementation(project(":instrumentation:ratpack-1.4:testing"))

// 1.4.0 has a bug which makes tests flaky
// (https://github.com/ratpack/ratpack/commit/dde536ac138a76c34df03a0642c88d64edde688e)
testLibrary("io.ratpack:ratpack-test:1.4.1")
testLibrary("io.ratpack:ratpack-test:1.7.0")

if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
testImplementation("com.sun.activation:jakarta.activation:1.2.2")
}
}

// Requires old Guava. Can't use enforcedPlatform since predates BOM
configurations.testRuntimeClasspath.resolutionStrategy.force("com.google.guava:guava:19.0")

// to allow all tests to pass we need to choose a specific netty version
if (!(findProperty("testLatestDeps") as Boolean)) {
configurations.configureEach {
if (!name.contains("muzzle")) {
resolutionStrategy {
eachDependency {
// specifying a fixed version for all libraries with io.netty group
if (requested.group == "io.netty") {
useVersion("4.1.31.Final")
}
}
}
}
}
}
18 changes: 0 additions & 18 deletions instrumentation/ratpack-1.4/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,10 @@ dependencies {

testImplementation(project(":instrumentation:ratpack-1.4:testing"))

// 1.4.0 has a bug which makes tests flaky
// (https://github.com/ratpack/ratpack/commit/dde536ac138a76c34df03a0642c88d64edde688e)
testLibrary("io.ratpack:ratpack-test:1.7.0")
testLibrary("io.ratpack:ratpack-guice:1.7.0")

if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
testImplementation("com.sun.activation:jakarta.activation:1.2.2")
}
}

// to allow all tests to pass we need to choose a specific netty version
if (!(findProperty("testLatestDeps") as Boolean)) {
configurations.configureEach {
if (!name.contains("muzzle")) {
resolutionStrategy {
eachDependency {
// specifying a fixed version for all libraries with io.netty group
if (requested.group == "io.netty") {
useVersion("4.1.63.Final")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.ratpack;

import io.opentelemetry.context.Context;
import ratpack.exec.ExecInitializer;
import ratpack.exec.Execution;
import ratpack.http.client.RequestSpec;


public final class OpenTelemetryExecInitializer implements ExecInitializer {

@Override
public void init(Execution execution) {
execution.maybeParent()
execution
.maybeParent()
.flatMap(parent -> parent.maybeGet(ContextHolder.class))
.ifPresent(execution::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,33 @@ final class OpenTelemetryHttpClient {
}

public HttpClient instrument(HttpClient httpClient) throws Exception {
return httpClient.copyWith(httpClientSpec -> {
httpClientSpec.requestIntercept(requestSpec -> {
Context otelCtx = instrumenter.start(Context.current(), requestSpec);
Span span = Span.fromContext(otelCtx);
String path = requestSpec.getUri().getPath();
span.updateName(path);
span.setAttribute(SemanticAttributes.HTTP_ROUTE, path);
Execution.current()
.add(new OpenTelemetryExecInitializer.ContextHolder(otelCtx, requestSpec));
});

httpClientSpec.responseIntercept(httpResponse -> {
OpenTelemetryExecInitializer.ContextHolder contextHolder = Execution.current()
.get(OpenTelemetryExecInitializer.ContextHolder.class);
instrumenter.end(contextHolder.context(), contextHolder.requestSpec(), httpResponse, null);
});

httpClientSpec.errorIntercept(ex -> {
OpenTelemetryExecInitializer.ContextHolder contextHolder = Execution.current()
.get(OpenTelemetryExecInitializer.ContextHolder.class);
instrumenter.end(contextHolder.context(), contextHolder.requestSpec(), null, ex);
});
});
return httpClient.copyWith(
httpClientSpec -> {
httpClientSpec.requestIntercept(
requestSpec -> {
Context otelCtx = instrumenter.start(Context.current(), requestSpec);
Span span = Span.fromContext(otelCtx);
String path = requestSpec.getUri().getPath();
span.updateName(path);
span.setAttribute(SemanticAttributes.HTTP_ROUTE, path);
Execution.current()
.add(new OpenTelemetryExecInitializer.ContextHolder(otelCtx, requestSpec));
});

httpClientSpec.responseIntercept(
httpResponse -> {
OpenTelemetryExecInitializer.ContextHolder contextHolder =
Execution.current().get(OpenTelemetryExecInitializer.ContextHolder.class);
instrumenter.end(
contextHolder.context(), contextHolder.requestSpec(), httpResponse, null);
});

httpClientSpec.errorIntercept(
ex -> {
OpenTelemetryExecInitializer.ContextHolder contextHolder =
Execution.current().get(OpenTelemetryExecInitializer.ContextHolder.class);
instrumenter.end(contextHolder.context(), contextHolder.requestSpec(), null, ex);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ protected List<String> requestHeader(RequestSpec requestSpec, String name) {

@Nullable
@Override
protected Long requestContentLength(RequestSpec requestSpec,
@Nullable HttpResponse httpResponse) {
protected Long requestContentLength(
RequestSpec requestSpec, @Nullable HttpResponse httpResponse) {
return null;
}

@Nullable
@Override
protected Long requestContentLengthUncompressed(RequestSpec requestSpec,
@Nullable HttpResponse httpResponse) {
protected Long requestContentLengthUncompressed(
RequestSpec requestSpec, @Nullable HttpResponse httpResponse) {
return null;
}

Expand All @@ -70,14 +70,14 @@ protected Long responseContentLength(RequestSpec requestSpec, HttpResponse httpR

@Nullable
@Override
protected Long responseContentLengthUncompressed(RequestSpec requestSpec,
HttpResponse httpResponse) {
protected Long responseContentLengthUncompressed(
RequestSpec requestSpec, HttpResponse httpResponse) {
return null;
}

@Override
protected List<String> responseHeader(RequestSpec requestSpec, HttpResponse httpResponse,
String name) {
protected List<String> responseHeader(
RequestSpec requestSpec, HttpResponse httpResponse, String name) {
return httpResponse.getHeaders().getAll(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static RatpackHttpTracing create(OpenTelemetry openTelemetry) {
return builder(openTelemetry).build();
}

/** Returns a new {@link RatpackHttpTracingBuilder} configured with the given {@link OpenTelemetry}. */
/**
* Returns a new {@link RatpackHttpTracingBuilder} configured with the given {@link
* OpenTelemetry}.
*/
public static RatpackHttpTracingBuilder builder(OpenTelemetry openTelemetry) {
return new RatpackHttpTracingBuilder(openTelemetry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public final class RatpackHttpTracingBuilder {

private final OpenTelemetry openTelemetry;

private final List<AttributesExtractor<? super RequestSpec, ? super HttpResponse>> additionalExtractors =
new ArrayList<>();
private final List<AttributesExtractor<? super RequestSpec, ? super HttpResponse>>
additionalExtractors = new ArrayList<>();
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.client(Config.get());

RatpackHttpTracingBuilder(OpenTelemetry openTelemetry) {
Expand Down Expand Up @@ -66,9 +66,7 @@ public RatpackHttpTracing build() {

Instrumenter<RequestSpec, HttpResponse> instrumenter =
Instrumenter.<RequestSpec, HttpResponse>builder(
openTelemetry,
INSTRUMENTATION_NAME,
HttpSpanNameExtractor.create(httpAttributes))
openTelemetry, INSTRUMENTATION_NAME, HttpSpanNameExtractor.create(httpAttributes))
.setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes))
.addAttributesExtractor(netAttributes)
.addAttributesExtractor(httpAttributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.ratpack.client

import io.opentelemetry.api.trace.SpanKind
Expand Down

0 comments on commit 10261ac

Please sign in to comment.