Skip to content

Commit

Permalink
feat: add web service consumer span processor (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
manikmagar authored Sep 9, 2024
1 parent 6254b42 commit 4689e86
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@
<version>1.4.01</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-wsc-connector</artifactId>
<version>1.10.0</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.opentelemetry</groupId>-->
<!-- <artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.avioconsulting.mule.opentelemetry.internal.processor;

import com.avioconsulting.mule.opentelemetry.api.traces.TraceComponent;
import io.opentelemetry.api.trace.SpanKind;
import org.mule.runtime.api.component.Component;
import org.mule.runtime.api.metadata.TypedValue;
import org.mule.runtime.api.notification.EnrichedServerNotification;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WSCProcessorComponent extends AbstractProcessorComponent {
@Override
protected String getNamespace() {
return "wsc";
}

@Override
protected List<String> getOperations() {
return Collections.singletonList("consume");
}

@Override
protected List<String> getSources() {
return Collections.emptyList();
}

@Override
protected SpanKind getSpanKind() {
return SpanKind.CLIENT;
}

@Override
protected String getDefaultSpanName(Map<String, String> tags) {
return tags.get("mule.wsc.config.service") + ":" + tags.get("mule.wsc.consumer.operation");
}

@Override
protected <A> Map<String, String> getAttributes(Component component, TypedValue<A> attributes) {
ComponentWrapper componentWrapper = new ComponentWrapper(component, configurationComponentLocator);
Map<String, String> tags = new HashMap<>();
tags.put("mule.wsc.consumer.operation", componentWrapper.getParameter("operation"));
Map<String, String> configConnectionParameters = componentWrapper.getConfigConnectionParameters();
tags.put("mule.wsc.config.service", configConnectionParameters.get("service"));
tags.put("mule.wsc.config.port", configConnectionParameters.get("port"));
if (configConnectionParameters.containsKey("address")) {
tags.put("mule.wsc.config.address", configConnectionParameters.get("address"));
}
return tags;
}

@Override
public TraceComponent getEndTraceComponent(EnrichedServerNotification notification) {
return super.getEndTraceComponent(notification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ com.avioconsulting.mule.opentelemetry.internal.processor.DBProcessorComponent
com.avioconsulting.mule.opentelemetry.internal.processor.AnypointMQProcessorComponent
com.avioconsulting.mule.opentelemetry.internal.processor.MuleCoreProcessorComponent
com.avioconsulting.mule.opentelemetry.internal.processor.APIKitProcessorComponent
com.avioconsulting.mule.opentelemetry.internal.processor.WSCProcessorComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.avioconsulting.mule.opentelemetry;

import com.avioconsulting.mule.opentelemetry.internal.opentelemetry.sdk.test.DelegatedLoggingSpanTestExporter;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.Test;

import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.awaitility.Awaitility.await;

public class MuleOpenTelemetryWSCTest extends AbstractMuleArtifactTraceTest {

@Override
protected String getConfigFile() {
return "wsc-flow-test.xml";
}

@Test
public void testWSCTracing() throws Exception {
Throwable throwable = catchThrowable(() -> flowRunner("consume-wsc-flow").run());
await().untilAsserted(() -> assertThat(DelegatedLoggingSpanTestExporter.spanQueue)
.hasSize(2));
assertThat(DelegatedLoggingSpanTestExporter.spanQueue)
.filteredOnAssertions(span -> assertThat(span)
.as("Span for wsc:consume")
.extracting("spanName", "spanKind")
.containsOnly("Calculator:Add", "CLIENT"))
.isNotEmpty()
.hasSize(1)
.element(0)
.extracting("attributes", as(InstanceOfAssertFactories.map(String.class, Object.class)))
.hasSizeGreaterThanOrEqualTo(6)
.containsEntry("mule.wsc.consumer.operation", "Add")
.containsEntry("mule.app.processor.name", "consume")
.containsEntry("mule.app.processor.namespace", "wsc")
.containsEntry("mule.wsc.config.port", "CalculatorSoap12")
.containsEntry("mule.wsc.config.address", "http://localhost/calculator.asmx")
.containsEntry("mule.wsc.config.service", "Calculator");
}

}
28 changes: 28 additions & 0 deletions src/test/resources/wsc-flow-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd">
<import file="global-common.xml"/>
<wsc:config name="Web_Service_Consumer_Config_Test" doc:name="Web Service Consumer Config" doc:id="16d99563-1133-45df-8ee9-0c436eb7bfa5" >
<wsc:connection wsdlLocation="http://localhost/calculator.asmx?wsdl" service="Calculator" port="CalculatorSoap12" address="http://localhost/calculator.asmx"/>
</wsc:config>
<flow name="consume-wsc-flow" doc:id="95f1a18d-c935-4ab6-9393-bc4c8834dd54">
<wsc:consume doc:name="Consume" doc:id="a7478426-8854-49d4-8df0-133e39e1f973" config-ref="Web_Service_Consumer_Config_Test" operation="Add">
<wsc:message>
<wsc:body><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>1</intA>
<intB>2</intB>
</Add>
</soap:Body>
</soap:Envelope>]]></wsc:body>
</wsc:message>
</wsc:consume>

</flow>

</mule>

0 comments on commit 4689e86

Please sign in to comment.