-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return status code exceptions via CompletableResultCode in GrpcExport…
…er and HttpExporter (#6645)
- Loading branch information
1 parent
7522bfe
commit 71124d2
Showing
7 changed files
with
284 additions
and
48 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
exporters/common/src/main/java/io/opentelemetry/exporter/internal/FailedExportException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal; | ||
|
||
import io.opentelemetry.exporter.internal.grpc.GrpcResponse; | ||
import io.opentelemetry.exporter.internal.http.HttpSender; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents the failure of a gRPC or HTTP exporter. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public abstract class FailedExportException extends Exception { | ||
|
||
private static final long serialVersionUID = 6988924855140178789L; | ||
|
||
private FailedExportException(@Nullable Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
/** Indicates an HTTP export failed after receiving a response from the server. */ | ||
public static HttpExportException httpFailedWithResponse(HttpSender.Response response) { | ||
return new HttpExportException(response, null); | ||
} | ||
|
||
/** Indicates an HTTP export failed exceptionally without receiving a response from the server. */ | ||
public static HttpExportException httpFailedExceptionally(Throwable cause) { | ||
return new HttpExportException(null, cause); | ||
} | ||
|
||
/** Indicates a gRPC export failed after receiving a response from the server. */ | ||
public static GrpcExportException grpcFailedWithResponse(GrpcResponse response) { | ||
return new GrpcExportException(response, null); | ||
} | ||
|
||
/** Indicates a gRPC export failed exceptionally without receiving a response from the server. */ | ||
public static GrpcExportException grpcFailedExceptionally(Throwable cause) { | ||
return new GrpcExportException(null, cause); | ||
} | ||
|
||
/** Returns true if the export failed with a response from the server. */ | ||
public abstract boolean failedWithResponse(); | ||
|
||
/** Represents the failure of an HTTP exporter. */ | ||
public static final class HttpExportException extends FailedExportException { | ||
|
||
private static final long serialVersionUID = -6787390183017184775L; | ||
|
||
@Nullable private final HttpSender.Response response; | ||
@Nullable private final Throwable cause; | ||
|
||
private HttpExportException(@Nullable HttpSender.Response response, @Nullable Throwable cause) { | ||
super(cause); | ||
this.response = response; | ||
this.cause = cause; | ||
} | ||
|
||
@Override | ||
public boolean failedWithResponse() { | ||
return response != null; | ||
} | ||
|
||
/** | ||
* Returns the response if the export failed with a response from the server, or null if the | ||
* export failed exceptionally with no response. | ||
*/ | ||
@Nullable | ||
public HttpSender.Response getResponse() { | ||
return response; | ||
} | ||
|
||
/** | ||
* Returns the exceptional cause of failure, or null if the export failed with a response from | ||
* the server. | ||
*/ | ||
@Nullable | ||
@Override | ||
public Throwable getCause() { | ||
return cause; | ||
} | ||
} | ||
|
||
/** Represents the failure of a gRPC exporter. */ | ||
public static final class GrpcExportException extends FailedExportException { | ||
|
||
private static final long serialVersionUID = -9157548250286695364L; | ||
|
||
@Nullable private final GrpcResponse response; | ||
@Nullable private final Throwable cause; | ||
|
||
private GrpcExportException(@Nullable GrpcResponse response, @Nullable Throwable cause) { | ||
super(cause); | ||
this.response = response; | ||
this.cause = cause; | ||
} | ||
|
||
@Override | ||
public boolean failedWithResponse() { | ||
return response != null; | ||
} | ||
|
||
/** | ||
* Returns the response if the export failed with a response from the server, or null if the | ||
* export failed exceptionally with no response. | ||
*/ | ||
@Nullable | ||
public GrpcResponse getResponse() { | ||
return response; | ||
} | ||
|
||
/** | ||
* Returns the exceptional cause of failure, or null if the export failed with a response from | ||
* the server. | ||
*/ | ||
@Nullable | ||
@Override | ||
public Throwable getCause() { | ||
return cause; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.