Skip to content

Conversation

@khushijain21
Copy link
Contributor

@khushijain21 khushijain21 commented Jun 25, 2025

What does this PR do?

This PR adds support for logging.event_data for beatreceivers running from EA. The idea is that all documents containing sensitive information should be logged to separate -event.log file.

Beats' adds a field called log.type:event to log messages containing sensitive information Ref and
typedLoggerCore looks for the presence of this key-value pair. If exists, it logs to -event.log file.

Documents rejected by ES-exporter also fall in this category. We add a new field called message on typedLogger. If a log entry contains this message, it is "also" logged using typedLogger.

Why is it important?

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

Related issues

@mauri870
Copy link
Member

mauri870 commented Jun 25, 2025

I don't see anything out of place, it's just missing a test for ConfigureOTelCore.

@khushijain21 khushijain21 changed the title Add support for logging.event_data Add support for logging.event_data in beatreceivers Jun 26, 2025
@khushijain21 khushijain21 changed the title Add support for logging.event_data in beatreceivers Add support for logging.event_data in beatreceivers Jun 26, 2025
logp/core.go Outdated

// ConfigureEventLoggingOTel takes a list log messages expected to contain sensitive data
// and ensures they are logged using typed logger
func ConfigureEventLoggingOTel(typedMsg []string, core zapcore.Core) (*Logger, error) {
Copy link
Contributor Author

@khushijain21 khushijain21 Jun 26, 2025

Choose a reason for hiding this comment

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

typedMsg is a log message snippet that we expect to contain sensitive information

typedMsg should be passed as failed to index document; input may contain sensitive data to log failed docs from ES exporter to -event.log file.
[Ref] https://github.com/open-telemetry/opentelemetry-collector-contrib//blob/main/exporter/elasticsearchexporter/bulkindexer.go#L384

@khushijain21 khushijain21 requested a review from leehinman June 26, 2025 05:37
@pchila
Copy link
Member

pchila commented Jun 26, 2025

@khushijain21 Could you please explain why a logger package in a library should concern itself with Otel or event logging filtering ? Those are concepts that are specific to the related applications (elastic-agent in this case) so I feel that we are giving the library additional responsibilities that do not belong in a generic logging package

@khushijain21
Copy link
Contributor Author

khushijain21 commented Jun 26, 2025

@pchila
So elastic-agent already uses typedLoggerCore to filter events based on provided key-value pair.
https://github.com/khushijain21/elastic-agent/blob/eventLogging/pkg/core/logger/logger.go#L133

We are only extending that functionality to include certain "log message snippets". If these log message exists - we log them using typedCore. This was specifically required for OTel hence the naming of new methods, but I could make them generic.

The logp package is concerned here because where and how events are logged comes from user configuration, and we want certain log message (coming from the OTel world) to use the same core. I hope that makes sense

@khushijain21 khushijain21 marked this pull request as ready for review June 26, 2025 10:19
@khushijain21 khushijain21 requested a review from a team as a code owner June 26, 2025 10:19
@khushijain21 khushijain21 requested review from AndersonQ and removed request for a team June 26, 2025 10:19
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Comment on lines +256 to +257
defaultCore: core,
typedCore: core,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this print all the messages for this logger to core? defaultCore and typedCore are same.

Copy link
Contributor Author

@khushijain21 khushijain21 Jun 26, 2025

Choose a reason for hiding this comment

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

Think of this as a core on top of an existing typeLoggerCore. The core passed to this method takes care of re-routing the logs correctly. All this does is add additional fields if a message exists.

The assumption of this method is that the output is already defined. The description also explains that

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[beat_receivers] Redact or drop logs that could contain event data in the monitoring filestream instance

6 participants