Skip to content

Commit b2d9533

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

File tree

8 files changed

+36
-11
lines changed

8 files changed

+36
-11
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/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/LogProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import io.opentelemetry.api.common.AttributeKey;
1111
import io.opentelemetry.api.common.Attributes;
1212
import io.opentelemetry.api.common.AttributesBuilder;
13-
import io.opentelemetry.sdk.logs.data.Body;
13+
import io.opentelemetry.api.common.Value;
1414
import io.opentelemetry.sdk.logs.data.LogRecordData;
1515
import java.util.ArrayList;
1616
import java.util.List;
@@ -84,7 +84,7 @@ public LogRecordData processFromAttributes(LogRecordData log) {
8484
updatedLogBuffer.setLength(updatedLogBuffer.length() - separator.length());
8585
}
8686

87-
return new MyLogData(log, existingLogAttributes, Body.string(updatedLogBuffer.toString()));
87+
return new MyLogData(log, existingLogAttributes, Value.of(updatedLogBuffer.toString()));
8888
}
8989

9090
return log;
@@ -107,7 +107,7 @@ public LogRecordData processToAttributes(LogRecordData log) {
107107
applyRule(groupNames.get(i), toAttributeRulePatterns.get(i), bodyAsString, builder);
108108
}
109109

110-
return new MyLogData(log, builder.build(), Body.string(bodyAsString));
110+
return new MyLogData(log, builder.build(), Value.of(bodyAsString));
111111
}
112112

113113
public static boolean logHasAllFromAttributeKeys(

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

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

66
import io.opentelemetry.api.common.Attributes;
7-
import io.opentelemetry.sdk.logs.data.Body;
7+
import io.opentelemetry.api.common.Value;
88
import io.opentelemetry.sdk.logs.data.LogRecordData;
99

1010
public class MyLogData extends DelegatingLogData {
1111

1212
private final Attributes attributes;
13-
private final Body body;
13+
private final Value<?> body;
1414

1515
public MyLogData(LogRecordData delegate, Attributes attributes) {
16-
this(delegate, attributes, delegate.getBody());
16+
this(delegate, attributes, delegate.getBodyValue());
1717
}
1818

19-
public MyLogData(LogRecordData delegate, Attributes attributes, Body body) {
19+
public MyLogData(LogRecordData delegate, Attributes attributes, Value<?> body) {
2020
super(delegate);
2121
this.attributes = attributes;
2222
this.body = body;
2323
}
2424

2525
@Override
26-
public Body getBody() {
26+
public Value<?> getBodyValue() {
2727
return body;
2828
}
2929

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)