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();