⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -12,6 +12,7 @@
public class RequestContextConstants {
public static final String TENANT_ID_HEADER_KEY = "x-tenant-id";
public static final String REQUEST_ID_HEADER_KEY = "request-id";
public static final String CONTEXT_ID_HEADER_KEY = "context-id";

public static final Metadata.Key<String> TENANT_ID_METADATA_KEY =
Metadata.Key.of(TENANT_ID_HEADER_KEY, ASCII_STRING_MARSHALLER);
Expand All @@ -22,6 +23,7 @@ public class RequestContextConstants {
public static final Set<String> HEADER_PREFIXES_TO_BE_PROPAGATED =
Set.of(
TENANT_ID_HEADER_KEY,
CONTEXT_ID_HEADER_KEY,
Copy link
Contributor

Choose a reason for hiding this comment

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

What's context ID and how does it differ from request ID?

Copy link
Contributor Author

@iamajais iamajais Jan 13, 2026

Choose a reason for hiding this comment

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

context id will be kept same for all requests for a particular context i.e scan context. Depends on the individual client what they want to use as context-id. For our use case we will use scanId as context-id so that we can tail all the logs for a particular scan. We kept it different from request-id so that we can differentiate between multiple requests.

"X-B3-",
"grpc-trace-bin",
"traceparent",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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.REQUEST_ID_HEADER_KEY;
import static org.hypertrace.core.grpcutils.context.RequestContextConstants.TENANT_ID_HEADER_KEY;

import io.grpc.Context;
import io.grpc.Contexts;
Expand All @@ -27,6 +29,8 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
Optional.ofNullable(RequestContext.CURRENT.get())
.orElseGet(() -> RequestContext.fromMetadata(metadata));
Optional<String> opRequestId = currentContext.getHeaderValue(REQUEST_ID_HEADER_KEY);
Optional<String> opTenantId = currentContext.getHeaderValue(TENANT_ID_HEADER_KEY);
Optional<String> opContextId = currentContext.getHeaderValue(CONTEXT_ID_HEADER_KEY);
if (opRequestId.isEmpty()) {
opRequestId = Optional.of(FastUUIDGenerator.randomUUID().toString());
}
Expand Down Expand Up @@ -63,6 +67,8 @@ public void onComplete() {
public void onMessage(ReqT message) {
try {
MDC.put(REQUEST_ID_HEADER_KEY, requestId);
opTenantId.ifPresent(s -> MDC.put(TENANT_ID_HEADER_KEY, s));
opContextId.ifPresent(s -> MDC.put(CONTEXT_ID_HEADER_KEY, s));
} catch (Exception e) {
log.error("Error while setting request context details in MDC params", e);
}
Expand Down
Loading