-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 gRPC header capture with shaded netty module and body capture witho…
…ut com.google.protobuf.util.JsonFormat (#339) * ✅ add test tasks for gRPC 1.30.0 * ♻️ move GrpcSemanticAttributes to common library for access across grpc instrumentation modules * ✨ add instrumentation for grpc-shaded-netty-1.9 * 🎨 format grpc-1.6 build * 🐛 fix classpath for versioned test source set * ✅ add muzzle check for module * 🎨 format shaded netty module * ♻️ move usages of grpc-common to util class * 🐛 add names to instrumentation module * 🎨 format utils * 🚚 rename NettyUtils * 🚚 move around classes * 🚚 move instrumentation classes to separate file * 🐛 copy-paste build script bug * 🔥 remove unneeded helper class method * ✅ update muzzle policy to be more restrictive, we need to work without JsonFormat available on the application class loader * ✨ add shaded project for protobuf-java-util * ♻️ use shaded protobuf java util in grpc instrumentation * 🔥 remove unneeded relocations
- Loading branch information
Showing
15 changed files
with
385 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcChannelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The Hypertrace Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_6; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import java.util.function.Supplier; | ||
|
||
final class GrpcChannelProvider implements Supplier<ManagedChannel> { | ||
|
||
private final int port; | ||
|
||
GrpcChannelProvider(final int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public ManagedChannel get() { | ||
return ManagedChannelBuilder.forTarget(String.format("localhost:%d", port)) | ||
.usePlaintext() | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcChannelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The Hypertrace Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_6; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import java.util.function.Supplier; | ||
|
||
final class GrpcChannelProvider implements Supplier<ManagedChannel> { | ||
|
||
private final int port; | ||
|
||
GrpcChannelProvider(final int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public ManagedChannel get() { | ||
return ManagedChannelBuilder.forTarget(String.format("localhost:%d", port)) | ||
.usePlaintext(true) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
compileOnly("io.grpc:grpc-core:1.6.0") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugins { | ||
`java-library` | ||
id("net.bytebuddy.byte-buddy") | ||
id("io.opentelemetry.instrumentation.auto-instrumentation") | ||
muzzle | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group = "io.grpc" | ||
module = "grpc-netty-shaded" | ||
versions = "[1.9.0,)" | ||
assertInverse = true | ||
} | ||
} | ||
|
||
afterEvaluate{ | ||
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project, | ||
sourceSets.main.get(), | ||
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin", | ||
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath | ||
).configure() | ||
} | ||
|
||
dependencies { | ||
compileOnly("io.grpc:grpc-core:1.9.0") | ||
compileOnly("io.grpc:grpc-netty-shaded:1.9.0") | ||
implementation(project(":instrumentation:grpc-common")) | ||
} |
36 changes: 36 additions & 0 deletions
36
.../javaagent/instrumentation/shaded/netty/ShadedNettyHttp2HeadersInstrumentationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The Hypertrace Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.shaded.netty; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public final class ShadedNettyHttp2HeadersInstrumentationModule extends InstrumentationModule { | ||
|
||
public ShadedNettyHttp2HeadersInstrumentationModule() { | ||
super("grpc-netty", "ht", "grpc-netty-ht"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return Collections.singletonList(new ShadedNettyUtilsInstrumentation()); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...opentelemetry/javaagent/instrumentation/shaded/netty/ShadedNettyUtilsInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright The Hypertrace Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.shaded.netty; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.failSafe; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import io.grpc.Metadata; | ||
import io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Headers; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.shaded.netty.utils.NettyUtils; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
final class ShadedNettyUtilsInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return failSafe(named("io.grpc.netty.shaded.io.grpc.netty.Utils")); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>(); | ||
transformers.put( | ||
isMethod().and(named("convertClientHeaders")).and(takesArguments(6)), | ||
ShadedNettyUtilsInstrumentation.class.getName() + "$Utils_convertClientHeaders_Advice"); | ||
transformers.put( | ||
isMethod().and(named("convertHeaders")).and(takesArguments(1)), | ||
ShadedNettyUtilsInstrumentation.class.getName() + "$GrpcUtils_convertHeaders_Advice"); | ||
return transformers; | ||
} | ||
|
||
static final class Utils_convertClientHeaders_Advice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void exit( | ||
@Advice.Argument(1) Object scheme, | ||
@Advice.Argument(2) Object defaultPath, | ||
@Advice.Argument(3) Object authority, | ||
@Advice.Argument(4) Object method) { | ||
|
||
Span currentSpan = Java8BytecodeBridge.currentSpan(); | ||
NettyUtils.handleConvertClientHeaders(scheme, defaultPath, authority, method, currentSpan); | ||
} | ||
} | ||
|
||
/** | ||
* There are multiple implementations of {@link Http2Headers}. Only some of them support getting | ||
* authority, path etc. For instance {@code GrpcHttp2ResponseHeaders} throws unsupported exception | ||
* when accessing authority etc. This header is used client response. | ||
* | ||
* @see {@link io.grpc.netty.GrpcHttp2HeadersUtils} | ||
*/ | ||
static final class GrpcUtils_convertHeaders_Advice { | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void exit( | ||
@Advice.Argument(0) Http2Headers http2Headers, @Advice.Return Metadata metadata) { | ||
|
||
NettyUtils.handleConvertHeaders(http2Headers, metadata); | ||
} | ||
} | ||
} |
Oops, something went wrong.