-
Notifications
You must be signed in to change notification settings - Fork 16
feat : add support for handling grpc request url #284
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f5e92e1
added the utility method for gprc request URL
kotharironak b7f1e50
feat : add support for calc grpc request url
kotharironak aa21100
Merge branch 'main' into add-support-for-grpc-path
kotharironak 511d4cf
Merge branch 'main' into add-support-for-grpc-path
kotharironak c5a33e8
review: address comments of renaming enriched attributes name
kotharironak 95d82f5
Merge remote-tracking branch 'origin/add-support-for-grpc-path' into …
kotharironak 98c7646
fix: snyk failures
kotharironak 7e9febe
updates protobuf version
kotharironak d7dbdb3
going back to compatible version for proto libs
kotharironak d01bbcc
snyk issue, adds constrains for google proto
kotharironak 6acebae
updated .snyk file
kotharironak cd5d69d
fixed last two snyk issue
kotharironak 8e5b130
added constrain block for jersy lib
kotharironak 98a40ed
fixed snyk issues
kotharironak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
48 changes: 48 additions & 0 deletions
48
...rc/main/java/org/hypertrace/traceenricher/enrichment/enrichers/GrpcAttributeEnricher.java
This file contains hidden or 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,48 @@ | ||
| package org.hypertrace.traceenricher.enrichment.enrichers; | ||
|
|
||
| import static org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT; | ||
| import static org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants.GRPC_REQUEST_URL; | ||
|
|
||
| import java.util.Optional; | ||
| import org.hypertrace.core.datamodel.Event; | ||
| import org.hypertrace.core.datamodel.StructuredTrace; | ||
| import org.hypertrace.core.datamodel.shared.trace.AttributeValueCreator; | ||
| import org.hypertrace.semantic.convention.utils.rpc.RpcSemanticConventionUtils; | ||
| import org.hypertrace.traceenricher.enrichedspan.constants.utils.EnrichedSpanUtils; | ||
| import org.hypertrace.traceenricher.enrichedspan.constants.v1.Protocol; | ||
| import org.hypertrace.traceenricher.enrichment.AbstractTraceEnricher; | ||
|
|
||
| public class GrpcAttributeEnricher extends AbstractTraceEnricher { | ||
|
|
||
| private static final String GRPC_RECV_DOT = "Recv."; | ||
| private static final String GRPC_SENT_DOT = "Sent."; | ||
|
|
||
| @Override | ||
| public void enrichEvent(StructuredTrace trace, Event event) { | ||
| // if protocol is Grpc update attribute | ||
| Protocol protocol = EnrichedSpanUtils.getProtocol(event); | ||
| if (Protocol.PROTOCOL_GRPC == protocol) { | ||
| Optional<String> grpcRequestEndpoint = | ||
| RpcSemanticConventionUtils.getGrpcRequestEndpoint(event); | ||
| if (grpcRequestEndpoint.isPresent()) { | ||
| addEnrichedAttribute( | ||
| event, GRPC_REQUEST_ENDPOINT, AttributeValueCreator.create(grpcRequestEndpoint.get())); | ||
|
|
||
| String prefix = getPrefix(event); | ||
| addEnrichedAttribute( | ||
| event, | ||
| GRPC_REQUEST_URL, | ||
| AttributeValueCreator.create(prefix.concat(grpcRequestEndpoint.get()))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private String getPrefix(Event event) { | ||
| if (EnrichedSpanUtils.isEntrySpan(event)) { | ||
| return GRPC_RECV_DOT; | ||
| } else if (EnrichedSpanUtils.isExitSpan(event)) { | ||
| return GRPC_SENT_DOT; | ||
| } | ||
| return ""; | ||
| } | ||
| } |
125 changes: 125 additions & 0 deletions
125
...est/java/org/hypertrace/traceenricher/enrichment/enrichers/GrpcAttributeEnricherTest.java
This file contains hidden or 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,125 @@ | ||
| package org.hypertrace.traceenricher.enrichment.enrichers; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.hypertrace.core.datamodel.AttributeValue; | ||
| import org.hypertrace.core.datamodel.Event; | ||
| import org.hypertrace.core.datamodel.StructuredTrace; | ||
| import org.hypertrace.core.datamodel.shared.SpanAttributeUtils; | ||
| import org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants; | ||
| import org.hypertrace.traceenricher.enrichedspan.constants.v1.CommonAttribute; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mock; | ||
|
|
||
| public class GrpcAttributeEnricherTest extends AbstractAttributeEnricherTest { | ||
|
|
||
| @Mock private StructuredTrace mockTrace; | ||
|
|
||
| private final GrpcAttributeEnricher enricher = new GrpcAttributeEnricher(); | ||
|
|
||
| /* | ||
| * Covers cases of GrpcAttributeEnricher, the details cases of getGrpcRequestEndpoint | ||
| * are covered at RpcSemanticConventionUtilsTest | ||
| * */ | ||
| @Test | ||
| public void test_withAValidUrl_shouldEnrichHttpPathAndParams() { | ||
| // case 1: using event name prefixed with Recv | ||
| Event e = createMockEvent(); | ||
| when(e.getEventName()).thenReturn("Recv.TestService.GetEventEchos"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_PROTOCOL), "GRPC"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), "ENTRY"); | ||
|
|
||
| enricher.enrichEvent(mockTrace, e); | ||
|
|
||
| String grpcRequestUrl = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_URL); | ||
| assertEquals("Recv.TestService.GetEventEchos", grpcRequestUrl); | ||
|
|
||
| String grpcRequestEndPoint = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT); | ||
| assertEquals("TestService.GetEventEchos", grpcRequestEndPoint); | ||
|
|
||
| // case 2: using grpc.path | ||
| e = createMockEvent(); | ||
| when(e.getEventName()).thenReturn("TestService.GetEventEchos"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_PROTOCOL), "GRPC"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), "ENTRY"); | ||
| addAttribute(e, "grpc.path", "/TestGrpcService/GetGrpcPathEchos"); | ||
|
|
||
| enricher.enrichEvent(mockTrace, e); | ||
|
|
||
| grpcRequestUrl = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_URL); | ||
| assertEquals("Recv.TestGrpcService.GetGrpcPathEchos", grpcRequestUrl); | ||
|
|
||
| grpcRequestEndPoint = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT); | ||
| assertEquals("TestGrpcService.GetGrpcPathEchos", grpcRequestEndPoint); | ||
|
|
||
| // case 3: no grpc protocol | ||
| e = createMockEvent(); | ||
| when(e.getEventName()).thenReturn("TestService.GetEventEchos"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), "ENTRY"); | ||
| addAttribute(e, "grpc.path", "/TestGrpcService/GetGrpcPathEchos"); | ||
|
|
||
| enricher.enrichEvent(mockTrace, e); | ||
|
|
||
| grpcRequestUrl = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_URL); | ||
| assertNull(grpcRequestUrl); | ||
|
|
||
| grpcRequestEndPoint = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT); | ||
| assertNull(grpcRequestEndPoint); | ||
|
|
||
| // case 4: client call - EXIT | ||
| e = createMockEvent(); | ||
| when(e.getEventName()).thenReturn("TestService.GetEventEchos"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_PROTOCOL), "GRPC"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), "EXIT"); | ||
| addAttribute(e, "grpc.path", "/TestGrpcService/GetGrpcPathEchos"); | ||
|
|
||
| enricher.enrichEvent(mockTrace, e); | ||
|
|
||
| grpcRequestUrl = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_URL); | ||
| assertEquals("Sent.TestGrpcService.GetGrpcPathEchos", grpcRequestUrl); | ||
|
|
||
| grpcRequestEndPoint = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT); | ||
| assertEquals("TestGrpcService.GetGrpcPathEchos", grpcRequestEndPoint); | ||
|
|
||
| // case 5: no entry or exsit span (internal span) - not prefix sent / recv | ||
| e = createMockEvent(); | ||
| when(e.getEventName()).thenReturn("TestService.GetEventEchos"); | ||
| addAttribute( | ||
| e, EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_PROTOCOL), "GRPC"); | ||
| addAttribute(e, "grpc.path", "/TestGrpcService/GetGrpcPathEchos"); | ||
|
|
||
| enricher.enrichEvent(mockTrace, e); | ||
|
|
||
| grpcRequestUrl = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_URL); | ||
| assertEquals("TestGrpcService.GetGrpcPathEchos", grpcRequestUrl); | ||
|
|
||
| grpcRequestEndPoint = | ||
| SpanAttributeUtils.getStringAttribute(e, EnrichedSpanConstants.GRPC_REQUEST_ENDPOINT); | ||
| assertEquals("TestGrpcService.GetGrpcPathEchos", grpcRequestEndPoint); | ||
| } | ||
|
|
||
| private void addAttribute(Event event, String key, String val) { | ||
| event | ||
| .getAttributes() | ||
| .getAttributeMap() | ||
| .put(key, AttributeValue.newBuilder().setValue(val).build()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Is PROTOCOL and enriched attribute?
If yes, are these 2 dependencies good enough for that?
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.
Yes
PROTOCOLis enriched attributes, and these deps take care of both enriched attributes required by this enricher.Ref :
hypertrace-ingester/hypertrace-trace-enricher/hypertrace-trace-enricher-impl/src/main/java/org/hypertrace/traceenricher/enrichment/enrichers/SpanTypeAttributeEnricher.java
Line 177 in 76ecd76