Search code examples
puppet

Puppet report processor sends the same @host to Sentry for all reports


I want to send all err logs from all my puppet nodes to Sentry - the logs are successfully sent to the master via the report = true option.

Versions used:

  • puppet: 7.10.0
  • sentry-ruby: 5.3.0

Looking on my master server, I can see the reports under the /opt/puppetlabs/server/data/puppetserver/reports/host_fqdn directory and a quick inspect into a random .yaml file confirms that the host is set correctly:

--- !ruby/object:Puppet::Transaction::Report
host: host_1_fqdn
time: X
configuration_version: Y
transaction_uuid: Z
report_format: 12
logs: ...

As far as I understood, you can define a custom reports processor and you can access the deserialized yaml reports from the Puppet::Transaction::Report object inside the process method, by using self. Hence, I would expect to get the same host name in my processor, as it is in the reports file by doing the following:

if self.respond_to?(:host)
    @host = self.host
end

Now, for the previous report I gave as an example, I expect the @host variable to store the host_1_fqdn value. With this in mind, I continue with sending some data from the report to Sentry via:

self.logs.each do |log|
  if log.level.to_s == 'err'
    Sentry.capture_message(log.message +  ":", {
      :tags => {
        'server_name' => @host
      },
    })
  end
end

Looking into Sentry, I see that all my events are received, but all of them have the server_name tag with the same value, i.e. the hostname of the puppet master, instead of having host_X_fqdn.

Tried to look into lots of places into the upstream puppet repo, but didn't find any hints of what could be wrong with my processor. To me it seems clearly that this is not Sentry-related at all, but I tried to provide the whole context, maybe my intuition is wrong.


Solution

  • Tried first to update my reports processor as John suggested, but it didn't work. Looking closer into the Sentry Ruby documentation, I found out that it is not recommended to override the default tags.

    Some tags are automatically set by Sentry. We strongly recommend against overwriting those tags. Instead, name your tags with your organization's nomenclature.

    Hence, I firstly updated my sentry-ruby gem to 5.5.0 via puppetserver gem and then removed the server_name tag from the code. Instead, I've defined a new one, named client_name, with exactly the same value, i.e. self.host, within the global scope.

    Sentry.set_tags(
      'client_name': self.host,
      ...other tags
    )
    

    Now all of my events have both tags, server_name (which defaults to the puppet server name) and the client_name (which evaluates to the name of the affected puppet node).