Interface TransactionStore

  • All Known Implementing Classes:
    InMemoryTransactionStore

    public interface TransactionStore
    Transaction store for managing service transactions.
    • Method Detail

      • transactionIdFor

        default String transactionIdFor​(org.mule.runtime.api.event.Event muleEvent)
        A default implementation to get a mule correlation id as a local transaction id.
        Parameters:
        muleEvent - Event
        Returns:
        String transaction id
      • startTransaction

        void startTransaction​(TraceComponent traceComponent,
                              String rootFlowName,
                              io.opentelemetry.api.trace.SpanBuilder rootFlowSpan)
        Start a new transaction. This usually happens when a new source flow starts. If the transaction with `transactionId` already exists but for different rootFlowName, then it is possible that new rootFlowSpan is a child flow invocation. In that case, span may be added to an existing transaction as a span.
        Parameters:
        traceComponent - TraceComponent with tracing information
        rootFlowName - Name of the flow requesting to start transaction.
        rootFlowSpan - SpanBuilder for building the root span.
      • addTransactionTags

        void addTransactionTags​(String transactionId,
                                String tagPrefix,
                                Map<String,​String> tags)
        Add custom tags to an existing transaction.
        Parameters:
        transactionId - A unique transaction id within the context of an application. Eg. Correlation id.
        tagPrefix - String
        tags - Map of String Keys and String Values containing the tags.
      • getTransactionContext

        TransactionContext getTransactionContext​(String transactionId,
                                                 org.mule.runtime.api.component.location.ComponentLocation componentLocation)
        Get the Context of the initiating flow span. This may be required to propagate context for a given transaction.
        Parameters:
        transactionId - A unique transaction id within the context of an application. Eg. Correlation id.
        componentLocation - ComponentLocation
        Returns:
        Context
      • getTraceIdForTransaction

        String getTraceIdForTransaction​(String transactionId)
        Get the Trace Id associated the transaction
        Parameters:
        transactionId - A unique transaction id within the context of an application. Eg. Correlation id.
        Returns:
        traceId
      • endTransaction

        default void endTransaction​(String transactionId,
                                    String rootFlowName)
        End a transaction represented by provided transaction id and rootFlowName, if exists.
        Parameters:
        transactionId - A unique transaction id within the context of an application. Eg. Correlation id.
        rootFlowName - Name of the flow requesting to start transaction.
      • endTransaction

        default void endTransaction​(String transactionId,
                                    String rootFlowName,
                                    Consumer<io.opentelemetry.api.trace.Span> spanUpdater)
        End a transaction represented by provided transaction id and rootFlowName, if exists. Consumer parameter allows updating the Span before ending. This is useful in scenarios like setting processing status code to error.

        Here is an example of setting Error when processor execution fails. transactionStore.endTransaction(traceComponent.getTransactionId(), traceComponent.getName(), rootSpan -> { if(notification.getException() != null) { rootSpan.setStatus(StatusCode.ERROR, notification.getException().getMessage()); rootSpan.recordException(notification.getException()); } });

        Parameters:
        transactionId - A unique transaction id within the context of an application. Eg. Correlation id.
        rootFlowName - Name of the flow requesting to start transaction.
        spanUpdater - Consumer to allow updating Span before ending.
      • addProcessorSpan

        void addProcessorSpan​(String containerName,
                              TraceComponent traceComponent,
                              io.opentelemetry.api.trace.SpanBuilder spanBuilder)
        Add a new processor span under an existing transaction.
        Parameters:
        containerName - String such as Flow name that contains requested location
        traceComponent - TraceComponent for span
        spanBuilder - SpanBuilder
      • endProcessorSpan

        default void endProcessorSpan​(String transactionId,
                                      String location)
        End an existing span under an existing transaction.
        Parameters:
        transactionId - String to add end span for
        location - String of the processor
      • endProcessorSpan

        default SpanMeta endProcessorSpan​(String transactionId,
                                          String location,
                                          Consumer<io.opentelemetry.api.trace.Span> spanUpdater)
        End an existing span under an existing transaction. Consumer parameter allows updating the Span before ending. This is useful in scenarios like setting processing status code to error.

        Here is an example of setting Error when processor execution fails. transactionStore.endProcessorSpan(traceComponent.getTransactionId(), traceComponent.getLocation(), s -> { if(notification.getEvent().getError().isPresent()) { Error error = notification.getEvent().getError().get(); s.setStatus(StatusCode.ERROR, error.getDescription()); s.recordException(error.getCause()); } });

        Parameters:
        transactionId - String
        location - String of the span
        spanUpdater - Consumer to allow updating Span before ending.