Skip to content

Commit 0778935

Browse files
Copilottrask
authored andcommitted
Fix Java warnings by suppressing deprecation warnings for backward compatibility
1 parent bda633d commit 0778935

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

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

Lines changed: 4 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,7 @@ public static Configuration create(
141141
return config;
142142
}
143143

144+
@SuppressWarnings("deprecation") // logging warnings for usages of deprecated configuration options
144145
private static void logConfigurationWarnings(Configuration config) {
145146
if (config.instrumentation.micrometer.reportingIntervalSeconds != 60) {
146147
configurationLogger.warn(
@@ -354,6 +355,7 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) {
354355
}
355356
}
356357

358+
@SuppressWarnings("deprecation") // support deprecated semconv attributes for backwards compatibility
357359
private static String mapAttributeKey(String oldAttributeKey) {
358360
String result = null;
359361
// Common attributes across HTTP client and server spans
@@ -479,6 +481,7 @@ private static boolean isOpenJ9Jvm() {
479481
return jvmName != null && jvmName.contains("OpenJ9");
480482
}
481483

484+
@SuppressWarnings("deprecation") // support deprecated configuration options for backwards compatibility
482485
private static void overlayAadEnvVars(
483486
Configuration config, Function<String, String> envVarsFunction) {
484487
String aadAuthString = getEnvVar(APPLICATIONINSIGHTS_AUTHENTICATION_STRING, envVarsFunction);

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

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

153+
@SuppressWarnings("deprecation") // support deprecated configuration options for backwards compatibility
153154
private static HttpPipelinePolicy getAuthenticationPolicy(
154155
Configuration.AadAuthentication configuration, String aadAudienceWithScope) {
155156
switch (configuration.type) {
@@ -174,6 +175,7 @@ private static HttpPipelinePolicy getAuthenticationPolicyWithUami(
174175
managedIdentityCredential.build(), aadAudienceWithScope);
175176
}
176177

178+
@Deprecated
177179
private static HttpPipelinePolicy getAuthenticationPolicyWithClientSecret(
178180
Configuration.AadAuthentication configuration, String aadAudienceWithScope) {
179181
ClientSecretCredentialBuilder credential =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public AiContextCustomizer(
3434
}
3535

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

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

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/processors/DelegatingLogData.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static java.util.Objects.requireNonNull;
77

88
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.common.Value;
910
import io.opentelemetry.api.logs.Severity;
1011
import io.opentelemetry.api.trace.SpanContext;
1112
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
@@ -59,10 +60,16 @@ public String getSeverityText() {
5960
}
6061

6162
@Override
63+
@SuppressWarnings("deprecation") // Implementation of deprecated method
6264
public Body getBody() {
6365
return delegate.getBody();
6466
}
6567

68+
@Override
69+
public Value<?> getBodyValue() {
70+
return delegate.getBodyValue();
71+
}
72+
6673
@Override
6774
public Attributes getAttributes() {
6875
return delegate.getAttributes();

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/processors/MyLogData.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44
package com.microsoft.applicationinsights.agent.internal.processors;
55

66
import io.opentelemetry.api.common.Attributes;
7+
import io.opentelemetry.api.common.Value;
78
import io.opentelemetry.sdk.logs.data.Body;
89
import io.opentelemetry.sdk.logs.data.LogRecordData;
910

1011
public class MyLogData extends DelegatingLogData {
1112

1213
private final Attributes attributes;
13-
private final Body body;
14+
private final Value<?> body;
1415

1516
public MyLogData(LogRecordData delegate, Attributes attributes) {
16-
this(delegate, attributes, delegate.getBody());
17+
this(delegate, attributes, delegate.getBodyValue());
1718
}
1819

19-
public MyLogData(LogRecordData delegate, Attributes attributes, Body body) {
20+
public MyLogData(LogRecordData delegate, Attributes attributes, Value<?> body) {
2021
super(delegate);
2122
this.attributes = attributes;
2223
this.body = body;
2324
}
2425

2526
@Override
26-
public Body getBody() {
27+
public Value<?> getBodyValue() {
2728
return body;
2829
}
2930

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private StrictMatcher(String key, String value) {
122122
}
123123

124124
@Override
125+
@SuppressWarnings("deprecation") // support deprecated semconv attributes for backwards compatibility
125126
public boolean test(
126127
Attributes attributes, LazyHttpUrl lazyHttpUrl, LazyHttpTarget lazyHttpTarget) {
127128
String val = MatcherGroup.getValueIncludingThreadName(attributes, key);
@@ -213,6 +214,7 @@ private KeyOnlyMatcher(String key) {
213214
}
214215

215216
@Override
217+
@SuppressWarnings("deprecation") // support deprecated semconv attributes for backwards compatibility
216218
public boolean test(
217219
Attributes attributes,
218220
@Nullable LazyHttpUrl lazyHttpUrl,
@@ -247,6 +249,7 @@ private String get() {
247249
}
248250
}
249251

252+
@SuppressWarnings("deprecation") // support deprecated semconv attributes for backwards compatibility
250253
private static boolean getHttpUrlKeyOldOrStableSemconv(AttributeKey<String> key) {
251254
String keyString = key.getKey();
252255
return keyString.equals(HttpIncubatingAttributes.HTTP_URL.getKey())

0 commit comments

Comments
 (0)