Skip to content

Commit

Permalink
General enhancements (#390)
Browse files Browse the repository at this point in the history
* Creating okhttp instrumentation subprojects

* Added http span name test

* Updating tests

* Creating http span interceptors

* Creating HttpSpanNameInterceptor

* Renaming http spans

* Setting http span interceptor in builder

* Validating http known methods

* Adding tests

* Created okhttp test project

* Added okhttp simple test

* Creating okhttp bytebuddy project

* Adding okhttp library bytebuddy plugin symbols

* Configuring OkHttp3Singletons

* Substituting local bytebuddy dependencies

* Moving bytebuddy plugin definitions

* Flushing spans for androidTests

* Validating successful okhttp sync requests

* Adding tests

* Updating notice files

* Adding build variant listener

* Updating instrumentation plugins

* Attaching bytebuddy plugins using the ByteBuddyDependencyAttacher

* Updating tests

* Bumping version

* Creating android_tests.sh

* Running android tests as part of the CI checks

* Adding animalsniffer checks

* Ignoring animalsniffer unnecessary warnings

* Adding header

* Updating licence header tools

* Adding internal notice spotless step

* Ensuring internal comment is only added to production code

* Using InternalNoticeStep singleton

* Renaming tests.sh

* Updating ci job name

* Removing internal notice generator for now

* Simplifying disk config

* Adding resource interceptor

* Adding tests

* Updating sample app

* Updating description

* Clean up

* Updating sample app

* Converting sample app gradle files to kts

* Clean up

* Reorganizing sample app packages

* Adding okhttp instrumentation to sample app

* Adding logs

* Adding logs

* Updating processing times

* Adding context propagator

* Adding notice files

* Adding instrumentations to sample app
  • Loading branch information
LikeTheSalad authored Feb 14, 2025
1 parent c2bbe1c commit d3a7c8e
Show file tree
Hide file tree
Showing 67 changed files with 796 additions and 302 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ jobs:
- uses: ./.github/actions/setup
- name: Build
run: ./gradlew assemble
- name: Test
run: ./tests.sh
- name: Checks and unit tests
run: ./checks.sh
- name: Enable KVM for Android tests
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Android tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
script: ./android_tests.sh
- name: Store test results
if: success() || failure()
uses: actions/upload-artifact@v4
Expand All @@ -45,6 +55,7 @@ jobs:
path: |
**/build/test-results/testRelease*/TEST-*.xml
**/build/test-results/test/TEST-*.xml
**/build/outputs/androidTest-results/**/TEST-*.xml
# The very last job to report whether the Workflow passed.
# This will act as the Branch Protection gatekeeper
Expand Down
20 changes: 16 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,28 @@ if the author does not have commit access, should "Squash and merge".
You can run the following command to run all the unit tests available:

```text
./tests.sh
./checks.sh
```

For instrumentation tests, you'd need to have an Android Emulator running on your host machine, or a
device connected with developer mode enabled. Once that's available, you can run the following
command to execute those tests:

```text
./android_tests.sh
```

### Releasing

The release steps have been defined in `.ci/release.sh` which it gets triggered within the BuildKite context.
The release steps have been defined in `.ci/release.sh` which it gets triggered within the BuildKite
context.

Releases are triggered manually using GitHub actions, and the GitHub action is the one contacting BuildKite.
Releases are triggered manually using GitHub actions, and the GitHub action is the one contacting
BuildKite.
To run a release then
* Navigate to the [GitHub job](https://github.com/elastic/apm-agent-android/actions/workflows/release.yml)

* Navigate to
the [GitHub job](https://github.com/elastic/apm-agent-android/actions/workflows/release.yml)
* Choose Run workflow.
* Fill the form and click `Run workflow` and wait for a few minutes to complete

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.api.clock

import io.opentelemetry.sdk.common.Clock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.api.flusher

import io.opentelemetry.sdk.common.CompletableResultCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.api.flusher

import io.opentelemetry.sdk.common.CompletableResultCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.api.flusher

import io.opentelemetry.sdk.common.CompletableResultCode
Expand Down
2 changes: 1 addition & 1 deletion android-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
api(project(":android-common"))
implementation(libs.byteBuddy)
implementation(libs.byteBuddy.plugin)
compileOnly("com.android.tools.build:gradle:${project.property("androidGradlePlugin_version")}")
compileOnly(libs.android.plugin)
}

buildConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.plugin.extensions

import org.gradle.api.provider.ListProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.plugin.extensions

import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.plugin.internal

interface BuildVariantListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.plugin.internal

import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.plugin.internal

import co.elastic.otel.android.plugin.ElasticAgentPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import io.opentelemetry.api.common.Attributes
import io.opentelemetry.sdk.common.CompletableResultCode
import io.opentelemetry.sdk.logs.export.LogRecordExporter
import io.opentelemetry.sdk.metrics.export.MetricExporter
import io.opentelemetry.sdk.resources.Resource
import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.sdk.trace.export.SpanExporter

Expand Down Expand Up @@ -202,6 +203,10 @@ class ElasticApmAgent internal constructor(
managedAgentBuilder.setProcessorFactory(value)
}

fun setResourceInterceptor(value: Interceptor<Resource>) = apply {
managedAgentBuilder.setResourceInterceptor(value)
}

fun setHttpSpanInterceptor(value: Interceptor<SpanData>?) = apply {
httpSpanInterceptor = value
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.otel.android.extensions

import co.elastic.otel.android.api.ElasticOtelAgent
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.logs.Severity
import io.opentelemetry.api.trace.Span
import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.api.trace.StatusCode
import io.opentelemetry.context.Context
import io.opentelemetry.context.Scope
import java.time.Instant

private const val SCOPE_NAME = "ElasticAgentExtension"

fun ElasticOtelAgent.log(
body: String,
severity: Severity? = null,
severityText: String? = null,
attributes: Attributes? = null,
context: Context? = null,
observedTimestamp: Instant? = null,
timestamp: Instant? = null
) {
val logger = getOpenTelemetry().logsBridge.get(SCOPE_NAME).logRecordBuilder()
.setBody(body)
severity?.let { logger.setSeverity(it) }
severityText?.let { logger.setSeverityText(it) }
attributes?.let { logger.setAllAttributes(it) }
context?.let { logger.setContext(it) }
observedTimestamp?.let { logger.setObservedTimestamp(it) }
timestamp?.let { logger.setTimestamp(it) }
logger.emit()
}

fun ElasticOtelAgent.span(
name: String,
attributes: Attributes? = null,
kind: SpanKind? = null,
parentContext: Context? = null,
makeCurrent: Boolean = true,
body: (Span) -> Unit
) {
val builder = getOpenTelemetry().getTracer(SCOPE_NAME).spanBuilder(name)
attributes?.let { builder.setAllAttributes(it) }
kind?.let { builder.setSpanKind(it) }
parentContext?.let { builder.setParent(it) }

val span = builder.startSpan()
val scope: Scope? = if (makeCurrent) span.makeCurrent() else null
try {
body(span)
} catch (e: Throwable) {
span.setStatus(StatusCode.ERROR)
span.recordException(e)
} finally {
scope?.close()
span.end()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import io.opentelemetry.api.common.Attributes
import io.opentelemetry.sdk.common.CompletableResultCode
import io.opentelemetry.sdk.logs.export.LogRecordExporter
import io.opentelemetry.sdk.metrics.export.MetricExporter
import io.opentelemetry.sdk.resources.Resource
import io.opentelemetry.sdk.trace.export.SpanExporter
import java.util.UUID

Expand Down Expand Up @@ -185,6 +186,10 @@ class ManagedElasticOtelAgent private constructor(
elasticOpenTelemetryBuilder.setDeviceIdProvider(value)
}

fun setResourceInterceptor(value: Interceptor<Resource>) = apply {
elasticOpenTelemetryBuilder.setResourceInterceptor(value)
}

fun addSpanAttributesInterceptor(value: Interceptor<Attributes>) = apply {
elasticOpenTelemetryBuilder.addSpanAttributesInterceptor(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package co.elastic.otel.android.internal.features.diskbuffering

data class DiskBufferingConfiguration private constructor(val enabled: Boolean) {
internal var maxCacheFileSize = 1024 * 1024
internal var maxCacheSize = 30 * 1024 * 1024 // 30 MB
internal var maxCacheSize = 15 * 1024 * 1024 // 15 MB
internal var maxFileAgeForWrite: Long? = null
internal var minFileAgeForRead: Long? = null

Expand Down
Loading

0 comments on commit d3a7c8e

Please sign in to comment.