GithubHelp home page GithubHelp logo

Comments (4)

KarstenSchnitter avatar KarstenSchnitter commented on July 17, 2024

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.

amrit9326 avatar amrit9326 commented on July 17, 2024

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.

KarstenSchnitter avatar KarstenSchnitter commented on July 17, 2024

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.

KarstenSchnitter avatar KarstenSchnitter commented on July 17, 2024

@amrit9326: How are you progressing? Is this issue still relevant?

from cf-java-logging-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.