open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.98k stars 865 forks source link

logback encoder field becomes decoded with otel java instrumentation agent #12757

Open howan36 opened 2 days ago

howan36 commented 2 days ago
    <springProfile name="prod">
        <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
                <layout class="com.ikea.common.spring.filter.http.CustomPatternLayout">
                    <maskPattern>(?:name|firstName|lastName|customerName)\s*(?:=|:)\s*(.+?) .</maskPattern>
                    <maskPattern>(?:address1|customerAddress)\s*(?:=|:)\s*(.+?) .</maskPattern>
                    <maskPattern>\\?"(?:address1|customerAddress)\\?"\s*:\s*\\?"(.+?)\\?"</maskPattern>
                    <maskPattern>\\?"(?:name|firstName|lastName|customerName)\\?"\s*:\s*\\?"(.+?)\\?"</maskPattern>
                    <hashPattern>\\?"(?:mobile|phone|phoneNumber|communicationPhone)\\?"\s*:\s*\\?"([+\d]+)\\?"</hashPattern>
                    <hashPattern>(?:PHONE|phone|phoneNumber|communicationPhone|mobile)\s*(?:=|:)\s*([+\d]+)</hashPattern>
                    <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [trace_id=%X{trace_id} span_id=%X{span_id}] [%p][%c#%M:%L] -> %m%n</pattern>
                </layout>
            </encoder>
        </appender>

        <root level="info">
            <appender-ref ref="CONSOLE"/>
        </root>
    </springProfile>

we use the above config to encode some sensitive field, but after received from collector, it becomes decoded

howan36 commented 2 days ago

if there are some configurations could solve that, or something missing from my side

howan36 commented 2 days ago
laurit commented 2 days ago

The layout patterns you have configured are for the console appender. Otel appender is not connected to the console appender and does not use this configuration. I believe you can use the collector to apply these patterns to the log data.

howan36 commented 2 days ago

ok, thanks a lot @laurit , besides, if otel log appender could output the log format to json, i found some field s were extracted to attributes labels, and the log body seems to be text mode

howan36 commented 2 days ago

for example,

200 OK GET https://xxxxxxxx/link-service/api/routes/updatedAt {"origin":"local","type":"request","correlation":"fdddd","protocol":"HTTP/1.1","remote":"api-devdddddd.cn.cnapp-ddl/61.170.77.230:443","method":"GET","uri":"https://addsd/lidsddsds/api/routes/updatedAt","host":"api-dedsdsdds","path":"/link-service/api/routes/updatedAt","scheme":"https","port":"443","headers":{"accept":["*/*"],"accept-encoding":["gzip"],"apiKey":["dsdssd"],"b3":["f08320df111ab165bbsdsdsddssdc9012e98651ee0-1"],"host":["sddsddssdds"],"traceparent":["00-12e98651ee0-01"],"user-agent":["ReactorNetty/1.1.20"]}} |     |  

howan36 commented 2 days ago

for this log, the first row is the original message, and the json is the content i use transform processor to concat from attributes, if they could combine into 1 big json

laurit commented 1 day ago

I don't follow what the ask is here. Otel appender dispatches data to the exporter which decides the output format, by default otlp is used.