-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add web service consumer span processor (#205)
- Loading branch information
1 parent
6254b42
commit 4689e86
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../java/com/avioconsulting/mule/opentelemetry/internal/processor/WSCProcessorComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/com/avioconsulting/mule/opentelemetry/MuleOpenTelemetryWSCTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |