Skip to content
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

only custom logger appender on collector #240

Closed
mosinnik opened this issue Oct 29, 2023 · 7 comments
Closed

only custom logger appender on collector #240

mosinnik opened this issue Oct 29, 2023 · 7 comments

Comments

@mosinnik
Copy link

In log-appender example after running Application I found only custom appender logs in collectors logs.
Log4j, logback and also JUL logs lost.

Looks like lost setup of OpenTelemetryAppender because all work fine after adding follow code after initializeOpenTelemetry(); (https://github.com/open-telemetry/opentelemetry-java-examples/blob/main/log-appender/src/main/java/io/opentelemetry/example/logappender/Application.java#L35)

    io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender.install(GlobalOpenTelemetry.get());
    io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender.install(GlobalOpenTelemetry.get());
@trask
Copy link
Member

trask commented Oct 31, 2023

hi @mosinnik! yes, this example should be fixed, the underlying logging instrumentation changed a few months ago and no longer uses the GlobalOpenTelemetry, and requires an explicit .install()

@QuinnBast
Copy link

Even using the .install() method does not work:

log4j.xml Pattern:

<PatternLayout>
    <Pattern>%date{YYYY-MM-dd_HH:mm:ss.SSS}|%thread|%msg|%level|%X{trace_id}|%X{span_id}%n</Pattern>
</PatternLayout>

Log statement:

// In my main:
val OTEL = AutoConfiguredOpenTelemetrySdk.initialize().openTelemetrySdk
OpenTelemetryAppender.install(OTEL)

// Within a trace context:
logger.info("{uuid=\"{}\",traceId=\"{}\"}: Received Request", uuid, Span.current().spanContext.traceId)

Output does not contain the trace ID or span ID, but the logger line that manually grabbed the trace ID is reporting it:

2024-04-25_15:01:50.277|DefaultDispatcher-worker-20|{uuid="0ab05c2d-6ad8-4b6d-af56-d066e8d574b7",traceId="d036777c48abe26432cbbbc6434ea7b3"}: Received Request|INFO||

@jaydeluca
Copy link
Member

jaydeluca commented Sep 22, 2024

this was fixed by #282

You can now see all the logs in the collector:

Example:

2024-09-22T10:18:47.928Z        info    LogsExporter    {"kind": "exporter", "data_type": "logs", "name": "debug", "resource logs": 1, "log records": 13}
2024-09-22T10:18:47.928Z        info    ResourceLog #0
Resource SchemaURL: 
Resource attributes:
     -> service.name: Str(log4j-example)
     -> telemetry.sdk.language: Str(java)
     -> telemetry.sdk.name: Str(opentelemetry)
     -> telemetry.sdk.version: Str(1.42.1)
ScopeLogs #0
ScopeLogs SchemaURL: 
InstrumentationScope log4j-logger 
LogRecord #0
ObservedTimestamp: 2024-09-22 10:18:47.727881 +0000 UTC
Timestamp: 2024-09-22 10:18:47.721882 +0000 UTC
SeverityText: INFO
SeverityNumber: Info(9)
Body: Str(A log4j log message without a span)
Attributes:
     -> thread.id: Int(1)
     -> thread.name: Str(main)


.....

@QuinnBast
Copy link

QuinnBast commented Sep 23, 2024

The referenced MR was merged back in December 2023.

In the comment I left, I was using OpenTelemetry version 1.37.0 which was released April 8th. This release would have included the referenced MR from December, so I don't believe that this has been fixed, since I was trying a later version of OpenTelemetry.

@jaydeluca
Copy link
Member

@QuinnBast apologies for any confusion. I closed this issue because what was reported - appenders not being correctly installed to send messages to the collector in the documented examples - has been addressed and is working now.

I could be mistaken but I don't think your comment is talking about the same thing? If that is the case, would you mind opening up a new issue detailing your problem?

@QuinnBast
Copy link

You might be right. I don't think my issue is specifically about the java-examples repo, I think this is an issue for the java OpenTelemetry client itself, but I'm not really sure where that repo is to open an issue on it?

@trask
Copy link
Member

trask commented Sep 23, 2024

hi @QuinnBast, this is probably the component you're using? https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/log4j/log4j-appender-2.17/library

if so you can open issue in that repo, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants