Code review comment: this isn't the same, since `locationIp` may or may not be assigned in the if condition

Code before review:
private TelemetryItem exportRequest(SpanData span, long itemCount) {
RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, span.getResource());
Attributes attributes = span.getAttributes();
long startEpochNanos = span.getStartEpochNanos();
telemetryBuilder.setId(span.getSpanId());
setTime(telemetryBuilder, startEpochNanos);
setItemCount(telemetryBuilder, itemCount);
MAPPINGS.map(attributes, telemetryBuilder);
addLinks(telemetryBuilder, span.getLinks());
String operationName = getOperationName(span);
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_NAME.toString(), operationName);
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_ID.toString(), span.getTraceId());
String aiLegacyParentId = span.getAttributes().get(AiSemanticAttributes.LEGACY_PARENT_ID);
if (aiLegacyParentId != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_PARENT_ID.toString(), aiLegacyParentId);
} else if (span.getParentSpanContext().isValid()) {
telemetryBuilder.addTag(
ContextTagKeys.AI_OPERATION_PARENT_ID.toString(),
span.getParentSpanContext().getSpanId());
}
String aiLegacyRootId = span.getAttributes().get(AiSemanticAttributes.LEGACY_ROOT_ID);
if (aiLegacyRootId != null) {
telemetryBuilder.addTag("ai_legacyRootID", aiLegacyRootId);
}
telemetryBuilder.setName(operationName);
telemetryBuilder.setDuration(
FormattedDuration.fromNanos(span.getEndEpochNanos() - startEpochNanos));
telemetryBuilder.setSuccess(getSuccess(span));
String httpUrl = getHttpUrlFromServerSpan(attributes);
if (httpUrl != null) {
telemetryBuilder.setUrl(httpUrl);
}
Long httpStatusCode = getStableAttribute(attributes, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_STATUS_CODE);
if (httpStatusCode == null) {
httpStatusCode = attributes.get(SemanticAttributes.RPC_GRPC_STATUS_CODE);
}
if (httpStatusCode != null) {
telemetryBuilder.setResponseCode(Long.toString(httpStatusCode));
} else {
telemetryBuilder.setResponseCode("0");
}
String locationIp = getStableAttribute(attributes, SemanticAttributes.CLIENT_ADDRESS, SemanticAttributes.HTTP_CLIENT_IP);
if (locationIp == null) {
locationIp = attributes.get(SemanticAttributes.NET_SOCK_PEER_ADDR);
}
if (locationIp != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_LOCATION_IP.toString(), locationIp);
}
telemetryBuilder.setSource(getSource(attributes));
String sessionId = attributes.get(AiSemanticAttributes.SESSION_ID);
if (sessionId != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_SESSION_ID.toString(), sessionId);
}
String deviceOs = attributes.get(AiSemanticAttributes.DEVICE_OS);
if (deviceOs != null) {
telemetryBuilder.addTag(AI_DEVICE_OS.toString(), deviceOs);
}
String deviceOsVersion = attributes.get(AiSemanticAttributes.DEVICE_OS_VERSION);
if (deviceOsVersion != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion);
}
if (checkIsPreAggregatedStandardMetric(span)) {
telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True");
}
Long enqueuedTime = attributes.get(AiSemanticAttributes.AZURE_SDK_ENQUEUED_TIME);
if (enqueuedTime != null) {
long timeSinceEnqueuedMillis =
Math.max(
0L, NANOSECONDS.toMillis(span.getStartEpochNanos()) - SECONDS.toMillis(enqueuedTime));
telemetryBuilder.addMeasurement("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
Long timeSinceEnqueuedMillis = attributes.get(AiSemanticAttributes.KAFKA_RECORD_QUEUE_TIME_MS);
if (timeSinceEnqueuedMillis != null) {
telemetryBuilder.addMeasurement("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
return telemetryBuilder.build();
}

Line under review: if (locationIp != null) {

Code after addressing the review:
private TelemetryItem exportRequest(SpanData span, long itemCount) {
RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create();
telemetryInitializer.accept(telemetryBuilder, span.getResource());
Attributes attributes = span.getAttributes();
long startEpochNanos = span.getStartEpochNanos();
telemetryBuilder.setId(span.getSpanId());
setTime(telemetryBuilder, startEpochNanos);
setItemCount(telemetryBuilder, itemCount);
MAPPINGS.map(attributes, telemetryBuilder);
addLinks(telemetryBuilder, span.getLinks());
String operationName = getOperationName(span);
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_NAME.toString(), operationName);
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_ID.toString(), span.getTraceId());
String aiLegacyParentId = span.getAttributes().get(AiSemanticAttributes.LEGACY_PARENT_ID);
if (aiLegacyParentId != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_OPERATION_PARENT_ID.toString(), aiLegacyParentId);
} else if (span.getParentSpanContext().isValid()) {
telemetryBuilder.addTag(
ContextTagKeys.AI_OPERATION_PARENT_ID.toString(),
span.getParentSpanContext().getSpanId());
}
String aiLegacyRootId = span.getAttributes().get(AiSemanticAttributes.LEGACY_ROOT_ID);
if (aiLegacyRootId != null) {
telemetryBuilder.addTag("ai_legacyRootID", aiLegacyRootId);
}
telemetryBuilder.setName(operationName);
telemetryBuilder.setDuration(
FormattedDuration.fromNanos(span.getEndEpochNanos() - startEpochNanos));
telemetryBuilder.setSuccess(getSuccess(span));
String httpUrl = getHttpUrlFromServerSpan(attributes);
if (httpUrl != null) {
telemetryBuilder.setUrl(httpUrl);
}
Long httpStatusCode = getStableOrOldAttribute(attributes, SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, SemanticAttributes.HTTP_STATUS_CODE);
if (httpStatusCode == null) {
httpStatusCode = attributes.get(SemanticAttributes.RPC_GRPC_STATUS_CODE);
}
if (httpStatusCode != null) {
telemetryBuilder.setResponseCode(Long.toString(httpStatusCode));
} else {
telemetryBuilder.setResponseCode("0");
}
String locationIp = getStableOrOldAttribute(attributes, SemanticAttributes.CLIENT_ADDRESS, SemanticAttributes.HTTP_CLIENT_IP);
if (locationIp == null) {
locationIp = attributes.get(SemanticAttributes.NET_SOCK_PEER_ADDR);
}
if (locationIp != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_LOCATION_IP.toString(), locationIp);
}
telemetryBuilder.setSource(getSource(attributes));
String sessionId = attributes.get(AiSemanticAttributes.SESSION_ID);
if (sessionId != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_SESSION_ID.toString(), sessionId);
}
String deviceOs = attributes.get(AiSemanticAttributes.DEVICE_OS);
if (deviceOs != null) {
telemetryBuilder.addTag(AI_DEVICE_OS.toString(), deviceOs);
}
String deviceOsVersion = attributes.get(AiSemanticAttributes.DEVICE_OS_VERSION);
if (deviceOsVersion != null) {
telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion);
}
if (checkIsPreAggregatedStandardMetric(span)) {
telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True");
}
Long enqueuedTime = attributes.get(AiSemanticAttributes.AZURE_SDK_ENQUEUED_TIME);
if (enqueuedTime != null) {
long timeSinceEnqueuedMillis =
Math.max(
0L, NANOSECONDS.toMillis(span.getStartEpochNanos()) - SECONDS.toMillis(enqueuedTime));
telemetryBuilder.addMeasurement("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
Long timeSinceEnqueuedMillis = attributes.get(AiSemanticAttributes.KAFKA_RECORD_QUEUE_TIME_MS);
if (timeSinceEnqueuedMillis != null) {
telemetryBuilder.addMeasurement("timeSinceEnqueued", (double) timeSinceEnqueuedMillis);
}
return telemetryBuilder.build();
}