Skip to main content
Version: 2.7.0

Netty

Aperture Java Instrumentation Agent

All Netty pipelines can have an Aperture Handler automatically added into them using Aperture Instrumentation Agent.

Netty Handler

Aperture Java SDK Netty package contains a Handler that automatically creates traffic flows for requests in a given pipeline:
import com.fluxninja.aperture.netty.ApertureServerHandler;

...

public class ServerInitializer extends ChannelInitializer<Channel> {

...

@Override
protected void initChannel(Channel ch) {
String controlPointName = "someFeature";

sdk = ApertureSDK.builder().setHost(this.agentHost).setPort(this.agentPort).build();

ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
// ApertureServerHandler must be added before the response-generating HelloWorldHandler,
// but after the codec handler.
pipeline.addLast(new ApertureServerHandler(sdk, controlPointName));
pipeline.addLast(new HelloWorldHandler());
}
}

You can instruct the handler to exclude specific paths from being monitored by the Aperture SDK. For example, you might want to exclude endpoints used for health checks. To achieve this, you can add the path(s) you want to ignore to the ignoredPaths field of the SDK, as shown in the following code:

ApertureSDK sdk = ApertureSDK.builder()
.setHost(...)
.setPort(...)
...
.addIgnoredPaths("/healthz,/metrics")
...
.build()

The paths should be specified as a comma-separated list. Note that the paths you specify must match exactly. However, you can change this behavior to treat the paths as regular expressions by setting the ignoredPathMatchRegex flag to true, like so:

  builder
.setIgnoredPathMatchRegex(true)

For more context on using Aperture Netty Handler to set Control Points, refer to the example app available in the repository.