-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gRPC observation instrumentation #110
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
.../main/java/io/micrometer/tracing/instrument/grpc/GrpcClientTracingObservationHandler.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,42 @@ | ||
package io.micrometer.tracing.instrument.grpc; | ||
|
||
import io.micrometer.common.util.internal.logging.InternalLogger; | ||
import io.micrometer.common.util.internal.logging.InternalLoggerFactory; | ||
import io.micrometer.core.instrument.binder.grpc.GrpcClientObservationContext; | ||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.Tracer; | ||
import io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler; | ||
import io.micrometer.tracing.handler.TracingObservationHandler; | ||
import io.micrometer.tracing.propagation.Propagator; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* {@link TracingObservationHandler} for gRPC in client side. | ||
* | ||
* @author Tadaya Tsuyukubo | ||
*/ | ||
public class GrpcClientTracingObservationHandler | ||
extends PropagatingSenderTracingObservationHandler<GrpcClientObservationContext> { | ||
|
||
private static final InternalLogger log = InternalLoggerFactory | ||
.getInstance(GrpcClientTracingObservationHandler.class); | ||
|
||
public GrpcClientTracingObservationHandler(Tracer tracer, Propagator propagator) { | ||
super(tracer, propagator); | ||
} | ||
|
||
@Override | ||
public void customizeSenderSpan(GrpcClientObservationContext context, Span span) { | ||
String authority = context.getAuthority(); | ||
try { | ||
URI uri = new URI(null, authority, null, null, null); | ||
span.remoteIpAndPort(uri.getHost(), uri.getPort()); | ||
} | ||
catch (Exception ex) { | ||
log.warn("Exception [{}], occurred while trying to parse the authority [{}] to host and port.", ex, | ||
authority); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
.../main/java/io/micrometer/tracing/instrument/grpc/GrpcServerTracingObservationHandler.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,45 @@ | ||
package io.micrometer.tracing.instrument.grpc; | ||
|
||
import io.micrometer.common.util.internal.logging.InternalLogger; | ||
import io.micrometer.common.util.internal.logging.InternalLoggerFactory; | ||
import io.micrometer.core.instrument.binder.grpc.GrpcServerObservationContext; | ||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.Tracer; | ||
import io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler; | ||
import io.micrometer.tracing.handler.TracingObservationHandler; | ||
import io.micrometer.tracing.propagation.Propagator; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* {@link TracingObservationHandler} for gRPC in server side. | ||
* | ||
* @author Tadaya Tsuyukubo | ||
*/ | ||
public class GrpcServerTracingObservationHandler | ||
extends PropagatingReceiverTracingObservationHandler<GrpcServerObservationContext> { | ||
|
||
private static final InternalLogger log = InternalLoggerFactory | ||
.getInstance(GrpcServerTracingObservationHandler.class); | ||
|
||
public GrpcServerTracingObservationHandler(Tracer tracer, Propagator propagator) { | ||
super(tracer, propagator); | ||
} | ||
|
||
@Override | ||
public Span.Builder customizeExtractedSpan(GrpcServerObservationContext context, Span.Builder builder) { | ||
String authority = context.getAuthority(); | ||
if (authority != null) { | ||
try { | ||
URI uri = new URI(null, authority, null, null, null); | ||
builder.remoteIpAndPort(uri.getHost(), uri.getPort()); | ||
} | ||
catch (Exception ex) { | ||
log.warn("Exception [{}], occurred while trying to parse the authority [{}] to host and port.", ex, | ||
authority); | ||
} | ||
} | ||
return builder; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
.../java/io/micrometer/tracing/instrument/grpc/GrpcClientTracingObservationHandlerTests.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,51 @@ | ||
package io.micrometer.tracing.instrument.grpc; | ||
|
||
import io.micrometer.core.instrument.binder.grpc.GrpcClientObservationContext; | ||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.Tracer; | ||
import io.micrometer.tracing.propagation.Propagator; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* Tests for {@link GrpcClientTracingObservationHandler}. | ||
* | ||
* @author Tadaya Tsuyukubo | ||
*/ | ||
class GrpcClientTracingObservationHandlerTests { | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void customizeSenderSpan(String authority, String host, int port) { | ||
Tracer tracer = mock(Tracer.class); | ||
Propagator propagator = mock(Propagator.class); | ||
GrpcClientTracingObservationHandler handler = new GrpcClientTracingObservationHandler(tracer, propagator); | ||
|
||
GrpcClientObservationContext context = new GrpcClientObservationContext((carrier, key, value) -> { | ||
}); | ||
context.setAuthority(authority); | ||
|
||
Span span = mock(Span.class); | ||
handler.customizeSenderSpan(context, span); | ||
|
||
verify(span).remoteIpAndPort(host, port); | ||
} | ||
|
||
static Stream<Arguments> customizeSenderSpan() { | ||
// @formatter:off | ||
return Stream.of( | ||
arguments("io.micrometer.grpc:12345", "io.micrometer.grpc", 12345), | ||
arguments("localhost:12345", "localhost", 12345), | ||
arguments("localhost", "localhost", -1) | ||
); | ||
// @formatter:on | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
.../java/io/micrometer/tracing/instrument/grpc/GrpcServerTracingObservationHandlerTests.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,65 @@ | ||
package io.micrometer.tracing.instrument.grpc; | ||
|
||
import io.micrometer.core.instrument.binder.grpc.GrpcServerObservationContext; | ||
import io.micrometer.tracing.Span; | ||
import io.micrometer.tracing.Tracer; | ||
import io.micrometer.tracing.propagation.Propagator; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* Tests for {@link GrpcServerTracingObservationHandler}. | ||
* | ||
* @author Tadaya Tsuyukubo | ||
*/ | ||
class GrpcServerTracingObservationHandlerTests { | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void customizeExtractedSpan(String authority, String host, int port) { | ||
Tracer tracer = mock(Tracer.class); | ||
Propagator propagator = mock(Propagator.class); | ||
GrpcServerTracingObservationHandler handler = new GrpcServerTracingObservationHandler(tracer, propagator); | ||
|
||
GrpcServerObservationContext context = new GrpcServerObservationContext((carrier, key) -> null); | ||
context.setAuthority(authority); | ||
|
||
Span.Builder builder = mock(Span.Builder.class); | ||
handler.customizeExtractedSpan(context, builder); | ||
|
||
verify(builder).remoteIpAndPort(host, port); | ||
} | ||
|
||
@Test | ||
void customizeExtractedSpanWithNull() { | ||
Tracer tracer = mock(Tracer.class); | ||
Propagator propagator = mock(Propagator.class); | ||
GrpcServerTracingObservationHandler handler = new GrpcServerTracingObservationHandler(tracer, propagator); | ||
|
||
GrpcServerObservationContext context = new GrpcServerObservationContext((carrier, key) -> null); | ||
context.setAuthority(null); | ||
|
||
Span.Builder builder = mock(Span.Builder.class); | ||
handler.customizeExtractedSpan(context, builder); | ||
|
||
verifyNoInteractions(builder); | ||
} | ||
|
||
static Stream<Arguments> customizeExtractedSpan() { | ||
// @formatter:off | ||
return Stream.of( | ||
arguments("io.micrometer.grpc:12345", "io.micrometer.grpc", 12345), | ||
arguments("localhost:12345", "localhost", 12345), | ||
arguments("localhost", "localhost", -1) | ||
); | ||
// @formatter:on | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Medium Vulnerability:
maven : io.grpc/grpc-api : 1.50.2
0 Critical, 0 High, 1 Medium, 0 Low vulnerabilities have been found across 1 dependencies.
View the Lift console for details about these vulnerabilities.
ℹ️ Learn about @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]