Skip to content

Provide a robust CDI way to inject request_ids #3444

@obelix74

Description

@obelix74

Is your feature request related to a problem? Please describe.

Currently, there is no robust way to inject request_id using CDI. Approaches such as the following has been used in code.

private Optional<String> getRequestId() {
// See org.jboss.resteasy.reactive.server.injection.ContextProducers
ResteasyReactiveRequestContext context = CurrentRequestManager.get();
if (context != null) {
ContainerRequestContextImpl request = context.getContainerRequestContext();
String requestId = (String) request.getProperty(RequestIdFilter.REQUEST_ID_KEY);
return Optional.ofNullable(requestId);
}
return Optional.empty();
}

However, they only work for REST calls.

Describe the solution you'd like

As suggested by @dimas-b in https://github.com/apache/polaris/pull/3414/changes/BASE..4b6234774c01f3197f2aa78e79dc5d5cbe488ba7#r2692150954,

Please see how TaskExecutorImpl deals with realm IDs. A similar CDI pattern is probably necessary for request
IDs, except that we may not have to produce a request ID for background tasks. I do not have an opinion on whether request IDs should be propagated from REST requests to related async tasks or not. However, CDI must be solid and not cause runtime exceptions even if the request ID is not propagated.

Create a CDI pattern to inject request_ids.

Describe alternatives you've considered

Approaches tried so far include using REST context or SLF4J logging MDC, but both have their shortcomings.

private Optional<String> getRequestId() {
// See org.jboss.resteasy.reactive.server.injection.ContextProducers
ResteasyReactiveRequestContext context = CurrentRequestManager.get();
if (context != null) {
ContainerRequestContextImpl request = context.getContainerRequestContext();
String requestId = (String) request.getProperty(RequestIdFilter.REQUEST_ID_KEY);
return Optional.ofNullable(requestId);
}
return Optional.empty();
}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions