From 1630fb3abbea6ea7721257e5157afe03686ecaff Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Mon, 30 Nov 2020 13:19:10 -0800 Subject: [PATCH] Catch general exception in OltpExporter (#1634) * Catch general exception in OltpExporter * Corrected typo --- .../OpenTelemetryProtocolExporterEventSource.cs | 15 +++++++++++++++ .../OtlpExporter.cs | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs index c10fb32586c..7a07b62a0ea 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs @@ -43,6 +43,15 @@ public void FailedToReachCollector(Exception ex) } } + [NonEvent] + public void ExportMethodException(Exception ex) + { + if (Log.IsEnabled(EventLevel.Error, (EventKeywords)(-1))) + { + this.ExportMethodException(ex.ToInvariantString()); + } + } + [Event(1, Message = "Exporter failed to convert SpanData content into gRPC proto definition. Data will not be sent. Exception: {0}", Level = EventLevel.Error)] public void FailedToConvertToProtoDefinitionError(string ex) { @@ -60,5 +69,11 @@ public void CouldNotTranslateActivity(string className, string methodName) { this.WriteEvent(3, className, methodName); } + + [Event(4, Message = "Unknown error in export method: {0}", Level = EventLevel.Error)] + public void ExportMethodException(string ex) + { + this.WriteEvent(4, ex); + } } } diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index 23db24446f0..94550b773cc 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -85,6 +85,12 @@ public override ExportResult Export(in Batch activityBatch) return ExportResult.Failure; } + catch (Exception ex) + { + OpenTelemetryProtocolExporterEventSource.Log.ExportMethodException(ex); + + return ExportResult.Failure; + } finally { request.Return();