Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public class RequestContextConstants {

public static final String AUTHORIZATION_HEADER = "authorization";

public static final String CTX_HEADER_PREFIX = "x-ctx-";

/** The values in this set are looked up with case insensitivity. */
public static final Set<String> HEADER_PREFIXES_TO_BE_PROPAGATED =
Set.of(
TENANT_ID_HEADER_KEY,
CONTEXT_ID_HEADER_KEY,
SUPPRESS_USER_TRACKING_HEADER_KEY,
CTX_HEADER_PREFIX,
"X-B3-",
"grpc-trace-bin",
"traceparent",
Expand Down
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";
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CTX_SCAN_ID_HEADER_KEY is a request-context header constant, but it's defined in ScanMetadataBuilder rather than alongside the other shared header constants in RequestContextConstants (e.g., TENANT_ID_HEADER_KEY, REQUEST_ID_HEADER_KEY, CTX_HEADER_PREFIX). Moving it (and optionally a Metadata.Key<String> form) into RequestContextConstants would make it easier for other modules to consistently reference the same header name and avoid duplication.

Suggested change
public static final String CTX_SCAN_ID_HEADER_KEY = "x-ctx-scan-id";
private static final String CTX_SCAN_ID_HEADER_KEY = "x-ctx-scan-id";

Copilot uses AI. Check for mistakes.

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;
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScanMetadataBuilder is a new API surface for constructing outbound metadata, but there are no unit tests validating that the expected keys/values are set (tenant, request-id, and scan-id). Since grpc-context-utils already has a test suite, adding a small test for ScanMetadataBuilder.build(...) would help catch accidental header name regressions.

Copilot uses AI. Check for mistakes.
}
}
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;

Expand Down Expand Up @@ -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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x-ctx-tenant-id
x-ctx-request-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))
Comment thread
iamajais marked this conversation as resolved.
Comment thread
iamajais marked this conversation as resolved.
.forEach(header -> MDC.put(header.getName(), header.getValue()));
Comment thread
iamajais marked this conversation as resolved.
} catch (Exception e) {
log.error("Error while setting request context details in MDC params", e);
}
Expand Down
Loading