{"record":{"id":"a47423b6bbe5919f","repo":"fluent/fluentd","slug":"the-key-specified-by-hostname-key-in-inject-ca","errorCode":null,"errorMessage":"the key specified by 'hostname_key' in <inject> cannot be used in buffering chunk key.","messagePattern":"the key specified by 'hostname_key' in <inject> cannot be used in buffering chunk key\\.","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin_helper/inject.rb","lineNumber":116,"sourceCode":"        @_inject_tag_key = nil\n        @_inject_time_key = nil\n        @_inject_time_formatter = nil\n      end\n\n      def configure(conf)\n        super\n\n        if @inject_config\n          @_inject_hostname_key = @inject_config.hostname_key\n          if @_inject_hostname_key\n            if self.respond_to?(:buffer_config)\n              # Output plugin cannot use \"hostname\"(specified by @hostname_key),\n              # injected by this plugin helper, in chunk keys.\n              # This plugin helper works in `#format` (in many cases), but modified record\n              # don't have any side effect in chunking of output plugin.\n              if self.buffer_config.chunk_keys.include?(@_inject_hostname_key)\n                log.error \"Use filters to inject hostname to use it in buffer chunking.\"\n                raise Fluent::ConfigError, \"the key specified by 'hostname_key' in <inject> cannot be used in buffering chunk key.\"\n              end\n            end\n\n            @_inject_hostname =  @inject_config.hostname\n            unless @_inject_hostname\n              @_inject_hostname = ::Socket.gethostname\n              log.info \"using hostname for specified field\", host_key: @_inject_hostname_key, host_name: @_inject_hostname\n            end\n          end\n          @_inject_worker_id_key = @inject_config.worker_id_key\n          if @_inject_worker_id_key\n            @_inject_worker_id = fluentd_worker_id # get id here, because #with_worker_config method may be used only for #configure in tests\n          end\n          @_inject_tag_key = @inject_config.tag_key\n          @_inject_time_key = @inject_config.time_key\n          if @_inject_time_key\n            @_inject_time_formatter = case @inject_config.time_type\n                                      when :float then ->(time){ time.to_r.truncate(+6).to_f } # microsecond floating point value","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin_helper/inject.rb#L98-L134","documentation":"Fluent::ConfigError from the Inject helper's configure. When hostname_key is set in <inject>, the helper writes the hostname into each record during format processing, which happens after the output plugin has already assigned records to buffer chunks. Chunking on a key that is injected only after chunk assignment would silently misroute records, so configure rejects any buffer chunk key equal to the inject hostname_key. A companion log line ('Use filters to inject hostname to use it in buffer chunking.') states the intended alternative.","triggerScenarios":"An output plugin that mixes Inject and Buffer helpers, configured with e.g. <inject>hostname_key host</inject> together with <buffer>keys host</buffer> or <buffer host>. The check buffer_config.chunk_keys.include?(@_inject_hostname_key) fires during configure.","commonSituations":"Trying to partition output files or tags by the forwarding node's hostname using inject hostname_key plus a chunk key; migrating a record_modifier-based hostname injection into <inject> while leaving host in the buffer keys.","solutions":["Move hostname injection upstream: use a filter (record_modifier with ${hostname}) before the output, then keep host as a chunk key - injection then happens before chunking, which is what the built-in log error recommends","Alternatively remove the hostname from the buffer chunk keys and let <inject> hostname_key only enrich the emitted records"],"exampleFix":"# before\n<match app.**>\n  @type file\n  <inject>\n    hostname_key host\n  </inject>\n  <buffer>\n    keys host\n  </buffer>\n</match>\n\n# after\n<filter app.**>\n  @type record_modifier\n  <record>\n    host ${hostname}\n  </record>\n</filter>\n<match app.**>\n  @type file\n  <buffer>\n    keys host\n  </buffer>\n</match>","handlingStrategy":"validation","validationCode":"# reject the conflict before Fluent's configure does\nif inject_config&.hostname_key &&\n   respond_to?(:buffer_config) &&\n   buffer_config.chunk_keys.include?(inject_config.hostname_key)\n  raise Fluent::ConfigError, 'remove hostname_key from chunk keys or inject via a filter'\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never list an inject-provided key among buffer chunk keys","When chunking on hostname, inject it with a record_modifier filter upstream","Add a config lint rule: chunk keys must be produced before the output plugin"],"tags":["fluentd","inject","buffer","configuration","hostname"],"backgroundTag":"config-conflict","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}