diff --git a/example/docker/dashboards/akka-http.json b/example/docker/dashboards/akka-http.json index 50330c3d8..f624f64ef 100644 --- a/example/docker/dashboards/akka-http.json +++ b/example/docker/dashboards/akka-http.json @@ -21,7 +21,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "iteration": 1649259284064, + "iteration": 1652266513928, "links": [], "liveNow": false, "panels": [ @@ -33,9 +33,9 @@ "x": 0, "y": 0 }, - "id": 2, + "id": 60, "panels": [], - "title": "Rps", + "title": "HTTP Connections", "type": "row" }, { @@ -43,14 +43,7 @@ "bars": false, "dashLength": 10, "dashes": false, - "description": "Global amount of rps experienced by entire cluster", - "fieldConfig": { - "defaults": { - "displayName": "Global", - "unit": "reqps" - }, - "overrides": [] - }, + "description": "Number of simultaneous HTTP connections over time", "fill": 1, "fillGradient": 0, "gridPos": { @@ -60,7 +53,7 @@ "y": 1 }, "hiddenSeries": false, - "id": 4, + "id": 50, "legend": { "avg": false, "current": false, @@ -85,111 +78,22 @@ "spaceLength": 10, "stack": false, "steppedLine": false, - "targets": [ - { - "exemplar": true, - "expr": "sum(rate(promexample_http_server_duration_count[$__rate_interval]))", - "interval": "", - "legendFormat": "", - "refId": "A" - } - ], - "thresholds": [], - "timeRegions": [], - "title": "Akka http global rps", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "mode": "time", - "show": true, - "values": [] - }, - "yaxes": [ - { - "$$hashKey": "object:68", - "format": "reqps", - "logBase": 1, - "show": true - }, - { - "$$hashKey": "object:69", - "format": "short", - "logBase": 1, - "show": true - } - ], - "yaxis": { - "align": false - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "fieldConfig": { - "defaults": { - "unit": "reqps" - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 9 - }, - "hiddenSeries": false, - "id": 6, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "maxPerRow": 2, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "8.3.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "repeat": "http_label", - "repeatDirection": "h", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, "targets": [ { "datasource": { "type": "prometheus", "uid": "PCF20F3AB9C3C68CE" }, - "exemplar": false, - "expr": "sum by($http_label) (rate(promexample_http_server_duration_count[$__rate_interval]))", + "exemplar": true, + "expr": "promexample_akka_http_connection_count", "interval": "", - "legendFormat": "{{$http_label}}", + "legendFormat": "", "refId": "A" } ], "thresholds": [], "timeRegions": [], - "title": "Rps by $http_label", + "title": "HTTP connections", "tooltip": { "shared": true, "sort": 0, @@ -203,7 +107,7 @@ }, "yaxes": [ { - "format": "reqps", + "format": "short", "logBase": 1, "show": true }, @@ -218,288 +122,485 @@ } }, { - "collapsed": false, + "collapsed": true, "gridPos": { "h": 1, "w": 24, "x": 0, - "y": 33 - }, - "id": 12, - "panels": [], - "title": "Response time", - "type": "row" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "description": "Average response time across whole cluster", - "fieldConfig": { - "defaults": { - "unit": "ms" - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 7, - "w": 24, - "x": 0, - "y": 34 - }, - "hiddenSeries": false, - "id": 23, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "8.3.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "exemplar": true, - "expr": "sum(rate(promexample_http_server_duration_sum[$__rate_interval])) / sum(rate(promexample_http_server_duration_count[$__rate_interval]) > 0)", - "interval": "", - "legendFormat": "Avg", - "refId": "A" - } - ], - "thresholds": [], - "timeRegions": [], - "title": "Average global response time", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "mode": "time", - "show": true, - "values": [] + "y": 9 }, - "yaxes": [ + "id": 2, + "panels": [ { - "format": "ms", - "logBase": 1, - "show": true + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "description": "Global amount of rps experienced by entire cluster", + "fieldConfig": { + "defaults": { + "displayName": "Global", + "unit": "reqps" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 10 + }, + "hiddenSeries": false, + "id": 4, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "sum(rate(promexample_http_server_duration_count[$__rate_interval]))", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Akka http global rps", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:68", + "format": "reqps", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:69", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } }, { - "format": "short", - "logBase": 1, - "show": true + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "fieldConfig": { + "defaults": { + "unit": "reqps" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 18 + }, + "hiddenSeries": false, + "id": 6, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "maxPerRow": 2, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": "http_label", + "repeatDirection": "h", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "PCF20F3AB9C3C68CE" + }, + "exemplar": false, + "expr": "sum by($http_label) (rate(promexample_http_server_duration_count[$__rate_interval]))", + "interval": "", + "legendFormat": "{{$http_label}}", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Rps by $http_label", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:91", + "format": "reqps", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:92", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } } ], - "yaxis": { - "align": false - } + "title": "Rps", + "type": "row" }, { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "description": "", - "fieldConfig": { - "defaults": { - "unit": "ms" - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, + "collapsed": true, "gridPos": { - "h": 8, + "h": 1, "w": 24, "x": 0, - "y": 41 - }, - "hiddenSeries": false, - "id": 25, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "maxPerRow": 2, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "8.3.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "repeat": "http_label", - "repeatDirection": "h", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "exemplar": true, - "expr": "sum by($http_label)(rate(promexample_http_server_duration_sum[$__rate_interval])) / sum by($http_label)(rate(promexample_http_server_duration_count[$__rate_interval]) > 0)", - "interval": "", - "legendFormat": "{{$http_label}}", - "refId": "A" - } - ], - "thresholds": [], - "timeRegions": [], - "title": "Avg response time by $http_label ", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" + "y": 10 }, - "type": "graph", - "xaxis": { - "mode": "time", - "show": true, - "values": [] - }, - "yaxes": [ + "id": 12, + "panels": [ { - "format": "ms", - "logBase": 1, - "show": true + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "description": "Average response time across whole cluster", + "fieldConfig": { + "defaults": { + "unit": "ms" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 11 + }, + "hiddenSeries": false, + "id": 23, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "sum(rate(promexample_http_server_duration_sum[$__rate_interval])) / sum(rate(promexample_http_server_duration_count[$__rate_interval]) > 0)", + "interval": "", + "legendFormat": "Avg", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Average global response time", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "ms", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } }, { - "format": "short", - "logBase": 1, - "show": true + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "description": "", + "fieldConfig": { + "defaults": { + "unit": "ms" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 18 + }, + "hiddenSeries": false, + "id": 25, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "maxPerRow": 2, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "repeat": "http_label", + "repeatDirection": "h", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "sum by($http_label)(rate(promexample_http_server_duration_sum[$__rate_interval])) / sum by($http_label)(rate(promexample_http_server_duration_count[$__rate_interval]) > 0)", + "interval": "", + "legendFormat": "{{$http_label}}", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Avg response time by $http_label ", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "ms", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } } ], - "yaxis": { - "align": false - } + "title": "Response time", + "type": "row" }, { - "collapsed": false, + "collapsed": true, "gridPos": { "h": 1, "w": 24, "x": 0, - "y": 81 + "y": 11 }, "id": 18, - "panels": [], - "title": "Active requests", - "type": "row" - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "description": "Active http requests across whole cluster", - "fieldConfig": { - "defaults": { - "unit": "active requests" - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 24, - "x": 0, - "y": 82 - }, - "hiddenSeries": false, - "id": 40, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "8.3.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ + "panels": [ { - "exemplar": true, - "expr": "sum(promexample_http_server_active_requests)", - "interval": "", - "legendFormat": "global", - "refId": "A" + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "description": "Active http requests across whole cluster", + "fieldConfig": { + "defaults": { + "unit": "active requests" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 12 + }, + "hiddenSeries": false, + "id": 40, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "8.3.1", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "sum(promexample_http_server_active_requests)", + "interval": "", + "legendFormat": "global", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Active requests", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "active requests", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } } ], - "thresholds": [], - "timeRegions": [], "title": "Active requests", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "mode": "time", - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "active requests", - "logBase": 1, - "show": true - }, - { - "format": "short", - "logBase": 1, - "show": true - } - ], - "yaxis": { - "align": false - } + "type": "row" } ], "refresh": false, @@ -567,6 +668,6 @@ "timezone": "", "title": "Akka http", "uid": "tsTUhI3Gz", - "version": 3, + "version": 1, "weekStart": "" -} \ No newline at end of file +} diff --git a/otel-extension/src/main/java/io/scalac/mesmer/instrumentation/http/HttpExtConnectionAdvice.java b/otel-extension/src/main/java/io/scalac/mesmer/instrumentation/http/HttpExtConnectionAdvice.java new file mode 100644 index 000000000..8ef44c229 --- /dev/null +++ b/otel-extension/src/main/java/io/scalac/mesmer/instrumentation/http/HttpExtConnectionAdvice.java @@ -0,0 +1,19 @@ +package io.scalac.mesmer.instrumentation.http; + +import akka.http.scaladsl.model.HttpRequest; +import akka.http.scaladsl.model.HttpResponse; +import akka.stream.scaladsl.Flow; +import io.scalac.mesmer.otelextension.instrumentations.akka.http.AkkaHttpConnectionsInstrumentation; +import net.bytebuddy.asm.Advice; + +public class HttpExtConnectionAdvice { + + @Advice.OnMethodEnter + public static void bindAndHandle( + @Advice.Argument(value = 0, readOnly = false) Flow handler, + @Advice.Argument(1) String _interface, + @Advice.Argument(2) Integer port) { + handler = + AkkaHttpConnectionsInstrumentation.bindAndHandleConnectionsImpl(handler, _interface, port); + } +} diff --git a/otel-extension/src/main/java/io/scalac/mesmer/otelextension/MesmerAkkaHttpInstrumentationModule.java b/otel-extension/src/main/java/io/scalac/mesmer/otelextension/MesmerAkkaHttpInstrumentationModule.java index ece6bdf55..dd422e1c5 100644 --- a/otel-extension/src/main/java/io/scalac/mesmer/otelextension/MesmerAkkaHttpInstrumentationModule.java +++ b/otel-extension/src/main/java/io/scalac/mesmer/otelextension/MesmerAkkaHttpInstrumentationModule.java @@ -1,14 +1,17 @@ package io.scalac.mesmer.otelextension; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; + import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.tooling.muzzle.InstrumentationModuleMuzzle; import io.opentelemetry.javaagent.tooling.muzzle.VirtualFieldMappingsBuilder; import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef; +import io.scalac.mesmer.otelextension.instrumentations.akka.http.Connections; import io.scalac.mesmer.otelextension.instrumentations.akka.http.PathMatching; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -27,6 +30,7 @@ public MesmerAkkaHttpInstrumentationModule() { @Override public List typeInstrumentations() { + return Arrays.asList( PathMatching.asyncHandler(), PathMatching.uuidPathMatcher(), @@ -41,12 +45,18 @@ public List typeInstrumentations() { PathMatching.segmentPathMatcher(), PathMatching.numberPathMatcher(), PathMatching.remainingPathMatcher(), - PathMatching.rawMatcher()); + PathMatching.rawMatcher(), + Connections.connections()); + } + + @Override + public List getMuzzleHelperClassNames() { + return emptyList(); } @Override public Map getMuzzleReferences() { - return Collections.emptyMap(); + return emptyMap(); } @Override @@ -55,11 +65,6 @@ public void registerMuzzleVirtualFields(VirtualFieldMappingsBuilder builder) { builder.register("akka.http.scaladsl.server.PathMatcher$Matching", "java.lang.String"); } - @Override - public List getMuzzleHelperClassNames() { - return Collections.emptyList(); - } - @Override public List getAdditionalHelperClassNames() { return Arrays.asList( @@ -69,6 +74,9 @@ public List getAdditionalHelperClassNames() { "io.scalac.mesmer.otelextension.instrumentations.akka.http.UpdateHttpRouteWrapper$$anonfun$$nestedInanonfun$apply$1$1", "io.scalac.mesmer.otelextension.instrumentations.akka.http.UpdateHttpRouteWrapper", "io.scalac.mesmer.otelextension.instrumentations.akka.http.OverridingRawPatchMatcherImpl$", - "io.scalac.mesmer.otelextension.instrumentations.akka.http.OverridingRawPatchMatcherImpl"); + "io.scalac.mesmer.otelextension.instrumentations.akka.http.OverridingRawPatchMatcherImpl", + "io.scalac.mesmer.otelextension.instrumentations.akka.http.AkkaHttpConnectionsInstrumentation$", + "io.scalac.mesmer.otelextension.instrumentations.akka.http.AkkaHttpConnectionsInstrumentation$HttpConnectionInstruments$", + "io.scalac.mesmer.otelextension.instrumentations.akka.http.AkkaHttpConnectionsInstrumentation"); } } diff --git a/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/AkkaHttpConnectionsInstrumentation.scala b/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/AkkaHttpConnectionsInstrumentation.scala new file mode 100644 index 000000000..8f5b5796c --- /dev/null +++ b/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/AkkaHttpConnectionsInstrumentation.scala @@ -0,0 +1,44 @@ +package io.scalac.mesmer.otelextension.instrumentations.akka.http + +import akka.http.scaladsl.model.HttpRequest +import akka.http.scaladsl.model.HttpResponse +import akka.stream.scaladsl.Flow +import io.opentelemetry.api.GlobalOpenTelemetry +import io.opentelemetry.api.common.Attributes +import io.opentelemetry.api.metrics.LongUpDownCounter +import io.opentelemetry.instrumentation.api.config.Config + +import io.scalac.mesmer.core.akka.stream.BidiFlowForward + +object AkkaHttpConnectionsInstrumentation { + def bindAndHandleConnectionsImpl( + handler: Flow[HttpRequest, HttpResponse, Any], + interface: String, + port: Long + ): Flow[HttpRequest, HttpResponse, Any] = { + + val attributes = Attributes + .builder() + .put("interface", interface) + .put("port", port) + .build() + + val connectionsCountFlow = BidiFlowForward[HttpRequest, HttpResponse]( + onPreStart = () => HttpConnectionInstruments.httpConnectionsCounter.add(1, attributes), + onPostStop = () => HttpConnectionInstruments.httpConnectionsCounter.add(-1, attributes) + ) + connectionsCountFlow.join(handler) + } + + private object HttpConnectionInstruments { + private val meter = GlobalOpenTelemetry.getMeter("mesmer") + private val config = Config.get() + + val httpConnectionsCounter: LongUpDownCounter = meter + .upDownCounterBuilder( + config.getString("io.scalac.mesmer.metrics.http.connections", "akka_http_connection_count") + ) + .setDescription("Amount of HTTP connections currently being used") + .build() + } +} diff --git a/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/Connections.scala b/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/Connections.scala new file mode 100644 index 000000000..819d3678e --- /dev/null +++ b/otel-extension/src/main/scala/io/scalac/mesmer/otelextension/instrumentations/akka/http/Connections.scala @@ -0,0 +1,22 @@ +package io.scalac.mesmer.otelextension.instrumentations.akka.http + +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer +import net.bytebuddy.description.`type`.TypeDescription +import net.bytebuddy.description.method.MethodDescription +import net.bytebuddy.matcher.ElementMatcher +import net.bytebuddy.matcher.ElementMatchers + +object Connections { + + val connections: TypeInstrumentation = new TypeInstrumentation { + val typeMatcher: ElementMatcher[TypeDescription] = ElementMatchers + .named[TypeDescription]("akka.http.scaladsl.HttpExt") + + def transform(transformer: TypeTransformer): Unit = + transformer.applyAdviceToMethod( + ElementMatchers.named[MethodDescription]("bindAndHandle"), + "io.scalac.mesmer.instrumentation.http.HttpExtConnectionAdvice" + ) + } +}