diff --git a/README.md b/README.md index ea84b7c..893b44f 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ This tool is able to override the following attributes: | Attribute | Flag | Default value | Description | | --------- | ---- | ------------- | ----------- | +| Max Batch Size | --batch-size | `10` | Maximum export batch size allowed when creating a BatchSpanProcessor. | | Repository Path | --repository-path | `.` | Path to the SCM repository to be read. | | Service Name | --service-name | `junit2otlp` | Overrides OpenTelemetry's service name. If the `OTEL_SERVICE_NAME` environment variable is set, it will take precedence over any other value. | | Service Version | --service-version | Empty | Overrides OpenTelemetry's service version. If the `OTEL_SERVICE_VERSION` environment variable is set, it will take precedence over any other value. | diff --git a/main.go b/main.go index 7fabbff..4b5159d 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,9 @@ import ( "go.opentelemetry.io/otel/trace" ) +const defaultMaxBatchSize = 10 + +var batchSizeFlag int var repositoryPathFlag string var serviceNameFlag string var serviceVersionFlag string @@ -31,6 +34,7 @@ var traceNameFlag string var runtimeAttributes []attribute.KeyValue func init() { + flag.IntVar(&batchSizeFlag, "batch-size", defaultMaxBatchSize, "Maximum export batch size allowed when creating a BatchSpanProcessor") flag.StringVar(&repositoryPathFlag, "repository-path", getDefaultwd(), "Path to the SCM repository to be read") flag.StringVar(&serviceNameFlag, "service-name", "", "OpenTelemetry Service Name to be used when sending traces and metrics for the jUnit report") flag.StringVar(&serviceVersionFlag, "service-version", "", "OpenTelemetry Service Version to be used when sending traces and metrics for the jUnit report") @@ -182,7 +186,12 @@ func initTracerProvider(ctx context.Context, res *resource.Resource) (*sdktrace. tracerProvider := sdktrace.NewTracerProvider( sdktrace.WithResource(res), - sdktrace.WithSpanProcessor(sdktrace.NewBatchSpanProcessor(traceExporter)), + sdktrace.WithSpanProcessor( + sdktrace.NewBatchSpanProcessor( + traceExporter, + sdktrace.WithMaxExportBatchSize(batchSizeFlag), + ), + ), ) otel.SetTracerProvider(tracerProvider) diff --git a/main_test.go b/main_test.go index 6451c74..c2f4ba7 100644 --- a/main_test.go +++ b/main_test.go @@ -125,9 +125,7 @@ func requireAttributeInArray(t *testing.T, attributes []TestAttribute, key strin return TestAttribute{} } -func Test_Main_SampleXML(t *testing.T) { - t.Setenv("BRANCH", "main") - +func setupRuntimeDependencies(t *testing.T) (context.Context, string, testcontainers.Container) { ctx := context.Background() // create file for otel to store the traces @@ -197,12 +195,22 @@ func Test_Main_SampleXML(t *testing.T) { t.Setenv("OTEL_EXPORTER_OTLP_HEADERS", "") t.Setenv("OTEL_SERVICE_NAME", "jaeger-srv-test") + return ctx, reportFilePath, otelCollector +} + +func Test_Main_SampleXML(t *testing.T) { + t.Setenv("BRANCH", "main") + batchSizeFlag = 25 + + ctx, reportFilePath, otelCollector := setupRuntimeDependencies(t) + defer func() { + batchSizeFlag = defaultMaxBatchSize // clean up test report os.Remove(reportFilePath) }() - err = Main(context.Background(), &TestReader{testFile: "TEST-sample.xml"}) + err := Main(context.Background(), &TestReader{testFile: "TEST-sample.xml"}) require.NoError(t, err) // wait for the file to be written by the otel-exporter