Skip to content

Commit 043825a

Browse files
authored
Fix end tracing span for Service bus processor client (Azure#19436)
1 parent 973ff23 commit 043825a

File tree

7 files changed

+20
-24
lines changed

7 files changed

+20
-24
lines changed

sdk/eventhubs/azure-messaging-eventhubs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Release History
22

33
## 5.6.0-beta.1 (Unreleased)
4-
4+
### Bug Fixes
5+
- Update to end the trace span regardless of the scope instance type for process operation tracing spans.
56

67
## 5.5.0 (2020-02-15)
78
### New features

sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import com.azure.messaging.eventhubs.models.PartitionEvent;
3434
import com.azure.messaging.eventhubs.models.PartitionOwnership;
3535
import com.azure.messaging.eventhubs.models.ReceiveOptions;
36-
import java.io.Closeable;
37-
import java.io.IOException;
3836
import java.time.Duration;
3937
import java.util.List;
4038
import java.util.Locale;
@@ -376,12 +374,12 @@ private void endProcessTracingSpan(Context processSpanContext, Signal<Void> sign
376374
}
377375

378376
Object spanObject = spanScope.get();
379-
if (spanObject instanceof Closeable) {
380-
Closeable close = (Closeable) spanObject;
377+
if (spanObject instanceof AutoCloseable) {
378+
AutoCloseable close = (AutoCloseable) spanObject;
381379
try {
382380
close.close();
383-
} catch (IOException ioException) {
384-
logger.error(Messages.EVENT_PROCESSOR_RUN_END, ioException);
381+
} catch (Exception exception) {
382+
logger.error(Messages.EVENT_PROCESSOR_RUN_END, exception);
385383
}
386384

387385
} else {

sdk/eventhubs/azure-messaging-eventhubs/src/main/resources/eventhubs-messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROCESS_SPAN_SCOPE_TYPE_ERROR=Process span scope type is not of type Closeable, but type: %s. Not closing the scope and span
1+
PROCESS_SPAN_SCOPE_TYPE_ERROR=Process span scope type is not of type AutoCloseable, but type: %s. Not closing the scope and span
22
MESSAGE_NOT_OF_TYPE=Message body type is not of type Data, but type: %s. Not setting body contents.
33
REQUEST_VALUE_NOT_VALID=Back pressure request value not valid. It must be between {} and {}.
44
EVENT_DATA_DOES_NOT_FIT=EventData does not fit into maximum number of batches. '%s'

sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorClientTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import reactor.core.publisher.Mono;
3030
import reactor.test.StepVerifier;
3131

32-
import java.io.Closeable;
3332
import java.time.Instant;
3433
import java.util.Collections;
3534
import java.util.HashMap;
@@ -139,7 +138,7 @@ public void testWithSimplePartitionProcessor() throws Exception {
139138
invocation -> {
140139
Context passed = invocation.getArgument(1, Context.class);
141140
return passed.addData(SPAN_CONTEXT_KEY, "value1")
142-
.addData("scope", (Closeable) () -> {
141+
.addData("scope", (AutoCloseable) () -> {
143142
})
144143
.addData(PARENT_SPAN_KEY, "value2");
145144
}
@@ -229,7 +228,7 @@ public void testProcessSpans() throws Exception {
229228
invocation -> {
230229
Context passed = invocation.getArgument(1, Context.class);
231230
assertTrue(passed.getData(MESSAGE_ENQUEUED_TIME).isPresent());
232-
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (Closeable) () -> {
231+
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (AutoCloseable) () -> {
233232
return;
234233
}).addData(PARENT_SPAN_KEY, "value2");
235234
}
@@ -450,7 +449,7 @@ public void testSingleEventReceiveHeartBeat() throws InterruptedException {
450449
when(tracer.start(eq("EventHubs.process"), any(), eq(ProcessKind.PROCESS))).thenAnswer(
451450
invocation -> {
452451
Context passed = invocation.getArgument(1, Context.class);
453-
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (Closeable) () -> {
452+
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (AutoCloseable) () -> {
454453
return;
455454
}).addData(PARENT_SPAN_KEY, "value2");
456455
}

sdk/servicebus/azure-messaging-servicebus/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Release History
22

33
## 7.1.0-beta.1 (Unreleased)
4-
4+
### Bug Fixes
5+
- Update to end the trace span regardless of the scope instance type for process operation tracing spans.
56

67
## 7.0.2 (2021-02-10)
78
### Dependency Updates

sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusProcessorClient.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import reactor.core.publisher.Signal;
1616
import reactor.core.scheduler.Schedulers;
1717

18-
import java.io.Closeable;
19-
import java.io.IOException;
2018
import java.util.Locale;
2119
import java.util.Objects;
2220
import java.util.Optional;
@@ -264,20 +262,20 @@ private void endProcessTracingSpan(Context processSpanContext, Signal<Void> sign
264262
if (!spanScope.isPresent() || !tracerProvider.isEnabled()) {
265263
return;
266264
}
267-
if (spanScope.get() instanceof Closeable) {
268-
Closeable close = (Closeable) processSpanContext.getData(SCOPE_KEY).get();
265+
if (spanScope.get() instanceof AutoCloseable) {
266+
AutoCloseable close = (AutoCloseable) processSpanContext.getData(SCOPE_KEY).get();
269267
try {
270268
close.close();
271-
tracerProvider.endSpan(processSpanContext, signal);
272-
} catch (IOException ioException) {
273-
logger.error("endTracingSpan().close() failed with an error %s", ioException);
269+
} catch (Exception exception) {
270+
logger.error("endTracingSpan().close() failed with an error %s", exception);
274271
}
275272

276273
} else {
277274
logger.warning(String.format(Locale.US,
278-
"Process span scope type is not of type Closeable, but type: %s. Not closing the scope and span",
279-
spanScope.get() != null ? spanScope.getClass() : "null"));
275+
"Process span scope type is not of type AutoCloseable, but type: %s. Not closing the scope"
276+
+ " and span", spanScope.get() != null ? spanScope.getClass() : "null"));
280277
}
278+
tracerProvider.endSpan(processSpanContext, signal);
281279
}
282280

283281
private Context startProcessTracingSpan(ServiceBusReceivedMessage receivedMessage, String entityPath,

sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusProcessorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import reactor.core.publisher.FluxSink;
1616
import reactor.core.publisher.Mono;
1717

18-
import java.io.Closeable;
1918
import java.time.OffsetDateTime;
2019
import java.util.ArrayList;
2120
import java.util.Collections;
@@ -353,7 +352,7 @@ public void testProcessorWithTracingEnabled() throws InterruptedException {
353352
invocation -> {
354353
Context passed = invocation.getArgument(1, Context.class);
355354
assertTrue(passed.getData(MESSAGE_ENQUEUED_TIME).isPresent());
356-
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (Closeable) () -> {
355+
return passed.addData(SPAN_CONTEXT_KEY, "value1").addData("scope", (AutoCloseable) () -> {
357356
return;
358357
}).addData(PARENT_SPAN_KEY, "value2");
359358
}

0 commit comments

Comments
 (0)