diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/CHANGELOG.md b/sdk/monitor/opentelemetry-exporter-azure-monitor/CHANGELOG.md index a6a89d242e3f..5e4ef205587e 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/CHANGELOG.md +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.0.0-beta.1 (Unreleased) +- OT Exporter retry when there are network issues +- OpenTelemetry Exporter using Resources API to get service properties - Rename package to `@azure/opentelemetry-exporter-azure-monitor` - [BREAKING] Deprecate all configuration options except for `connectionString` - [BREAKING] Removed support for `TelemetryProcessor` diff --git a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts index 270b37d6022c..64c64e049e3f 100644 --- a/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts +++ b/sdk/monitor/opentelemetry-exporter-azure-monitor/src/export/trace.ts @@ -4,6 +4,7 @@ import { Logger } from "@opentelemetry/api"; import { ConsoleLogger, LogLevel, ExportResult } from "@opentelemetry/core"; import { ReadableSpan, SpanExporter } from "@opentelemetry/tracing"; +import { RestError } from "@azure/core-http"; import { ConnectionStringParser } from "../utils/connectionStringParser"; import { HttpSender, FileSystemPersist } from "../platform"; import { @@ -105,12 +106,20 @@ export class AzureMonitorTraceExporter implements SpanExporter { return ExportResult.FAILED_NOT_RETRYABLE; } } catch (senderErr) { - // Request failed -- always retry - this._logger.error( - "Envelopes could not be exported and are not retriable. Error message:", - senderErr.message - ); - return ExportResult.FAILED_NOT_RETRYABLE; + if (this._isNetworkError(senderErr)) { + this._logger.error( + "Retrying due to transient client side error. Error message:", + senderErr.message + ); + return ExportResult.FAILED_RETRYABLE; + } + else { + this._logger.error( + "Envelopes could not be exported and are not retriable. Error message:", + senderErr.message + ); + return ExportResult.FAILED_NOT_RETRYABLE; + } } } @@ -140,4 +149,21 @@ export class AzureMonitorTraceExporter implements SpanExporter { this._logger.warn(`Failed to fetch persisted file`, err); } } + + private _isNetworkError(error: Error): boolean { + if (error instanceof RestError) { + if ( + error && + error.code && + (error.code === "ETIMEDOUT" || + error.code === "ESOCKETTIMEDOUT" || + error.code === "ECONNREFUSED" || + error.code === "ECONNRESET" || + error.code === "ENOENT") + ) { + return true; + } + } + return false; + } }