Comments (4)
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 tenantid
by the AddHttpHeadersToLogContextFilter.java Have a look at this constructor on how to take the header out of the list of propagated HTTP headers. There is also a section in the documentation on (custom header propagation)[https://github.com/SAP/cf-java-logging-support/wiki/Instrumenting-Servlets#custom-http-header-propagation]. You might also want to have a look at the ContextFieldSupplier interface documented here.
Best Regards,
Karsten
from cf-java-logging-support.
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?
Also I tried debugging where subdomain is being splitted and mapped with tenantID but didn't find anything so far.
from cf-java-logging-support.
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:
- Using the servlet filter this happens once when the request is received, storing the data in the MDC.
- Using the ContextFieldSupplier, the tenant id is extracted for every log event at the time the event is created. This can also override the value from other sources in the generated JSON, but not in the event itself. The latter is important, if the logs are collected by some other frameworks, e.g. OpenTelemetry.
from cf-java-logging-support.
@amrit9326: How are you progressing? Is this issue still relevant?
from cf-java-logging-support.
Related Issues (20)
- Log4j2 JsonPatternLayout might generate invalid JSON in v3.5.3 HOT 1
- Maven repo not updated HOT 2
- Custom Fields might lead to "java.lang.UnsupportedOperationException" with log4j2
- remote_user does not get set in the request logs HOT 12
- Cannot set logger level to INFO HOT 1
- Starting with version 3.6.0 exception causes are not logged HOT 7
- Request Logger no longer works without JsonEncoder since 3.6.0 HOT 2
- [Question] High operational risk for apache commons lang HOT 4
- Services using Custom metrics is not usable with all type of bindings HOT 1
- Add `exception_type` field to the logs HOT 4
- Log4j2 config - packages property for plugins will be deprecated HOT 3
- Log4j-slf4j-ipml artifact got moved to log4j-slf4j2-impl HOT 3
- Major Release 4.0 HOT 1
- Dynatrace Exporter uses "cumulative" temporality by default HOT 2
- Missing fields missing in Request log HOT 1
- Request for Incorporating MTLS X509 Certificate Authentication in Application Logging Service HOT 1
- Unexpected stall on logback warning HOT 3
- Investigate default Configuration of OpenTelemetry Java Agent, when Binding contains no CLS credentials HOT 1
- Is there a specific documentation or example github repo for referring the cloud logging service, to implement in the java based CAP application HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cf-java-logging-support.