Number must be positive. (Parameter 'batchSize')

Note for other people running into the error:

Number must be positive. (Parameter 'batchSize')

when executing AgentComponents agentComponents = new AgentComponents(elasticApmLogger, elasticApmConfig, null);

Solution

The reason is that MaxBatchEventCount in the IConfigurationReader implementation is 0. The documentation on the interface states:

The maximal number of events to send in a batch.
It's possible for a batch contain less then the maximum events
if there are events that need to be sent out because they were held for too long.

  • Positive number - The maximal number of of events to send in a batch.
  • 0 and negative - Invalid and the default value is used instead.

However, a value of zero will raise the error Number must be positive.

Using a negative value also raises Number must be positive.

Replace the value of the configuration option by a positive value like the default value 10 (see ConfigConsts.cs in the class DefaultValues).