Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add spotless config #18

Merged
merged 10 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ jobs:
- android/run-tests:
test-command: ./gradlew testDebug
- android/save-gradle-cache
lint:
executor:
name: android/android-machine
resource-class: large
tag: default
steps:
- checkout
- android/restore-gradle-cache
- run:
name: "Run Spotless"
command: ./gradlew spotlessCheck
smoke_test:
executor:
name: android/android-machine
Expand Down Expand Up @@ -89,6 +100,8 @@ workflows:
jobs:
- unit_test:
<<: *filters_always
- lint:
<<: *filters_always
- smoke_test:
<<: *filters_always
- publish_maven:
Expand All @@ -97,6 +110,7 @@ workflows:
- java_beeline
requires:
- unit_test
- lint
- smoke_test
nightly:
triggers:
Expand All @@ -108,4 +122,5 @@ workflows:
- main
jobs:
- unit_test
- lint
- smoke_test
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,kts}]
max_line_length = 200
ktlint_function_naming_ignore_when_annotated_with = Composable
# `java.util.*,kotlinx.android.synthetic.**` is the default value, we add org.junit.Assert for our unit tests
ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**,org.junit.Assert.*
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ build:
test:
./gradlew test

lint:
./gradlew spotlessCheck

format:
./gradlew spotlessApply

clean: clean-smoke-tests
./gradlew clean

Expand Down
80 changes: 42 additions & 38 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
`signing`
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.spotless)
}

android {
Expand All @@ -17,7 +18,7 @@ android {
minCompileSdk = 21
}

buildConfigField("String","HONEYCOMB_DISTRO_VERSION","\"0.0.1-alpha\"")
buildConfigField("String", "HONEYCOMB_DISTRO_VERSION", "\"0.0.1-alpha\"")

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand All @@ -30,7 +31,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
Expand Down Expand Up @@ -82,56 +83,59 @@ dependencies {
androidTestImplementation(libs.opentelemetry.android.agent)
}

apply("${project.rootDir}/spotless.gradle")

publishing {
publications {
val maven = create<MavenPublication>("release") {
groupId = "io.honeycomb.android"
artifactId = "honeycomb-opentelemetry-android"
version = "0.0.1-alpha"
val maven =
create<MavenPublication>("release") {
groupId = "io.honeycomb.android"
artifactId = "honeycomb-opentelemetry-android"
version = "0.0.1-alpha"

afterEvaluate {
from(components["release"])
}
afterEvaluate {
from(components["release"])
}

pom {
name = "Honeycomb OpenTelemetry Distribution for Android"
url = "https://github.com/honeycombio/honeycomb-opentelemetry-android"
description = "Honeycomb SDK for configuring OpenTelemetry instrumentation"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
pom {
name = "Honeycomb OpenTelemetry Distribution for Android"
url = "https://github.com/honeycombio/honeycomb-opentelemetry-android"
description = "Honeycomb SDK for configuring OpenTelemetry instrumentation"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
}
developers {
developer {
id = "Honeycomb"
name = "Honeycomb"
email = "support@honeycomb.io"
organization = "Honeycomb"
organizationUrl = "https://honeycomb.io"
developers {
developer {
id = "Honeycomb"
name = "Honeycomb"
email = "support@honeycomb.io"
organization = "Honeycomb"
organizationUrl = "https://honeycomb.io"
}
}
scm {
url = "https://github.com/honeycombio/honeycomb-opentelemetry-android"
connection = "scm:git:git@github.com:honeycombio/honeycomb-opentelemetry-android.git"
developerConnection = "scm:git:git@github.com:honeycombio/honeycomb-opentelemetry-android.git"
}
}
scm {
url = "https://github.com/honeycombio/honeycomb-opentelemetry-android"
connection = "scm:git:git@github.com:honeycombio/honeycomb-opentelemetry-android.git"
developerConnection = "scm:git:git@github.com:honeycombio/honeycomb-opentelemetry-android.git"
}
}
}

signing {
val base64key = System.getenv("GPG_BASE64")
val pw = System.getenv("GPG_PASSPHRASE")
val key = if (base64key != null && base64key != "") {
String(Base64.getDecoder().decode(base64key)).trim()
} else {
""
}

val key =
if (base64key != null && base64key != "") {
String(Base64.getDecoder().decode(base64key)).trim()
} else {
""
}

useInMemoryPgpKeys(key, pw)
sign(maven)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.honeycomb.opentelemetry.android

import android.os.Build
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import kotlin.time.Duration.Companion.seconds

@RunWith(AndroidJUnit4::class)
Expand All @@ -30,7 +28,8 @@ class HoneycombOptionsInstrumentedTest {
"service.name" to "unknown_service",
"honeycomb.distro.version" to "0.0.1-alpha",
"honeycomb.distro.runtime_version" to Build.VERSION.RELEASE,
), options.resourceAttributes
),
options.resourceAttributes,
)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<!-- This is needed for the smoke tests to be able to talk to the local collector. -->
<application android:usesCleartextTraffic="true">
</application>
</manifest>
</manifest>
103 changes: 56 additions & 47 deletions core/src/main/java/io/honeycomb/opentelemetry/android/Honeycomb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,26 @@ class Honeycomb {
/**
* Automatically configures OpenTelemetryRum based on values stored in the app's resources.
*/
fun configure(app: Application, options: HoneycombOptions): OpenTelemetryRum {
fun configure(
app: Application,
options: HoneycombOptions,
): OpenTelemetryRum {
val traceExporter = buildSpanExporter(options)
val metricsExporter = buildMetricsExporter(options)
val logsExporter = if (options.logsProtocol == OtlpProtocol.GRPC) {
OtlpGrpcLogRecordExporter.builder()
.setEndpoint(options.logsEndpoint)
.setTimeout(options.logsTimeout.toJavaDuration())
.setHeaders { options.logsHeaders }
.build()
} else {
OtlpHttpLogRecordExporter.builder()
.setEndpoint(options.logsEndpoint)
.setTimeout(options.logsTimeout.toJavaDuration())
.setHeaders { options.logsHeaders }
.build()
}
val logsExporter =
if (options.logsProtocol == OtlpProtocol.GRPC) {
OtlpGrpcLogRecordExporter.builder()
.setEndpoint(options.logsEndpoint)
.setTimeout(options.logsTimeout.toJavaDuration())
.setHeaders { options.logsHeaders }
.build()
} else {
OtlpHttpLogRecordExporter.builder()
.setEndpoint(options.logsEndpoint)
.setTimeout(options.logsTimeout.toJavaDuration())
.setHeaders { options.logsHeaders }
.build()
}

val resource =
Resource.builder().putAll(createAttributes(options.resourceAttributes)).build()
Expand All @@ -82,7 +86,10 @@ class Honeycomb {
// Normally, uncaught exception traces have no name, so add one.
crashInstrumentation.addAttributesExtractor(
AttributesExtractor.constant(
AttributeKey.stringKey("name"), "UncaughtException"))
AttributeKey.stringKey("name"),
"UncaughtException",
),
)

val batchSpanProcessor = BatchSpanProcessor.builder(traceExporter).build()

Expand All @@ -95,7 +102,7 @@ class Honeycomb {
.addMeterProviderCustomizer { builder, _ ->
builder.setResource(resource)
builder.registerMetricReader(
PeriodicMetricReader.builder(metricsExporter).build()
PeriodicMetricReader.builder(metricsExporter).build(),
)
}
.addLoggerProviderCustomizer { builder, _ ->
Expand All @@ -110,55 +117,57 @@ class Honeycomb {
}

private fun buildSpanExporter(options: HoneycombOptions): SpanExporter {
val traceExporter = if (options.tracesProtocol == OtlpProtocol.GRPC) {
OtlpGrpcSpanExporter.builder()
.setEndpoint(options.tracesEndpoint)
.setTimeout(options.tracesTimeout.toJavaDuration())
.setHeaders { options.tracesHeaders }
.build()
} else {
OtlpHttpSpanExporter.builder()
.setEndpoint(options.tracesEndpoint)
.setTimeout(options.tracesTimeout.toJavaDuration())
.setHeaders { options.tracesHeaders }
.build()
}
val traceExporter =
if (options.tracesProtocol == OtlpProtocol.GRPC) {
OtlpGrpcSpanExporter.builder()
.setEndpoint(options.tracesEndpoint)
.setTimeout(options.tracesTimeout.toJavaDuration())
.setHeaders { options.tracesHeaders }
.build()
} else {
OtlpHttpSpanExporter.builder()
.setEndpoint(options.tracesEndpoint)
.setTimeout(options.tracesTimeout.toJavaDuration())
.setHeaders { options.tracesHeaders }
.build()
}

if (options.debug) {
return SpanExporter.composite(traceExporter, OtlpJsonLoggingSpanExporter.create())
}
return traceExporter;
return traceExporter
}

private fun buildMetricsExporter(options: HoneycombOptions): MetricExporter {
val metricsExporter = if (options.metricsProtocol == OtlpProtocol.GRPC) {
OtlpGrpcMetricExporter.builder()
.setEndpoint(options.metricsEndpoint)
.setTimeout(options.metricsTimeout.toJavaDuration())
.setHeaders { options.metricsHeaders }
.build()
} else {
OtlpHttpMetricExporter.builder()
.setEndpoint(options.metricsEndpoint)
.setTimeout(options.metricsTimeout.toJavaDuration())
.setHeaders { options.metricsHeaders }
.build()
}
val metricsExporter =
if (options.metricsProtocol == OtlpProtocol.GRPC) {
OtlpGrpcMetricExporter.builder()
.setEndpoint(options.metricsEndpoint)
.setTimeout(options.metricsTimeout.toJavaDuration())
.setHeaders { options.metricsHeaders }
.build()
} else {
OtlpHttpMetricExporter.builder()
.setEndpoint(options.metricsEndpoint)
.setTimeout(options.metricsTimeout.toJavaDuration())
.setHeaders { options.metricsHeaders }
.build()
}

if (options.debug) {
return CompositeMetricExporter(metricsExporter, OtlpJsonLoggingMetricExporter.create())
}
return metricsExporter;
return metricsExporter
}
}

private class CompositeMetricExporter(vararg val exporters: MetricExporter): MetricExporter {
private class CompositeMetricExporter(vararg val exporters: MetricExporter) : MetricExporter {
override fun getAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {
return try {
exporters.first().getAggregationTemporality(instrumentType);
exporters.first().getAggregationTemporality(instrumentType)
} catch (e: NoSuchElementException) {
// doesn't really matter
AggregationTemporality.DELTA;
AggregationTemporality.DELTA
}
}

Expand Down
Loading
Loading