diff --git a/libs/opentelemetry-exporter-jaeger-1.31.0.jar b/libs/opentelemetry-exporter-jaeger-1.31.0.jar new file mode 100644 index 0000000..f583fbe Binary files /dev/null and b/libs/opentelemetry-exporter-jaeger-1.31.0.jar differ diff --git a/libs/opentelemetry-exporter-logging-1.31.0.jar b/libs/opentelemetry-exporter-logging-1.31.0.jar new file mode 100644 index 0000000..0a7f972 Binary files /dev/null and b/libs/opentelemetry-exporter-logging-1.31.0.jar differ diff --git a/libs/opentelemetry-sdk-common-1.31.0.jar b/libs/opentelemetry-sdk-common-1.31.0.jar new file mode 100644 index 0000000..29135ff Binary files /dev/null and b/libs/opentelemetry-sdk-common-1.31.0.jar differ diff --git a/libs/opentelemetry-sdk-extension-autoconfigure-1.31.0.jar b/libs/opentelemetry-sdk-extension-autoconfigure-1.31.0.jar new file mode 100644 index 0000000..3352a35 Binary files /dev/null and b/libs/opentelemetry-sdk-extension-autoconfigure-1.31.0.jar differ diff --git a/libs/opentelemetry-sdk-logs-1.31.0.jar b/libs/opentelemetry-sdk-logs-1.31.0.jar new file mode 100644 index 0000000..7778fc0 Binary files /dev/null and b/libs/opentelemetry-sdk-logs-1.31.0.jar differ diff --git a/libs/opentelemetry-sdk-metrics-1.31.0.jar b/libs/opentelemetry-sdk-metrics-1.31.0.jar new file mode 100644 index 0000000..fe4db22 Binary files /dev/null and b/libs/opentelemetry-sdk-metrics-1.31.0.jar differ diff --git a/libs/opentelemetry-semconv-1.30.1-alpha.jar b/libs/opentelemetry-semconv-1.30.1-alpha.jar new file mode 100644 index 0000000..02ad084 Binary files /dev/null and b/libs/opentelemetry-semconv-1.30.1-alpha.jar differ diff --git a/src/server/Connection.java b/src/server/Connection.java index 785ec85..d607024 100644 --- a/src/server/Connection.java +++ b/src/server/Connection.java @@ -1,10 +1,15 @@ package server; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.Context; import shared.ExceptionLogger; import shared.FileUtil; import java.io.*; import java.net.Socket; +import java.util.concurrent.TimeUnit; public class Connection implements Runnable { @@ -12,8 +17,9 @@ public class Connection implements Runnable { private final Server server; private DataOutputStream out; private DataInputStream in; + private Span fileSend; - public Connection(Server server, Socket clientSocket) { + public Connection(Server server, Tracer trace, Span parent, Socket clientSocket) { this.server = server; this.clientSocket = clientSocket; try { @@ -22,6 +28,15 @@ public class Connection implements Runnable { } catch (Exception e) { ExceptionLogger.log(e); } + parent.addEvent("Connection Established", System.nanoTime(), TimeUnit.NANOSECONDS); + SpanBuilder sb = trace.spanBuilder("New Connection"); + Context ctx = Context.current(); + parent.storeInContext(ctx); + sb.setParent(ctx); + sb.setAttribute("INetAddress", clientSocket.getInetAddress().toString()); + sb.setAttribute("Port", clientSocket.getPort()); + sb.setAttribute("LocalPort", clientSocket.getLocalPort()); + fileSend = sb.startSpan(); } @Override @@ -34,7 +49,7 @@ public class Connection implements Runnable { byte command = in.readByte(); if (command == FileUtil.COMMAND.WRITE.type) - FileUtil.receive(in); + FileUtil.receive(in, fileSend); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/server/Server.java b/src/server/Server.java index 144bac6..e977793 100644 --- a/src/server/Server.java +++ b/src/server/Server.java @@ -1,10 +1,17 @@ package server; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.Tracer; import shared.ExceptionLogger; +import shared.OTelUtils; + import java.io.IOException; import java.net.ServerSocket; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; public class Server { @@ -14,17 +21,24 @@ public class Server { private volatile boolean running = true; + private static final OpenTelemetry ot = OTelUtils.create(); + public Server() { + Tracer main = ot.getTracer("Main Server", "0.69"); System.out.println("Starting server"); + SpanBuilder sb = main.spanBuilder("Start Server"); + Span sbs = sb.startSpan(); try { + sbs.addEvent("Server Start", System.nanoTime(), TimeUnit.NANOSECONDS); ServerSocket serverSocket = new ServerSocket(SERVER_PORT); System.out.println("Server Started"); while (running) - executor.execute(new Connection(this, serverSocket.accept())); + executor.execute(new Connection(this, main, sbs, serverSocket.accept())); serverSocket.close(); } catch (IOException e) { + sbs.recordException(e); ExceptionLogger.log(e); } executor.shutdown(); diff --git a/src/shared/FileUtil.java b/src/shared/FileUtil.java index 7f97730..1450780 100644 --- a/src/shared/FileUtil.java +++ b/src/shared/FileUtil.java @@ -1,6 +1,7 @@ package shared; import client.ChunkedCompressedChecksumFileWriter; +import io.opentelemetry.api.trace.Span; import net.jpountz.lz4.LZ4Compressor; import net.jpountz.lz4.LZ4Factory; import net.jpountz.lz4.LZ4FastDecompressor; @@ -11,6 +12,7 @@ import server.ChunkedCompressedChecksumFileReader; import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; public class FileUtil { @@ -55,9 +57,10 @@ public class FileUtil { } } - public static void receive(DataInputStream dataIn) { + public static void receive(DataInputStream dataIn, Span fs) { try { String path = createPath(dataIn.readUTF()); + fs.addEvent("Sending file " + path, System.nanoTime(), TimeUnit.NANOSECONDS); System.out.println("Writing to file: " + path); ChunkedCompressedChecksumFileReader reader = new ChunkedCompressedChecksumFileReader(dataIn, path, FileUtil.SEED); diff --git a/src/shared/OTelUtils.java b/src/shared/OTelUtils.java new file mode 100644 index 0000000..b20ce60 --- /dev/null +++ b/src/shared/OTelUtils.java @@ -0,0 +1,49 @@ +package shared; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.exporter.logging.LoggingMetricExporter; +import io.opentelemetry.exporter.logging.LoggingSpanExporter; +import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; +import io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv.ResourceAttributes; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; + +public class OTelUtils { + + public static OpenTelemetry create(){ + Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME.getKey(), "cum").put(ResourceAttributes.SERVICE_VERSION.getKey(), "0.1.0").build(); + + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) + .setResource(resource) + .build(); + + SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder() + .registerMetricReader(PeriodicMetricReader.builder(LoggingMetricExporter.create()).build()) + .setResource(resource) + .build(); + + SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder() + .addLogRecordProcessor(BatchLogRecordProcessor.builder(SystemOutLogRecordExporter.create()).build()) + .setResource(resource) + .build(); + + return OpenTelemetrySdk.builder() + .setTracerProvider(sdkTracerProvider) + .setMeterProvider(sdkMeterProvider) + .setLoggerProvider(sdkLoggerProvider) + .setPropagators(ContextPropagators.create(TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), W3CBaggagePropagator.getInstance()))) + .buildAndRegisterGlobal(); + } + +}