Skip to content

Commit

Permalink
HPCC4J-612 Shift to zero-code instrumentaton
Browse files Browse the repository at this point in the history
- Removes manually declared spans
- Adds WithSpan annotations on several clients
- Adds hascredentials span attribute to current span
- Ensures executeECLScript is traced

Signed-off-by: Pastrana <[email protected]>
  • Loading branch information
Pastrana authored and Pastrana committed Sep 17, 2024
1 parent 7050cb3 commit ca685f9
Show file tree
Hide file tree
Showing 37 changed files with 443 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
import org.hpccsystems.commons.ecl.FieldDef;
import org.hpccsystems.commons.ecl.RecordDefinitionTranslator;

import org.hpccsystems.dfs.client.RowServiceOutputStream;
import org.hpccsystems.dfs.client.Utils;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.semconv.ServerAttributes;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*******************************************************************************/
package org.hpccsystems.dfs.client;

import org.hpccsystems.dfs.client.Utils;

import org.hpccsystems.commons.ecl.FieldDef;
import org.hpccsystems.commons.ecl.RecordDefinitionTranslator;
import org.hpccsystems.commons.errors.HpccFileException;
Expand All @@ -22,7 +20,6 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.semconv.ServerAttributes;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.ServiceAttributes;

/**
Expand Down
53 changes: 30 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<project.benchmarking>false</project.benchmarking>
<opentelemetry.bom.version>1.38.0</opentelemetry.bom.version>
<opentelemetry.semconv.version>1.25.0-alpha</opentelemetry.semconv.version>
<opentelemetry.instrumentation.annotations.version>2.6.0</opentelemetry.instrumentation.annotations.version>
</properties>

<scm>
Expand Down Expand Up @@ -135,6 +136,12 @@
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<!-- Not managed by opentelemetry-bom -->
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>${opentelemetry.instrumentation.annotations.version}</version>
</dependency>
<dependency>
<!-- Not managed by opentelemetry-bom -->
<groupId>io.opentelemetry.semconv</groupId>
Expand Down Expand Up @@ -190,29 +197,29 @@
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>${axis2.version}</version>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>${axis2.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hpccsystems.ws.client;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -43,14 +42,12 @@

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.ServerAttributes;

Expand Down Expand Up @@ -91,6 +88,7 @@ public boolean isTargetHPCCContainerized() throws Exception
return targetsContainerizedHPCC;
}

@WithSpan
private boolean getTargetHPCCIsContainerized(Connection conn) throws Exception
{
if (wsconn == null)
Expand Down Expand Up @@ -155,6 +153,7 @@ public Version getTargetHPCCBuildVersion()
return targetHPCCBuildVersion;
}

@WithSpan
private String getTargetHPCCBuildVersionString() throws Exception
{
if (wsconn == null)
Expand Down Expand Up @@ -266,47 +265,29 @@ protected boolean initBaseWsClient(Connection connection, boolean fetchVersionAn

if (fetchVersionAndContainerMode)
{
Span fetchHPCCVerSpan = getWsClientSpanBuilder("FetchHPCCVersion").setSpanKind(SpanKind.INTERNAL).startSpan();
try (Scope scope = fetchHPCCVerSpan.makeCurrent())
try
{
try
{
targetHPCCBuildVersion = new Version(getTargetHPCCBuildVersionString());
}
catch (Exception e)
{
initErrMessage = "BaseHPCCWsClient: Could not stablish target HPCC bulid version, review all HPCC connection values";
if (!e.getLocalizedMessage().isEmpty())
initErrMessage = initErrMessage + "\n" + e.getLocalizedMessage();
success = false;
}
targetHPCCBuildVersion = new Version(getTargetHPCCBuildVersionString());
}
finally
catch (Exception e)
{
fetchHPCCVerSpan.setStatus(success ? StatusCode.OK : StatusCode.ERROR, initErrMessage);
fetchHPCCVerSpan.end();
initErrMessage = "BaseHPCCWsClient: Could not stablish target HPCC bulid version, review all HPCC connection values";
if (!e.getLocalizedMessage().isEmpty())
initErrMessage = initErrMessage + "\n" + e.getLocalizedMessage();
success = false;
}

Span fetchHPCCContainerMode = getWsClientSpanBuilder("FetchHPCCContainerMode").startSpan();
try (Scope scope = fetchHPCCContainerMode.makeCurrent())
try
{
try
{
targetsContainerizedHPCC = getTargetHPCCIsContainerized(wsconn);
}
catch (Exception e)
{
initErrMessage = initErrMessage + "\nBaseHPCCWsClient: Could not determine target HPCC Containerization mode, review all HPCC connection values";
if (!e.getLocalizedMessage().isEmpty())
initErrMessage = initErrMessage + "\n" + e.getLocalizedMessage();

success = false;
}
targetsContainerizedHPCC = getTargetHPCCIsContainerized(wsconn);
}
finally
catch (Exception e)
{
fetchHPCCContainerMode.setStatus(success ? StatusCode.OK : StatusCode.ERROR, initErrMessage);
fetchHPCCContainerMode.end();
initErrMessage = initErrMessage + "\nBaseHPCCWsClient: Could not determine target HPCC Containerization mode, review all HPCC connection values";
if (!e.getLocalizedMessage().isEmpty())
initErrMessage = initErrMessage + "\n" + e.getLocalizedMessage();

success = false;
}
}
if (!initErrMessage.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
import org.hpccsystems.ws.client.wrappers.gen.filespray.ProgressResponseWrapper;
import org.w3c.dom.Document;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;

/**
* Facilitates File Spray related activities.
* This includes listing available dropzones, uploading files to dropzone, listing files in a dropzone,
Expand Down Expand Up @@ -356,7 +359,6 @@ private void initWsFileSprayStub(Connection connection)
{
initErrMessage += "\nCould not initialize FileSprayStub - Review all HPCC connection values";
}

}

/**
Expand Down Expand Up @@ -421,6 +423,7 @@ public void setFileUploadReadBufferLength(int length)
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public boolean handleSprayResponse(ProgressResponseWrapper progressResponseWrapper, int maxRetries, int milliesBetweenRetry)
throws Exception, org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
{
Expand Down Expand Up @@ -560,7 +563,8 @@ public List<DropZoneWrapper> fetchLocalDropZones() throws Exception, ArrayOfEspE
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public List<DropZoneWrapper> fetchDropZones(String dropzoneNetAddress) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public List<DropZoneWrapper> fetchDropZones(@SpanAttribute String dropzoneNetAddress) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();

Expand Down Expand Up @@ -621,7 +625,8 @@ public List<DropZoneWrapper> fetchDropZones(String dropzoneNetAddress) throws Ex
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public String copyFile(String from, String to, boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public String copyFile(@SpanAttribute String from, @SpanAttribute String to, @SpanAttribute boolean overwrite) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
Copy cp = new Copy();
Expand Down Expand Up @@ -671,7 +676,8 @@ public String copyFile(String from, String to, boolean overwrite) throws Excepti
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public DropZoneFilesResponseWrapper fetchDropZones(String dzname, String netaddress, String os, String path, String subfolder, boolean dironly,
@WithSpan
public DropZoneFilesResponseWrapper fetchDropZones(@SpanAttribute String dzname, @SpanAttribute String netaddress, @SpanAttribute String os, @SpanAttribute String path, String subfolder, boolean dironly,
boolean watchvisibleonely) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
Expand Down Expand Up @@ -699,6 +705,7 @@ public DropZoneFilesResponseWrapper fetchDropZones(String dzname, String netaddr
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
@WithSpan
public DropZoneFilesResponseWrapper fetchDropZones(DropZoneFilesRequestWrapper szrequest) throws Exception, ArrayOfEspExceptionWrapper
{
if (szrequest == null) throw new Exception("DropZoneFilesRequestWrapper null detected");
Expand Down Expand Up @@ -740,7 +747,8 @@ public DropZoneFilesResponseWrapper fetchDropZones(DropZoneFilesRequestWrapper s
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public PhysicalFileStruct[] dzFileSearch(String dzname, String netaddr, String namefilter) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public PhysicalFileStruct[] dzFileSearch(@SpanAttribute String dzname, @SpanAttribute String netaddr, @SpanAttribute String namefilter) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();

Expand Down Expand Up @@ -788,7 +796,8 @@ public PhysicalFileStruct[] dzFileSearch(String dzname, String netaddr, String n
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public List<PhysicalFileStructWrapper> listFiles(String netAddress, String path, String OS) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public List<PhysicalFileStructWrapper> listFiles(@SpanAttribute String netAddress, @SpanAttribute String path, @SpanAttribute String OS) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();

Expand Down Expand Up @@ -994,8 +1003,9 @@ public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZ
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayVariable(DelimitedDataOptions options, DropZoneWrapper targetDropZone, String sourceFileName,
String targetFileName, String prefix, String destGroup, boolean overwrite, SprayVariableFormat format, Integer sourceMaxRecordSize,
@WithSpan
public ProgressResponseWrapper sprayVariable(@SpanAttribute DelimitedDataOptions options, @SpanAttribute DropZoneWrapper targetDropZone, @SpanAttribute String sourceFileName,
@SpanAttribute String targetFileName, String prefix, String destGroup, boolean overwrite, SprayVariableFormat format, Integer sourceMaxRecordSize,
Integer maxConnections, Boolean compress, Boolean replicate, Boolean failIfNoSourceFile, Boolean recordStructurePresent,
Integer expireDays) throws Exception, ArrayOfEspExceptionWrapper
{
Expand Down Expand Up @@ -1149,8 +1159,9 @@ public ProgressResponseWrapper sprayLocalXML(String sourceFileName, String targe
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayXML(DropZoneWrapper targetDropZone, String sourceFileName, String targetFileName, String prefix,
String destGroup, String rowtag, boolean overwrite, SprayVariableFormat format, Integer maxrecsize, Integer maxConnections,
@WithSpan
public ProgressResponseWrapper sprayXML(@SpanAttribute DropZoneWrapper targetDropZone,@SpanAttribute String sourceFileName,@SpanAttribute String targetFileName, String prefix,
@SpanAttribute String destGroup, String rowtag, boolean overwrite, SprayVariableFormat format, Integer maxrecsize, Integer maxConnections,
Boolean replicate, Boolean compress, Boolean failIfNoSourceFile, Integer expireDays) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();
Expand Down Expand Up @@ -1303,7 +1314,8 @@ public ProgressResponseWrapper sprayFixedLocalDropZone(String sourceFileName, in
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper sprayFixed(DropZoneWrapper targetDropZone, String sourceFileName, int recordSize, String targetFileLabel,
@WithSpan
public ProgressResponseWrapper sprayFixed(@SpanAttribute DropZoneWrapper targetDropZone, @SpanAttribute String sourceFileName, int recordSize, String targetFileLabel,
String prefix, String destGroup, boolean overwrite, Integer maxConnections, Boolean compress, Boolean replicate,
Boolean failIfNoSourceFile, Integer expireDays, String decryptKey, String encryptKey, Boolean nosplit, Boolean recordStructurePresent,
Integer transferBufferSize, Boolean wrap) throws Exception, ArrayOfEspExceptionWrapper
Expand Down Expand Up @@ -1364,7 +1376,8 @@ public ProgressResponseWrapper sprayFixed(DropZoneWrapper targetDropZone, String
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public ProgressResponseWrapper getDfuProgress(String dfuwuid) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public ProgressResponseWrapper getDfuProgress(@SpanAttribute String dfuwuid) throws Exception, ArrayOfEspExceptionWrapper
{
verifyStub();

Expand Down Expand Up @@ -1411,7 +1424,8 @@ public ProgressResponseWrapper getDfuProgress(String dfuwuid) throws Exception,
* @throws org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper
* the array of esp exception wrapper
*/
public boolean uploadFile(File file, String targetDropzoneAddress) throws Exception, ArrayOfEspExceptionWrapper
@WithSpan
public boolean uploadFile(@SpanAttribute File file, @SpanAttribute String targetDropzoneAddress) throws Exception, ArrayOfEspExceptionWrapper
{
List<DropZoneWrapper> dropZones = fetchDropZones(targetDropzoneAddress);
if (dropZones == null || dropZones.size() <= 0) throw new Exception("Could not fetch target dropzone information");
Expand Down Expand Up @@ -1469,7 +1483,8 @@ static protected void setupUploadResultParser() throws XPathExpressionException,
* - The target dropzone
* @return - Boolean, success
*/
public boolean uploadLargeFile(File uploadFile, DropZoneWrapper dropZone)
@WithSpan
public boolean uploadLargeFile(@SpanAttribute File uploadFile, @SpanAttribute DropZoneWrapper dropZone)
{
if (uploadFile == null || dropZone == null)
{
Expand Down Expand Up @@ -1619,7 +1634,8 @@ public boolean uploadLargeFile(File uploadFile, DropZoneWrapper dropZone)
* @throws Exception
* the exception
*/
private boolean uploadFile(File file, DropZoneWrapper dropZone) throws Exception
@WithSpan
private boolean uploadFile(@SpanAttribute File file, @SpanAttribute DropZoneWrapper dropZone) throws Exception
{
if (file == null) return false;
String filename = file.getName();
Expand Down
Loading

0 comments on commit ca685f9

Please sign in to comment.