Skip to content

Commit

Permalink
OT Exporter retry when there are network issues (#12905)
Browse files Browse the repository at this point in the history
* OT Exporter retry when there are network issues

* Adding network error check

* Fixing issue with tests

* reverting unnecessary change
  • Loading branch information
hectorhdzg authored Jan 7, 2021
1 parent eba91b5 commit abbfad2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions sdk/monitor/opentelemetry-exporter-azure-monitor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit abbfad2

Please sign in to comment.