-
Notifications
You must be signed in to change notification settings - Fork 48
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 Custom Tenant Id in Request Logging Filter #172
Comments
HI @amrit9326, thanks for creating the issue. I need a little while to investigate the issue. Here are some background informations to the way the tenant id is added, that might help until then: The tenant-id is taken from the HTTP header Best Regards, |
Hi @KarstenSchnitter , Right now the tenantID is being mapped with the subdomain and I want to map it with the SpringSecurityContext.getToken().getZoneId() . Could you please let us know from which part of code implementation this can be done? |
Besides reading the tenantId from the HTTP header, there is no instrumentation for tenant ids in this library. That means, there is some other library, that is setting the tenant id on your behalf. I suggest to have a look at SAP Cloud ALM, if you use that. There is an old issue #122, that shows an implementation of a servlet filter, that adds a field to all log messages from the Spring Security context. Note, that it is not adding the tenant-id back as an HTTP header, but writes it directly to the MDC (wrapped by the LogContext). An alternative approach is to implement a ContextFieldSupplier like this: package my.package;
public class TenantIdSupplier implements ContextFieldSupplier {
@Override
public Map<String, Object> get() {
return new HashMap<>() {{
put(Fields.TENANT_ID, SpringSecurityContext.getToken().getZoneId());
}};
}
} You than need to add this class to your logback configuration as indicated here, e.g. a snippet for logback: <appender name="STDOUT-JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="com.sap.hcp.cf.logback.encoder.JsonEncoder">
<contextFieldSupplier>my.package.TenantIdSupplier</contextFieldSupplier>
<!-- all other configuraton -->
</encoder>
</appender> The difference between both approaches is, when and how often the tenant id is extracted from the SecurityContext:
|
@amrit9326: How are you progressing? Is this issue still relevant? |
Hi Team,
We're trying to add custom tenantID in the request logging filter but couldn't find anyway of doing it , it's taking the tenantID from the subdomain by default which we don't want.
We tried adding the tenantID by extending the different filter classes and overriding it's method where we're modifying the request header by adding the tenantID but it's being overrided with the subdomain.
Please check the code below
Please check the image below where tenantID is dvh and we're trying to replace it with some guid.
The text was updated successfully, but these errors were encountered: