Skip to content

Commit

Permalink
Merge pull request #1318 from microsoft/bugfix/content-length
Browse files Browse the repository at this point in the history
- fixes long responses parsing
  • Loading branch information
baywet authored May 22, 2024
2 parents f8a54d6 + 93c51f5 commit eed4179
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.12] - 2024-05-21

### Changed

- Fixed a bug where large responses would make the client fail. [microsoftgraph/msgraph-sdk-java#2009](https://github.com/microsoftgraph/msgraph-sdk-java/issues/2009)

## [1.1.11] - 2024-05-07

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@

/** RequestAdapter implementation for OkHttp */
public class OkHttpRequestAdapter implements com.microsoft.kiota.RequestAdapter {
private static final String contentTypeHeaderKey = "Content-Type";
private static final String contentLengthHeaderKey = "Content-Length";
private static final String CONTENT_LENGTH_HEADER_KEY = "Content-Length";
private static final String CONTENT_TYPE_HEADER_KEY = "Content-Type";
@Nonnull private final Call.Factory client;
@Nonnull private final AuthenticationProvider authProvider;
@Nonnull private final ObservabilityOptions obsOptions;
Expand Down Expand Up @@ -715,17 +715,18 @@ private Response getHttpResponseMessage(
getRequestFromRequestInformation(
requestInfo, span, spanForAttributes))
.execute();
final String contentLengthHeaderValue = getHeaderValue(response, "Content-Length");
final String contentLengthHeaderValue =
getHeaderValue(response, CONTENT_LENGTH_HEADER_KEY);
if (contentLengthHeaderValue != null && !contentLengthHeaderValue.isEmpty()) {
final int contentLengthHeaderValueAsInt =
Integer.parseInt(contentLengthHeaderValue);
final long contentLengthHeaderValueAsLong =
Long.parseLong(contentLengthHeaderValue);
spanForAttributes.setAttribute(
EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsInt);
EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsLong);
}
final String contentTypeHeaderValue = getHeaderValue(response, "Content-Length");
final String contentTypeHeaderValue = getHeaderValue(response, CONTENT_TYPE_HEADER_KEY);
if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) {
spanForAttributes.setAttribute(
"http.response_content_type", contentTypeHeaderValue);
CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue);
}
spanForAttributes.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code());
spanForAttributes.setAttribute(
Expand Down Expand Up @@ -886,14 +887,14 @@ private void setBaseUrlForRequestInformation(@Nonnull final RequestInformation r
public MediaType contentType() {
final Set<String> contentTypes =
requestInfo.headers.getOrDefault(
contentTypeHeaderKey, new HashSet<>());
CONTENT_TYPE_HEADER_KEY, new HashSet<>());
if (contentTypes.isEmpty()) {
return null;
} else {
final String contentType =
contentTypes.toArray(new String[] {})[0];
spanForAttributes.setAttribute(
"http.request_content_type", contentType);
CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType);
return MediaType.parse(contentType);
}
}
Expand All @@ -902,7 +903,7 @@ public MediaType contentType() {
public long contentLength() throws IOException {
final Set<String> contentLength =
requestInfo.headers.getOrDefault(
contentLengthHeaderKey, new HashSet<>());
CONTENT_LENGTH_HEADER_KEY, new HashSet<>());
if (!contentLength.isEmpty()) {
return Long.parseLong(
contentLength.toArray(new String[] {})[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@

import io.opentelemetry.api.common.AttributeKey;

public class TelemetrySemanticConventions {
public final class TelemetrySemanticConventions {
private TelemetrySemanticConventions() {}

// https://opentelemetry.io/docs/specs/semconv/attributes-registry/
public static final AttributeKey HTTP_RESPONSE_STATUS_CODE =
public static final AttributeKey<Long> HTTP_RESPONSE_STATUS_CODE =
longKey("http.response.status_code"); // stable
public static final AttributeKey HTTP_REQUEST_RESEND_COUNT =
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_COUNT =
longKey("http.request.resend_count"); // stable
public static final AttributeKey HTTP_REQUEST_METHOD =
public static final AttributeKey<String> HTTP_REQUEST_METHOD =
stringKey("http.request.method"); // stable
public static final AttributeKey NETWORK_PROTOCOL_VERSION =
public static final AttributeKey<String> NETWORK_PROTOCOL_VERSION =
stringKey("network.protocol.version"); // stable
public static final AttributeKey URL_FULL = stringKey("url.full"); // stable
public static final AttributeKey URL_SCHEME = stringKey("url.scheme"); // stable
public static final AttributeKey SERVER_ADDRESS = stringKey("server.address"); // stable
public static final AttributeKey SERVER_PORT = longKey("server.port"); // stable
public static final AttributeKey<String> URL_FULL = stringKey("url.full"); // stable
public static final AttributeKey<String> URL_SCHEME = stringKey("url.scheme"); // stable
public static final AttributeKey<String> SERVER_ADDRESS = stringKey("server.address"); // stable
public static final AttributeKey<Long> SERVER_PORT = longKey("server.port"); // stable

public static final AttributeKey EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE =
public static final AttributeKey<Long> EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE =
longKey("http.response.body.size"); // experimental
public static final AttributeKey EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE =
public static final AttributeKey<Long> EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE =
longKey("http.request.body.size"); // experimental

public static final AttributeKey<String> CUSTOM_HTTP_RESPONSE_CONTENT_TYPE =
stringKey("http.response_content_type"); // custom
public static final AttributeKey<String> CUSTOM_HTTP_REQUEST_CONTENT_TYPE =
stringKey("http.request_content_type"); // custom
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public UserAgentHandlerOption() {}

private boolean enabled = true;
@Nonnull private String productName = "kiota-java";
@Nonnull private String productVersion = "1.1.11";
@Nonnull private String productVersion = "1.1.12";

/**
* Gets the product name to be used in the user agent header
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ org.gradle.caching=true
mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 1
mavenMinorVersion = 1
mavenPatchVersion = 11
mavenPatchVersion = 12
mavenArtifactSuffix =

#These values are used to run functional tests
Expand Down

0 comments on commit eed4179

Please sign in to comment.