Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ kotlin {
all {
languageSettings.apply {
optIn("dev.kdriver.cdp.InternalCdpApi")
optIn("kotlin.time.ExperimentalTime")
optIn("kotlin.js.ExperimentalJsExport")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonPrimitive
import kotlin.reflect.KClass
import kotlin.time.Clock
import kotlin.time.ExperimentalTime

/**
* Default implementation of the [Connection] interface.
*/
@OptIn(ExperimentalTime::class)
open class DefaultConnection(
private val websocketUrl: String,
private val messageListeningScope: CoroutineScope,
Expand Down
2 changes: 0 additions & 2 deletions core/src/commonMain/kotlin/dev/kdriver/core/tab/DefaultTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.math.abs
import kotlin.time.Clock
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime

/**
* Represents a browser tab, which is a connection to a specific target in the browser.
*
* This class provides methods to interact with the tab, such as navigating to URLs,
* managing history, evaluating JavaScript expressions, and manipulating the DOM.
*/
@OptIn(ExperimentalTime::class)
open class DefaultTab(
websocketUrl: String,
messageListeningScope: CoroutineScope,
Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ ktor = "3.1.3"
mockk = "1.13.12"
jsoup = "1.16.2"
kotlinx-coroutines = "1.10.2"
kotlinx-serialization = "1.9.0"
kotlinx-serialization = "1.8.1"
kotlinx-io = "0.7.0"
zstd = "1.5.7-4"
opentelemetry = "1.56.0"

[plugins]
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Expand Down Expand Up @@ -39,3 +40,5 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
zstd = { module = "com.github.luben:zstd-jni", version.ref = "zstd" }
opentelemetry-extension-kotlin = { module = "io.opentelemetry:opentelemetry-extension-kotlin", version.ref = "opentelemetry" }
opentelemetry-sdk-testing = { module = "io.opentelemetry:opentelemetry-sdk-testing", version.ref = "opentelemetry" }
77 changes: 77 additions & 0 deletions opentelemetry/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.serialization)
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
alias(libs.plugins.dokka)
alias(libs.plugins.ksp)
alias(libs.plugins.maven)
}

mavenPublishing {
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.CENTRAL_PORTAL)
signAllPublications()
pom {
name.set("opentelemetry")
description.set("opentelemetry integration for kdriver.")
url.set(project.ext.get("url")?.toString())
licenses {
license {
name.set(project.ext.get("license.name")?.toString())
url.set(project.ext.get("license.url")?.toString())
}
}
developers {
developer {
id.set(project.ext.get("developer.id")?.toString())
name.set(project.ext.get("developer.name")?.toString())
email.set(project.ext.get("developer.email")?.toString())
url.set(project.ext.get("developer.url")?.toString())
}
}
scm {
url.set(project.ext.get("scm.url")?.toString())
}
}
}

kotlin {
// jvm
jvmToolchain(21)
jvm {
testRuns.named("test") {
executionTask.configure {
useJUnitPlatform()
}
}
}

applyDefaultHierarchyTemplate()
sourceSets {
all {
languageSettings.apply {
optIn("dev.kdriver.cdp.InternalCdpApi")
optIn("kotlin.js.ExperimentalJsExport")
}
}
val commonMain by getting {

Check warning on line 57 in opentelemetry/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

opentelemetry/build.gradle.kts#L57

Private property `commonMain` is unused. (detekt.UnusedPrivateProperty)
dependencies {
api(project(":core"))
implementation(libs.opentelemetry.extension.kotlin)
}
}
val jvmTest by getting {

Check warning on line 63 in opentelemetry/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

opentelemetry/build.gradle.kts#L63

Private property `jvmTest` is unused. (detekt.UnusedPrivateProperty)
dependencies {
implementation(kotlin("test"))
implementation(libs.tests.mockk)
implementation(libs.opentelemetry.sdk.testing)
}
}
}
}

detekt {
buildUponDefaultConfig = true
config.setFrom("${rootProject.projectDir}/detekt.yml")
source.from(file("src/commonMain/kotlin"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.kdriver.opentelemetry

import dev.kdriver.core.browser.Browser
import dev.kdriver.core.tab.Tab
import io.opentelemetry.api.trace.Tracer

/**
* Wraps an existing browser with OpenTelemetry instrumentation.
*
* This extension function allows you to add tracing to an existing Browser.
* All tabs opened through the wrapped browser will automatically be traced.
*
* @param tracer The OpenTelemetry tracer to use for creating spans.
* @return An instrumented Browser that wraps this browser.
*
* @sample
* ```kotlin
* val browser = createBrowser(this, config)
* val tracedBrowser = browser.withTracing(tracer)
* ```
*/
fun Browser.withTracing(
tracer: Tracer,
): Browser {
return OpenTelemetryBrowser(this, tracer)
}

/**
* Wraps an existing tab with OpenTelemetry instrumentation.
*
* This extension function allows you to add tracing to an existing Tab.
* All actions performed on the wrapped tab will automatically be traced.
*
* @param tracer The OpenTelemetry tracer to use for creating spans.
* @return An instrumented Tab that wraps this tab.
*
* @sample
* ```kotlin
* val tab = browser.get("https://example.com")
* val tracedTab = tab.withTracing(tracer)
* ```
*/
fun Tab.withTracing(
tracer: Tracer,
): Tab {
return OpenTelemetryTab(this, tracer)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.kdriver.opentelemetry

import dev.kdriver.core.browser.Browser
import dev.kdriver.core.tab.Tab
import io.opentelemetry.api.trace.Tracer

Check warning on line 6 in opentelemetry/src/commonMain/kotlin/dev/kdriver/opentelemetry/OpenTelemetryBrowser.kt

View check run for this annotation

codefactor.io / CodeFactor

opentelemetry/src/commonMain/kotlin/dev/kdriver/opentelemetry/OpenTelemetryBrowser.kt#L6

OpenTelemetryBrowser is missing required documentation. (detekt.UndocumentedPublicClass)
class OpenTelemetryBrowser(
private val browser: Browser,
private val tracer: Tracer,
) : Browser by browser {

override suspend fun get(url: String, newTab: Boolean, newWindow: Boolean): Tab {
val result = browser.get(url, newTab, newWindow)
return if (newTab !is OpenTelemetryTab) OpenTelemetryTab(result, tracer) else result
}

}
Loading