-
Notifications
You must be signed in to change notification settings - Fork 885
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 request metadata instrumentation #7011
Merged
trask
merged 45 commits into
open-telemetry:main
from
Tavh:6991-implement-grpc-request-metadata
Jan 18, 2023
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
c6f544b
Added gRPC request instrumentation
Tavh 7830c0f
spotless
Tavh 045a616
applied spotless to grpc-1.6:javaagent
Tavh 33f2232
applied spotless to grpc-1.6:library
Tavh bc79e30
Changed GRPC_METADATA_ATTRIBUTE_VALUE_PREFIX to RPC_REQUEST_METADATA_…
Tavh 4c90987
grpcRequestMetadata -> rpcRequestMetadata
Tavh 5c302bb
grpcRequestMetadata -> rpcRequestMetadata
Tavh cdd31b2
removed onEnd from comment
Tavh cf1649f
changed requestMetadataValuesToCapture to capturedRequestMetadata
Tavh e0391fd
spotless
Tavh ae0783b
spotless
Tavh 1b842ee
spotless
Tavh f8ed4e4
!= null to !empty
Tavh 99e65a5
requestMetadataValuesToCapture -> capturedRequestMetadata
Tavh bd73355
spotless & made METADATA_KEY protected
Tavh 1b14f73
Initialized capturedRequestMetadata as empty list
Tavh 5112050
Removed . from comment
Tavh 3699771
Added . to comment
Tavh 577d98a
capture metadata config rpc -> grpc
Tavh 0809704
dot
Tavh 92e98ac
Split into client/server config
trask 0135af8
Merge pull request #1 from trask/6991-implement-grpc-request-metadata
Tavh 80a8e69
Update build.gradle.kts
Tavh ad399ce
fix test
Tavh 095e7e9
fix test
Tavh 50776df
modified grpc test
Tavh a9122fd
spotless
Tavh 1300621
Fixed test
Tavh e8ef646
spotless
Tavh 45fa0e7
changed test values
Tavh ba9cd2d
spotless
Tavh 2801919
comment
Tavh 83d9a08
comment
Tavh fcbae3c
Merge branch 'main' into 6991-implement-grpc-request-metadata
Tavh a9d290c
removed null checks
Tavh 5c75ecc
removed nullcheck
Tavh e2fbb6c
fixed compilation error
Tavh bb30c18
spotless
Tavh ffdb462
Moved metadata capture to request start
Tavh 1b207c9
Moved metadata capture to request start
Tavh 0026c0d
spotless
Tavh 1ef28b6
moved attributes capture back to request end
Tavh 23a8daf
revert comment
Tavh 6e42047
renamed prefix
Tavh bea9394
spotless
Tavh 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 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
38 changes: 38 additions & 0 deletions
38
...ry/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/CapturedGrpcMetadataUtil.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,38 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.grpc.v1_6; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.stream.Collectors; | ||
|
||
final class CapturedGrpcMetadataUtil { | ||
private static final String RPC_REQUEST_METADATA_KEY_ATTRIBUTE_PREFIX = | ||
"rpc.grpc.request.metadata."; | ||
private static final ConcurrentMap<String, AttributeKey<List<String>>> requestKeysCache = | ||
new ConcurrentHashMap<>(); | ||
|
||
static List<String> lowercase(List<String> names) { | ||
return unmodifiableList( | ||
names.stream().map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList())); | ||
} | ||
|
||
static AttributeKey<List<String>> requestAttributeKey(String metadataKey) { | ||
return requestKeysCache.computeIfAbsent( | ||
metadataKey, CapturedGrpcMetadataUtil::createRequestKey); | ||
} | ||
|
||
private static AttributeKey<List<String>> createRequestKey(String metadataKey) { | ||
return AttributeKey.stringArrayKey(RPC_REQUEST_METADATA_KEY_ATTRIBUTE_PREFIX + metadataKey); | ||
} | ||
|
||
private CapturedGrpcMetadataUtil() {} | ||
} |
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
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 it possible to capture attributes on start so they can be used for sampling?
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.
@trask Capture them only at start or at both start and end?
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.
can they be different at those two times?
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.
@trask Not sure what you mean by 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.
sorry, I mean, if you capture the request metadata in onStart, is there a reason to capture them in onEnd also?
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.
@trask So do you think it should only be on start?
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.
if we don't know of any reason to also be on end, then let's start with "only on start"
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.
@trask
Status capture has to be on end because it doesn't exist at start.
I moved the metadata capture to start though