Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing and log correlation without otel #43718

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sdk/clientcore/core/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
<suppress files="io.clientcore.core.implementation.util.InternalContext.java" checks="JavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.RequestDataConfiguration.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.SwaggerMethodParser.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.util.DefaultLogger.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.instrumentation.DefaultLogger.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.util.ImplUtils.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.util.IterableOfByteBuffersInputStream.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.util.ServerSentEventHelper.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.util.Slf4jLoggerShim.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.instrumentation.Slf4jLoggerShim.java" checks="MissingJavadocMethodCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.HeaderSubstitution.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.RequestDataConfiguration.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.RestProxyImpl.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.util.EnvironmentConfiguration.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.util.ImplUtils.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.util.Slf4jLoggerShim.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.instrumentation.Slf4jLoggerShim.java" checks="MissingJavadocTypeCheck" />
<suppress files="io.clientcore.core.implementation.util.EnvironmentConfiguration.java" checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" />
<suppress files="io.clientcore.core.implementation.util.Slf4jLoggerShim.java" checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" />
<suppress files="io.clientcore.core.implementation.http.rest.SwaggerMethodParser.java" checks="com.azure.tools.checkstyle.checks.GoodLoggingCheck" />
<suppress files="io.clientcore.core.implementation.instrumentation.Slf4jLoggerShim.java" checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" />
<suppress files="io.clientcore.core.implementation.ReflectionSerializable.java" checks="com.azure.tools.checkstyle.checks.JavadocThrowsChecks" />
<suppress files="io.clientcore.core.implementation.http.serializer.HttpResponseBodyDecoder.java" checks="com.azure.tools.checkstyle.checks.JavadocThrowsChecks" />
<suppress files="io.clientcore.core.http.client.DefaultHttpClientBuilder.java" checks="com.azure.tools.checkstyle.checks.ServiceClientBuilderCheck" />
Expand Down
1 change: 1 addition & 0 deletions sdk/clientcore/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

--add-exports io.clientcore.core/io.clientcore.core.shared=ALL-UNNAMED
--add-exports io.clientcore.core/io.clientcore.core.implementation=ALL-UNNAMED
--add-exports io.clientcore.core/io.clientcore.core.implementation.instrumentation.fallback=ALL-UNNAMED
</javaModulesSurefireArgLine>

<!-- If JMH benchmarking was ran Checkstyle may fail on jmh_benchmark generated classes, ignore them. -->
Expand Down
27 changes: 21 additions & 6 deletions sdk/clientcore/core/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
<Class name="io.clientcore.core.implementation.http.rest.SwaggerMethodParser" />
<Class name="io.clientcore.core.implementation.instrumentation.otel.OTelInstrumentation" />
<Class name="io.clientcore.core.serialization.json.implementation.jackson.core.util.RequestPayload" />
<Class name="io.clientcore.core.util.ClientLogger" />
<Class name="io.clientcore.core.instrumentation.logging.ClientLogger" />
<Class name="io.clientcore.core.implementation.instrumentation.otel.OTelInstrumentation" />
</Or>
</Match>
<Match>
Expand Down Expand Up @@ -121,8 +122,8 @@
<Class name="io.clientcore.core.serialization.xml.XmlReader" />
<Class name="io.clientcore.core.shared.HttpClientTests" />
<Class name="io.clientcore.core.shared.HttpClientTestsServer" />
<Class name="io.clientcore.core.util.ClientLoggerTests" />
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
<Class name="io.clientcore.core.instrumentation.logging.ClientLoggerTests" />
<Class name="io.clientcore.core.instrumentation.logging.InstrumentationTestUtils" />
<Class name="io.clientcore.core.util.binarydata.BinaryDataTest" />
<Class name="io.clientcore.core.util.serializer.JsonSerializerTests" />
</Or>
Expand Down Expand Up @@ -165,9 +166,9 @@
<Match>
<Bug pattern="INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE" />
<Or>
<Class name="io.clientcore.core.implementation.util.DefaultLogger" />
<Class name="io.clientcore.core.implementation.instrumentation.DefaultLogger" />
<Class name="io.clientcore.core.serialization.xml.implementation.aalto.UncheckedStreamException" />
<Class name="io.clientcore.core.util.ClientLoggerTests" />
<Class name="io.clientcore.core.instrumentation.logging.ClientLoggerTests" />
</Or>
</Match>
<Match>
Expand Down Expand Up @@ -237,13 +238,14 @@
<Class name="io.clientcore.core.implementation.http.rest.LengthValidatingInputStreamTests" />
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
<Class name="io.clientcore.core.util.binarydata.BinaryDataTest" />
<Class name="io.clientcore.core.implementation.instrumentation.fallback.FallbackInstrumentationTests" />
</Or>
</Match>
<Match>
<Bug pattern="OS_OPEN_STREAM" />
<Or>
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
<Class name="io.clientcore.core.http.pipeline.HttpInstrumentationLoggingTests" />
</Or>
</Match>
<Match>
Expand All @@ -259,6 +261,7 @@
<Class name="io.clientcore.core.http.pipeline.HttpRetryPolicy" />
<Class name="io.clientcore.core.shared.HttpClientTests" />
<Class name="io.clientcore.core.shared.HttpClientTestsServer" />
<Class name="io.clientcore.core.implementation.instrumentation.fallback.RandomIdUtils" />
</Or>
</Match>
<Match>
Expand Down Expand Up @@ -399,4 +402,16 @@
<Bug pattern="XXE_XMLSTREAMREADER" />
<Class name="io.clientcore.core.serialization.xml.XmlReader" />
</Match>
<Match>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE" />
<Class name="io.clientcore.core.http.pipeline.HttpInstrumentationPolicy" />
</Match>
<Match>
<Bug pattern="NP_LOAD_OF_KNOWN_NULL_VALUE" />
<Class name="io.clientcore.core.http.pipeline.HttpInstrumentationPolicy" />
</Match>
<Match>
<Bug pattern="AA_ASSERTION_OF_ARGUMENTS" />
<Class name="io.clientcore.core.implementation.instrumentation.otel.tracing.OTelSpanContext" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package io.clientcore.core.credential;

import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.clientcore.core.http.models.Response;
import io.clientcore.core.http.models.ResponseBodyMode;
import io.clientcore.core.http.models.ServerSentEventListener;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.ServerSentEventUtils;
import io.clientcore.core.util.ServerSentResult;
import io.clientcore.core.util.binarydata.BinaryData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.clientcore.core.http.client.implementation.JdkHttpClientProxySelector;
import io.clientcore.core.http.models.ProxyOptions;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.SharedExecutorService;
import io.clientcore.core.util.configuration.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package io.clientcore.core.http.client.implementation;

import io.clientcore.core.http.models.HttpHeaders;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.util.AbstractMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package io.clientcore.core.http.client.implementation;

import io.clientcore.core.http.models.HttpMethod;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.net.URI;
import java.net.http.HttpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import io.clientcore.core.http.models.HttpHeaderName;
import io.clientcore.core.http.models.HttpHeaders;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.SharedExecutorService;
import io.clientcore.core.util.configuration.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package io.clientcore.core.http.models;

import io.clientcore.core.http.pipeline.HttpRequestRedirectCondition;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.util.EnumSet;
import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.clientcore.core.annotation.Metadata;
import io.clientcore.core.implementation.http.HttpRequestAccessHelper;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.binarydata.BinaryData;

import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package io.clientcore.core.http.models;

import io.clientcore.core.http.pipeline.HttpRequestRetryCondition;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.time.Duration;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package io.clientcore.core.http.models;

import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;

import java.util.Iterator;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package io.clientcore.core.http.models;

import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.auth.BasicChallengeHandler;
import io.clientcore.core.util.auth.ChallengeHandler;
import io.clientcore.core.util.auth.DigestChallengeHandler;
Expand All @@ -22,6 +22,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import static io.clientcore.core.implementation.instrumentation.AttributeKeys.URL_FULL_KEY;
import static io.clientcore.core.implementation.util.ImplUtils.isNullOrEmpty;

/**
Expand Down Expand Up @@ -342,7 +343,7 @@ private static ProxyOptions attemptToLoadSystemProxy(Configuration configuration

return proxyOptions;
} catch (URISyntaxException ex) {
LOGGER.atWarning().addKeyValue("uri", proxyProperty).log(INVALID_PROXY_URI, ex);
LOGGER.atWarning().addKeyValue(URL_FULL_KEY, proxyProperty).log(INVALID_PROXY_URI, ex);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import io.clientcore.core.http.annotation.QueryParam;
import io.clientcore.core.http.client.HttpClient;
import io.clientcore.core.implementation.http.rest.UriEscapers;
import io.clientcore.core.util.ClientLogger;
import io.clientcore.core.instrumentation.InstrumentationContext;
import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.util.Context;
import io.clientcore.core.util.binarydata.BinaryData;

Expand Down Expand Up @@ -119,6 +120,7 @@ public final class RequestOptions {
private ResponseBodyMode responseBodyMode;
private boolean locked;
private ClientLogger logger;
private InstrumentationContext instrumentationContext;

/**
* Creates a new instance of {@link RequestOptions}.
Expand Down Expand Up @@ -408,4 +410,33 @@ private RequestOptions lock() {
public static RequestOptions none() {
return NONE;
}

/**
* Gets the {@link InstrumentationContext} used to instrument the request.
*
* @return The {@link InstrumentationContext} used to instrument the request.
*/
public InstrumentationContext getInstrumentationContext() {
return instrumentationContext;
}

/**
* Sets the {@link InstrumentationContext} used to instrument the request.
*
* @param instrumentationContext The {@link InstrumentationContext} used to instrument the request.
*
* @return The updated {@link RequestOptions} object.
*
* @throws IllegalStateException if this instance is obtained by calling {@link RequestOptions#none()}.
*/
public RequestOptions setInstrumentationContext(InstrumentationContext instrumentationContext) {
if (locked) {
throw LOGGER.logThrowableAsError(new IllegalStateException(
"This instance of RequestOptions is immutable. Cannot set instrumentation context."));
}

this.instrumentationContext = instrumentationContext;

return this;
}
}
Loading
Loading