Skip to content

Commit

Permalink
grizzly-http-server: use instrumentation decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
jam01 committed Jul 11, 2020
1 parent 689faf5 commit 471d635
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
16 changes: 15 additions & 1 deletion rule/grizzly-http-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<properties>
<sa.rule.name>grizzly:http-server</sa.rule.name>
<min.version>2.3.35</min.version>
<version.opentracing.grizzly>0.1.3</version.opentracing.grizzly>
<version.opentracing.grizzly>0.1.4-SNAPSHOT</version.opentracing.grizzly>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -57,6 +57,20 @@
</plugins>
</build>
<dependencies>
<dependency>
<!-- https://github.com/opentracing-contrib/java-grizzly-http-server -->
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-grizzly-http-server</artifactId>
<version>${version.opentracing.grizzly}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-grizzly-http-server</artifactId>
<version>${version.opentracing.grizzly}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.contrib.grizzly.http.server.GrizzlyServerSpanDecorator;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.tag.Tags;
Expand Down Expand Up @@ -37,15 +38,10 @@ public static void onHandleReadExit(
final Span span = tracer.buildSpan("HTTP::" + request.getMethod().getMethodString())
.ignoreActiveSpan()
.asChildOf(extractedContext)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();

Tags.COMPONENT.set(span, "java-grizzly-http-server");
Tags.HTTP_METHOD.set(span, request.getMethod().getMethodString());
Tags.HTTP_URL.set(span, request.getRequestURI());

ctx.addCompletionListener(new ScopeCompletionListener(span));

GrizzlyServerSpanDecorator.STANDARD_TAGS.onRequest(request, span);
ctx.addCompletionListener(new SpanCompletionListener(span));
SpanAssociations.get().associateSpan(ctx, span);
}

Expand All @@ -54,14 +50,14 @@ public static void onPrepareResponse(
final Object response) {
Span toTag = SpanAssociations.get().retrieveSpan(ctx);
if (toTag != null) {
Tags.HTTP_STATUS.set(toTag, ((HttpResponsePacket) response).getStatus());
GrizzlyServerSpanDecorator.STANDARD_TAGS.onResponse((HttpResponsePacket) response, toTag);
}
}

public static class ScopeCompletionListener implements FilterChainContext.CompletionListener {
public static class SpanCompletionListener implements FilterChainContext.CompletionListener {
private final Span span;

public ScopeCompletionListener(Span span) {
public SpanCompletionListener(Span span) {
this.span = span;
}

Expand Down

0 comments on commit 471d635

Please sign in to comment.