-
Notifications
You must be signed in to change notification settings - Fork 1
Distributted logging for scan-id #90
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
8ad6a12
da6be47
5085a8c
de6ab58
07fdd5e
87e7cc7
4e89675
1f764b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.hypertrace.core.grpcutils.context; | ||
|
|
||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.REQUEST_ID_HEADER_KEY; | ||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.TENANT_ID_HEADER_KEY; | ||
|
|
||
| import io.grpc.Metadata; | ||
|
|
||
| public class ScanMetadataBuilder { | ||
|
|
||
| public static final String CTX_SCAN_ID_HEADER_KEY = "x-ctx-scan-id"; | ||
|
|
||
| public static Metadata build(String tenantId, String requestId, String scanId) { | ||
| Metadata metadata = new Metadata(); | ||
| metadata.put(Metadata.Key.of(TENANT_ID_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER), tenantId); | ||
| metadata.put( | ||
| Metadata.Key.of(REQUEST_ID_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER), requestId); | ||
| metadata.put(Metadata.Key.of(CTX_SCAN_ID_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER), scanId); | ||
| return metadata; | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package org.hypertrace.core.grpcutils.server; | ||
|
|
||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.CONTEXT_ID_HEADER_KEY; | ||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.CTX_HEADER_PREFIX; | ||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.REQUEST_ID_HEADER_KEY; | ||
| import static org.hypertrace.core.grpcutils.context.RequestContextConstants.TENANT_ID_HEADER_KEY; | ||
|
|
||
|
|
@@ -69,6 +70,9 @@ public void onMessage(ReqT message) { | |
| MDC.put(REQUEST_ID_HEADER_KEY, requestId); | ||
| opTenantId.ifPresent(s -> MDC.put(TENANT_ID_HEADER_KEY, s)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x-ctx-tenant-id and remove existing manual insertion of tenant and request id |
||
| opContextId.ifPresent(s -> MDC.put(CONTEXT_ID_HEADER_KEY, s)); | ||
| currentContext.getAllHeaders().stream() | ||
| .filter(header -> header.getName().startsWith(CTX_HEADER_PREFIX)) | ||
|
iamajais marked this conversation as resolved.
iamajais marked this conversation as resolved.
|
||
| .forEach(header -> MDC.put(header.getName(), header.getValue())); | ||
|
iamajais marked this conversation as resolved.
|
||
| } catch (Exception e) { | ||
| log.error("Error while setting request context details in MDC params", e); | ||
| } | ||
|
|
||
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.
CTX_SCAN_ID_HEADER_KEYis a request-context header constant, but it's defined inScanMetadataBuilderrather than alongside the other shared header constants inRequestContextConstants(e.g.,TENANT_ID_HEADER_KEY,REQUEST_ID_HEADER_KEY,CTX_HEADER_PREFIX). Moving it (and optionally aMetadata.Key<String>form) intoRequestContextConstantswould make it easier for other modules to consistently reference the same header name and avoid duplication.