@Override
    public void pre(SpanAdapter span, Exchange exchange, Endpoint endpoint) {
        super.pre(span, exchange, endpoint);

        String contentType = exchange.getIn().getHeader(CONTENT_TYPE, String.class);
        if (contentType != null) {
            span.setTag(SERVICEBUS_CONTENT_TYPE, contentType);
        }

        String correlationId = exchange.getIn().getHeader(CORRELATION_ID, String.class);
        if (correlationId != null) {
            span.setTag(SERVICEBUS_CORRELATION_ID, correlationId);
        }

        Long deliveryCount = exchange.getIn().getHeader(DELIVERY_COUNT, Long.class);
        if (deliveryCount != null) {
            span.setTag(SERVICEBUS_DELIVERY_COUNT, deliveryCount);
        }

        Long enqueuedSequenceNumber = exchange.getIn().getHeader(ENQUEUED_SEQUENCE_NUMBER, Long.class);
        if (enqueuedSequenceNumber != null) {
            span.setTag(SERVICEBUS_ENQUEUED_SEQUENCE_NUMBER, enqueuedSequenceNumber);
        }

        OffsetDateTime enqueuedTime = exchange.getIn().getHeader(ENQUEUED_TIME, OffsetDateTime.class);
        if (enqueuedTime != null) {
            span.setTag(SERVICEBUS_ENQUEUED_TIME, enqueuedTime.toString());
        }

        OffsetDateTime expiresAt = exchange.getIn().getHeader(EXPIRES_AT, OffsetDateTime.class);
        if (expiresAt != null) {
            span.setTag(SERVICEBUS_EXPIRES_AT, expiresAt.toString());
        }

        String partitionKey = exchange.getIn().getHeader(PARTITION_KEY, String.class);
        if (partitionKey != null) {
            span.setTag(SERVICEBUS_PARTITION_KEY, partitionKey);
        }

        String replyToSessionId = exchange.getIn().getHeader(REPLY_TO_SESSION_ID, String.class);
        if (replyToSessionId != null) {
            span.setTag(SERVICEBUS_REPLY_TO_SESSION_ID, replyToSessionId);
        }

        String sessionId = exchange.getIn().getHeader(SESSION_ID, String.class);
        if (sessionId != null) {
            span.setTag(SERVICEBUS_SESSION_ID, sessionId);
        }

        Duration timeToLive = exchange.getIn().getHeader(TIME_TO_LIVE, Duration.class);
        if (timeToLive != null) {
            span.setTag(SERVICEBUS_TIME_TO_LIVE, timeToLive.toString());
        }
    }
@Test
    public void testPre() {
        String contentType = "application/json";
        String correlationId = "1234";
        Long deliveryCount = 27L;
        Long enqueuedSequenceNumber = 1L;
        OffsetDateTime enqueuedTime = OffsetDateTime.now();
        OffsetDateTime expiresAt = OffsetDateTime.now();
        String partitionKey = "MyPartitionKey";
        String replyToSessionId = "MyReplyToSessionId";
        String sessionId = "4321";
        Duration ttl = Duration.ofDays(7);

        Endpoint endpoint = Mockito.mock(Endpoint.class);
        Exchange exchange = Mockito.mock(Exchange.class);
        Message message = Mockito.mock(Message.class);

        Mockito.when(endpoint.getEndpointUri()).thenReturn("azure-servicebus:topicOrQueueName");
        Mockito.when(exchange.getIn()).thenReturn(message);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.CONTENT_TYPE, String.class)).thenReturn(contentType);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.CORRELATION_ID, String.class)).thenReturn(correlationId);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.DELIVERY_COUNT, Long.class)).thenReturn(deliveryCount);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.ENQUEUED_SEQUENCE_NUMBER, Long.class))
                .thenReturn(enqueuedSequenceNumber);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.ENQUEUED_TIME, OffsetDateTime.class))
                .thenReturn(enqueuedTime);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.EXPIRES_AT, OffsetDateTime.class)).thenReturn(expiresAt);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.PARTITION_KEY, String.class)).thenReturn(partitionKey);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.REPLY_TO_SESSION_ID, String.class))
                .thenReturn(replyToSessionId);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.SESSION_ID, String.class)).thenReturn(sessionId);
        Mockito.when(message.getHeader(AzureServiceBusSpanDecorator.TIME_TO_LIVE, Duration.class)).thenReturn(ttl);

        AbstractMessagingSpanDecorator decorator = new AzureServiceBusSpanDecorator();

        MockSpanAdapter span = new MockSpanAdapter();

        decorator.pre(span, exchange, endpoint);

        assertEquals(contentType, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_CONTENT_TYPE));
        assertEquals(correlationId, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_CORRELATION_ID));
        assertEquals(deliveryCount, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_DELIVERY_COUNT));
        assertEquals(enqueuedSequenceNumber, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_ENQUEUED_SEQUENCE_NUMBER));
        assertEquals(enqueuedTime.toString(), span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_ENQUEUED_TIME));
        assertEquals(expiresAt.toString(), span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_EXPIRES_AT));
        assertEquals(partitionKey, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_PARTITION_KEY));
        assertEquals(replyToSessionId, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_REPLY_TO_SESSION_ID));
        assertEquals(sessionId, span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_SESSION_ID));
        assertEquals(ttl.toString(), span.tags().get(AzureServiceBusSpanDecorator.SERVICEBUS_TIME_TO_LIVE));
    }