Skip to content

Commit 570a6fa

Browse files
[OTLP] Dispose exporter if setup fails (#6398)
Co-authored-by: Rajkumar Rangaraj <[email protected]>
1 parent 4dc6000 commit 570a6fa

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -327,25 +327,33 @@ internal static BaseProcessor<LogRecord> BuildOtlpLogExporter(
327327
experimentalOptions!);
328328
#pragma warning restore CA2000 // Dispose objects before losing scope
329329

330-
if (configureExporterInstance != null)
330+
try
331331
{
332-
otlpExporter = configureExporterInstance(otlpExporter);
333-
}
332+
if (configureExporterInstance != null)
333+
{
334+
otlpExporter = configureExporterInstance(otlpExporter);
335+
}
334336

335-
if (processorOptions!.ExportProcessorType == ExportProcessorType.Simple)
336-
{
337-
return new SimpleLogRecordExportProcessor(otlpExporter);
337+
if (processorOptions!.ExportProcessorType == ExportProcessorType.Simple)
338+
{
339+
return new SimpleLogRecordExportProcessor(otlpExporter);
340+
}
341+
else
342+
{
343+
var batchOptions = processorOptions.BatchExportProcessorOptions;
344+
345+
return new BatchLogRecordExportProcessor(
346+
otlpExporter,
347+
batchOptions.MaxQueueSize,
348+
batchOptions.ScheduledDelayMilliseconds,
349+
batchOptions.ExporterTimeoutMilliseconds,
350+
batchOptions.MaxExportBatchSize);
351+
}
338352
}
339-
else
353+
catch
340354
{
341-
var batchOptions = processorOptions.BatchExportProcessorOptions;
342-
343-
return new BatchLogRecordExportProcessor(
344-
otlpExporter,
345-
batchOptions.MaxQueueSize,
346-
batchOptions.ScheduledDelayMilliseconds,
347-
batchOptions.ExporterTimeoutMilliseconds,
348-
batchOptions.MaxExportBatchSize);
355+
otlpExporter.Dispose();
356+
throw;
349357
}
350358
}
351359

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,31 @@ internal static BaseProcessor<Activity> BuildOtlpExporterProcessor(
151151
BaseExporter<Activity> otlpExporter = new OtlpTraceExporter(exporterOptions!, sdkLimitOptions!, experimentalOptions!);
152152
#pragma warning restore CA2000 // Dispose objects before losing scope
153153

154-
if (configureExporterInstance != null)
154+
try
155155
{
156-
otlpExporter = configureExporterInstance(otlpExporter);
157-
}
156+
if (configureExporterInstance != null)
157+
{
158+
otlpExporter = configureExporterInstance(otlpExporter);
159+
}
158160

159-
if (exportProcessorType == ExportProcessorType.Simple)
160-
{
161-
return new SimpleActivityExportProcessor(otlpExporter);
161+
if (exportProcessorType == ExportProcessorType.Simple)
162+
{
163+
return new SimpleActivityExportProcessor(otlpExporter);
164+
}
165+
else
166+
{
167+
return new BatchActivityExportProcessor(
168+
otlpExporter,
169+
batchExportProcessorOptions!.MaxQueueSize,
170+
batchExportProcessorOptions.ScheduledDelayMilliseconds,
171+
batchExportProcessorOptions.ExporterTimeoutMilliseconds,
172+
batchExportProcessorOptions.MaxExportBatchSize);
173+
}
162174
}
163-
else
175+
catch
164176
{
165-
return new BatchActivityExportProcessor(
166-
otlpExporter,
167-
batchExportProcessorOptions!.MaxQueueSize,
168-
batchExportProcessorOptions.ScheduledDelayMilliseconds,
169-
batchExportProcessorOptions.ExporterTimeoutMilliseconds,
170-
batchExportProcessorOptions.MaxExportBatchSize);
177+
otlpExporter.Dispose();
178+
throw;
171179
}
172180
}
173181
}

0 commit comments

Comments
 (0)