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

Use dedicated zapcore.Core for Windows service #3147

Merged
merged 1 commit into from
May 20, 2021

Conversation

rmfitzpatrick
Copy link
Contributor

@rmfitzpatrick rmfitzpatrick commented May 12, 2021

Description:
Fixing a bug - As reported in #2756 Windows service events only contain the zap entry message and none of the fields. These changes create a dedicated zapcore.Core to wrap the service logger's Core and use a production console encoder to encode the full entry, including its fields and stack if provided.

Link to tracking Issue:

#2756

Testing:

Tested manually with windows service. Currently examining unit test in addition to existing service test.

edit: I don't believe there's a clean* way to mock eventlog.Log sending in a unit test since* no interfaces are used and it resolves to a syscall: https://github.com/golang/sys/blob/94ec62e081691fed0145b707594111cee9cb360a/windows/zsyscall_windows.go#L1035.

@rmfitzpatrick rmfitzpatrick requested a review from a team May 12, 2021 19:48
Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I commented on this PR, apparently I forgot to submit and lost the comment, so doing it again.

I did not know we send our logs to Event Viewer on Windows.

Do we consider this to be a best practice? I think vast majority of app I saw on Windows simply log to a text file. Are we sure we are not doing a weird thing here by logging to Event Viewer?

(I understand it may be an official best practice recommended by Microsoft, but the tradition usually trumps official and I have yet to see any Windows app not written by Microsoft that puts its own logs in the Windows Event System).

Thoughts?

(Sorry for bringing this up only now, but I would like to know everyone's opinion and maybe delete the whole implementation if we don't believe it is the right approach).

@tigrannajaryan
Copy link
Member

@open-telemetry/collector-approvers (especially if you have Windows experience) what do you think about my comment above?

@bogdandrutu
Copy link
Member

bogdandrutu commented May 18, 2021

@reyang @victlu we need help :) maybe someone from MS can help us with this.

See #3147 (review) for the questions

@bogdandrutu
Copy link
Member

/cc @james-bebbington for thoughts about the initial implementation

@SergeyKanzhelev
Copy link
Member

My 2c: event viewer for logging brings more pain than benefits. If there any chance this can be abstracted out into -contrib, it will be better. Logs are likely will be a destination of choice for many operators

@victlu
Copy link

victlu commented May 18, 2021

@tigrannajaryan @bogdandrutu
I checked with one PM... If you are developing an app using a default "template", the Host will include EventLog (on Windows) as a logging provider. This is very nice on "cloud" platforms like Azure Web Apps where access to log files may not be as straight forward. It's also nice for on-prem platforms where your IT admin uses SCOM.

@SergeyKanzhelev
Copy link
Member

I checked with one PM... If you are developing an app using a default "template", the Host will include EventLog (on Windows) as a logging provider. This is very nice on "cloud" platforms like Azure Web Apps where access to log files may not be as straight forward. It's also nice for on-prem platforms where your IT admin uses SCOM.

Does these platforms justify this dependency on event log? Also, I don't think there were any efforts/recommendations writing to event log from Java apps, for example when I read https://docs.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#supported-log-types

@rmfitzpatrick
Copy link
Contributor Author

Not trying to weigh in on the windows service option's implementation and #2756 being under the radar, I will say the troubleshooting experience of the collector as a windows service is suboptimal and these changes provide much needed context for component issues. They don't resolve the problem for cases where other components stand up their own logger (like logging exporter) unless a shared core/sink is provided.

@tigrannajaryan
Copy link
Member

@tigrannajaryan @bogdandrutu
I checked with one PM... If you are developing an app using a default "template", the Host will include EventLog (on Windows) as a logging provider. This is very nice on "cloud" platforms like Azure Web Apps where access to log files may not be as straight forward. It's also nice for on-prem platforms where your IT admin uses SCOM.

@victlu do I understand it correct that if you run the Collector under Azure outputting the logs to Windows Event log results in more accessible logs? Is there a UI or something that shows them but no easy way to just see a file on the machine? Can you expand a bit?

If this is the case we may want to support it, but perhaps it can be a command line option and by default we output to stdout as usual.

@tigrannajaryan
Copy link
Member

Everyone, I created a separate issue to discuss whether we want to output to Event Viewer or no here #3241

Please continue the discussion there. I am going to review/merge this bug fix for now since it appears to be an obvious bug, but I still would like to discuss and decide whether going forward we want to keep the current behavior or delete and resort to regular logs.

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one minor naming nit.

service/application_windows.go Outdated Show resolved Hide resolved
@tigrannajaryan tigrannajaryan merged commit 2e84285 into open-telemetry:main May 20, 2021
@tigrannajaryan
Copy link
Member

@rmfitzpatrick does this fully fix #2756 ?

@rmfitzpatrick
Copy link
Contributor Author

@rmfitzpatrick does this fully fix #2756 ?

I believe so in general, but if there are still outliers (like not having events for standalone loggers) new issues could be reported w/ more context whose solutions would be guided by #3241's outcomes.

dashpole pushed a commit to dashpole/opentelemetry-collector that referenced this pull request Jun 14, 2021
As reported in open-telemetry#2756 Windows service events only contain the zap entry message and none of the fields.  These changes create a dedicated `zapcore.Core` to wrap the service logger's Core and use a production console encoder to encode the full entry, including its fields and stack if provided.

**Link to tracking Issue:**

open-telemetry#2756
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

Successfully merging this pull request may close these issues.

5 participants