Skip to content

Commit 47ffa64

Browse files
Copilottrask
authored andcommitted
Fix Java warnings by suppressing deprecation warnings for backward compatibility
1 parent 3f5a008 commit 47ffa64

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class ConfigurationBuilder {
104104
private static final String APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLEDIAGNOSTICS =
105105
"APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLEDIAGNOSTICS";
106106

107-
@Deprecated
107+
// supported for backwards compatibility
108108
private static final String APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS =
109109
"APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS";
110110

@@ -141,6 +141,8 @@ public static Configuration create(
141141
return config;
142142
}
143143

144+
@SuppressWarnings(
145+
"deprecation") // logging warnings for usages of deprecated configuration options
144146
private static void logConfigurationWarnings(Configuration config) {
145147
if (config.instrumentation.micrometer.reportingIntervalSeconds != 60) {
146148
configurationLogger.warn(
@@ -354,6 +356,8 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) {
354356
}
355357
}
356358

359+
@SuppressWarnings(
360+
"deprecation") // support deprecated semconv attributes for backwards compatibility
357361
private static String mapAttributeKey(String oldAttributeKey) {
358362
String result = null;
359363
// Common attributes across HTTP client and server spans
@@ -479,6 +483,8 @@ private static boolean isOpenJ9Jvm() {
479483
return jvmName != null && jvmName.contains("OpenJ9");
480484
}
481485

486+
@SuppressWarnings(
487+
"deprecation") // support deprecated configuration options for backwards compatibility
482488
private static void overlayAadEnvVars(
483489
Configuration config, Function<String, String> envVarsFunction) {
484490
String aadAuthString = getEnvVar(APPLICATIONINSIGHTS_AUTHENTICATION_STRING, envVarsFunction);

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/httpclient/LazyHttpClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public Mono<HttpResponse> send(HttpRequest request, Context context) {
150150
return getDelegate().send(request, context);
151151
}
152152

153+
@SuppressWarnings(
154+
"deprecation") // support deprecated configuration options for backwards compatibility
153155
private static HttpPipelinePolicy getAuthenticationPolicy(
154156
Configuration.AadAuthentication configuration, String aadAudienceWithScope) {
155157
switch (configuration.type) {
@@ -174,6 +176,7 @@ private static HttpPipelinePolicy getAuthenticationPolicyWithUami(
174176
managedIdentityCredential.build(), aadAudienceWithScope);
175177
}
176178

179+
@Deprecated
177180
private static HttpPipelinePolicy getAuthenticationPolicyWithClientSecret(
178181
Configuration.AadAuthentication configuration, String aadAudienceWithScope) {
179182
ClientSecretCredentialBuilder credential =

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AiContextCustomizer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public AiContextCustomizer(
3434
}
3535

3636
@Override
37+
@SuppressWarnings(
38+
"deprecation") // support deprecated semconv attributes for backwards compatibility
3739
public Context onStart(Context context, R request, Attributes startAttributes) {
3840

3941
// TODO (trask) ideally would also check parentSpanContext !isValid || isRemote

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/service/ServiceProfilerClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package com.microsoft.applicationinsights.agent.internal.profiler.service;
55

66
import com.azure.core.exception.HttpResponseException;
7+
import com.azure.core.http.HttpHeaderName;
78
import com.azure.core.http.HttpMethod;
89
import com.azure.core.http.HttpPipeline;
910
import com.azure.core.http.HttpRequest;
@@ -69,7 +70,7 @@ private static BlobAccessPass getUploadAccess(HttpResponse response) {
6970
if (response.getStatusCode() >= 300) {
7071
throw new HttpResponseException(response);
7172
}
72-
String location = response.getHeaderValue("Location");
73+
String location = response.getHeaderValue(HttpHeaderName.LOCATION);
7374
if (location == null || location.isEmpty()) {
7475
throw new AssertionError("response did not have a location");
7576
}
@@ -86,7 +87,7 @@ public Mono<HttpResponse> executePostWithRedirect(URL requestUrl) {
8687

8788
HttpRequest request = new HttpRequest(HttpMethod.POST, requestUrl);
8889
if (userAgent != null) {
89-
request.setHeader("User-Agent", userAgent);
90+
request.setHeader(HttpHeaderName.USER_AGENT, userAgent);
9091
}
9192
return httpPipeline.send(request);
9293
}

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplingOverrides.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private StrictMatcher(String key, String value) {
122122
}
123123

124124
@Override
125+
@SuppressWarnings(
126+
"deprecation") // support deprecated semconv attributes for backwards compatibility
125127
public boolean test(
126128
Attributes attributes, LazyHttpUrl lazyHttpUrl, LazyHttpTarget lazyHttpTarget) {
127129
String val = MatcherGroup.getValueIncludingThreadName(attributes, key);
@@ -213,6 +215,8 @@ private KeyOnlyMatcher(String key) {
213215
}
214216

215217
@Override
218+
@SuppressWarnings(
219+
"deprecation") // support deprecated semconv attributes for backwards compatibility
216220
public boolean test(
217221
Attributes attributes,
218222
@Nullable LazyHttpUrl lazyHttpUrl,
@@ -247,6 +251,8 @@ private String get() {
247251
}
248252
}
249253

254+
@SuppressWarnings(
255+
"deprecation") // support deprecated semconv attributes for backwards compatibility
250256
private static boolean getHttpUrlKeyOldOrStableSemconv(AttributeKey<String> key) {
251257
String keyString = key.getKey();
252258
return keyString.equals(HttpIncubatingAttributes.HTTP_URL.getKey())

0 commit comments

Comments
 (0)