[OTLP] Dispose exporter if setup fails (#6398)

Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
This commit is contained in:
Martin Costello 2025-07-30 14:40:11 +01:00 committed by GitHub
parent 4dc60007ca
commit 570a6fa687
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 29 deletions

View File

@ -327,6 +327,8 @@ public static class OtlpLogExporterHelperExtensions
experimentalOptions!);
#pragma warning restore CA2000 // Dispose objects before losing scope
try
{
if (configureExporterInstance != null)
{
otlpExporter = configureExporterInstance(otlpExporter);
@ -348,6 +350,12 @@ public static class OtlpLogExporterHelperExtensions
batchOptions.MaxExportBatchSize);
}
}
catch
{
otlpExporter.Dispose();
throw;
}
}
private static T GetOptions<T>(
IServiceProvider sp,

View File

@ -151,6 +151,8 @@ public static class OtlpTraceExporterHelperExtensions
BaseExporter<Activity> otlpExporter = new OtlpTraceExporter(exporterOptions!, sdkLimitOptions!, experimentalOptions!);
#pragma warning restore CA2000 // Dispose objects before losing scope
try
{
if (configureExporterInstance != null)
{
otlpExporter = configureExporterInstance(otlpExporter);
@ -170,4 +172,10 @@ public static class OtlpTraceExporterHelperExtensions
batchExportProcessorOptions.MaxExportBatchSize);
}
}
catch
{
otlpExporter.Dispose();
throw;
}
}
}