Skip to content

[processor/dnslookup] Add log processing and host file resolver #40910

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

kaisecheng
Copy link
Contributor

@kaisecheng kaisecheng commented Jun 24, 2025

Description

This PR adds log processing for DNS Lookup Processor and implements host files resolver.
The Resolver interface defines Resolve() for forward lookup and Reverse() for reverse lookup.
Hostfile resolver supports a list of hostfiles to resolve IP <> hostname.

Config

  dnslookup:
    # Forward DNS resolution configuration (hostname to IP)
    resolve:
      # Context for attributes: "resource" or "record". Default: "resource"
      context: "record"
      # List of attributes to check for hostnames. The first valid hostname is used. Default: ["source.address"]
      source_attributes: ["source.address"]
      # Attribute to store the resolved IP.  Default: "source.ip"
      target_attribute: "source.ip"

    # Reverse DNS resolution configuration (IP to hostname)
    reverse:
      # Context for attributes: "resource" or "record". Default: "resource"
      context: "record"
      # List of attributes to check for IPs. The first valid IP is used. Default: ["source.ip"]
      source_attributes: ["server.ip"]
      # Attribute to store the resolved hostname. Default: "source.address"
      target_attribute: "server.address"
    
    # Path to custom host files. Default: []
    hostfiles: 
      - "/path/to/host/file"
      - "/path/to/other/file"

nameserver resolver, system default resolver and cache implementation will be in the next PR

Link to tracking issue

Parts of #34398

Testing

  • integration tests for log processor
  • unit tests for hostfile resolver

Documentation

  • added README.md

@kaisecheng kaisecheng changed the title [processor/dnslookup] Implemented log processing and host file resolver [processor/dnslookup] Add log processing and host file resolver Jun 25, 2025
- `record`: Attributes within a data point, log record or a span.
- `source_attributes`: An array of attribute names, which are used for lookup. The first valid hostname/IP is used.
- [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.32.0/docs/general/attributes.md#source) is the default for forward resolution.
- `source.ip` is the default for reverse resolution.
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

*_address in semconv can be IP or hostname. Ideally, an attribute dedicated solely to the IP address would be great. I am not sure "network.peer" is the right description to store the resolved IP.

If you think network.peer is better than creating a new attribute, I can change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense for HTTP, but in the DNS context, the peer part would make it confusing IMO, as it's not the DNS server's peer address we're referring to on this config.

@kaisecheng
Copy link
Contributor Author

@edmocosta I have discussed with Andrzej that this is the minimum testable processor and he agreed to move on base on the current functionality. A noop resolver is added to temporarily replace the default resolver. This is ready for your review.


// LookupConfig defines the configuration for forward/reverse DNS resolution.
type LookupConfig struct {
Enabled bool `mapstructure:"enabled"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to support this Enabled config? If the lookup is configured, it's enabled, otherwise users could just remove/comment it on their configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My concern is the default value for Resolve and Reverse. Typically, a processor has default values and semconv attributes to simplify user configuration.

lookup source_attributes target_attribute
Resolve "source.address" "source.ip"
Reverse "source.ip" "source.address"

Without enabled, two lookups overwrite each other's result. Therefore I set enabled: false to Reverse.
For consistency, I avoid to set empty default for Reverse, while Reverse has values.

If no default values for Resolve and Reverse, I think enabled can be removed, but I am not sure it is the right way to go. Having enabled flag is handy to quickly turn on/off some features.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I agree, but considering those are different operations, and that we don't actually know which one the user wants, I wouldn't enabled any lookup by default, and I would enforce them to be explicit set on the config.
Regarding the defaults, we could probably reach similar results by using the source_attributes and target_attribute default values at code level, making them optional config keys.

I personally find something like:

  dnslookup:
    reverse:

Easier to read/understand than:

  dnslookup:
    resolve:
      enabled: false
    reverse:
      enabled: true

Also, the following would still do resolve lookups, which IMO, is somehow hidden at config level (but not at the docs):

  dnslookup:
    reverse:
      enabled: true

Anyway, just my 2 cents :)

func (g *dnsLookupProcessor) processTraces(_ context.Context, ts ptrace.Traces) (ptrace.Traces, error) {
return ts, nil
func newDNSLookupProcessor(config *Config, logger *zap.Logger) (*dnsLookupProcessor, error) {
dnsResolver, err := createResolverChain(config, logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to create the resolvers/chain instances per signal type? If the same configuration applies to all signals, and they're stateless, we probably could create it once and re-use the same chain, avoiding for example reading all hostfiles 3 times, and also allowing it (in the future) to leverage/share the same cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point. It make sense to share the cache for signals per component.ID. I think we can implement it later to keep this PR slim enough for review. I will add a todo

@kaisecheng
Copy link
Contributor Author

@edmocosta I have removed enabled from config and addressed all the comments. It is ready for a second look.

@edmocosta
Copy link
Contributor

Hi @kaisecheng, could you please resolve the conflicts, so it can run the CI? thanks!

@kaisecheng kaisecheng force-pushed the dnslookup_basic_op branch from 88e86a8 to 709bf73 Compare July 1, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants