-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add custom tracking module * Minor corrections * Improve MenuFragment code
- Loading branch information
Showing
13 changed files
with
265 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
common/otel/src/main/java/com/splunk/sdk/common/otel/internal/RumConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2025 Splunk Inc. | ||
* | ||
* Licensed 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 com.splunk.sdk.common.otel.internal | ||
|
||
import io.opentelemetry.api.common.AttributeKey | ||
|
||
object RumConstants { | ||
const val RUM_TRACER_NAME: String = "SplunkRum" | ||
val WORKFLOW_NAME_KEY: AttributeKey<String> = AttributeKey.stringKey("workflow.name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import plugins.ConfigAndroidLibrary | ||
import plugins.ConfigPublish | ||
import utils.artifactIdProperty | ||
import utils.artifactPrefix | ||
import utils.instrumentationPrefix | ||
import utils.versionProperty | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("kotlin-android") | ||
id("kotlin-parcelize") | ||
} | ||
|
||
apply<ConfigAndroidLibrary>() | ||
apply<ConfigPublish>() | ||
|
||
ext { | ||
set(artifactIdProperty, "$artifactPrefix$instrumentationPrefix${project.name}") | ||
set(versionProperty, Configurations.sdkVersionName) | ||
} | ||
|
||
android { | ||
namespace = "com.splunk.rum.customtracking" | ||
} | ||
|
||
dependencies { | ||
api(Dependencies.Otel.api) | ||
implementation(project(":integration:agent:api")) | ||
implementation(project(":common:otel")) | ||
implementation(Dependencies.SessionReplay.commonLogger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<issues format="6" by="lint 7.4.0" type="baseline" client="gradle" dependencies="false" name="AGP (7.4.0)" variant="all" version="7.4.0"> | ||
|
||
</issues> |
83 changes: 83 additions & 0 deletions
83
...tion/runtime/customtracking/src/main/java/com/splunk/rum/customtracking/CustomTracking.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2025 Splunk Inc. | ||
* | ||
* Licensed 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 com.splunk.rum.customtracking | ||
|
||
import com.cisco.android.common.logger.Logger | ||
import com.splunk.sdk.common.otel.OpenTelemetry | ||
import com.splunk.sdk.common.otel.internal.RumConstants | ||
import io.opentelemetry.api.common.Attributes | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.api.trace.Tracer | ||
|
||
|
||
class CustomTracking internal constructor() { | ||
|
||
/** | ||
* Add a custom event. This can be useful to capture business events. | ||
* | ||
* <p>This event will be turned into a Span and sent to the RUM ingest along with other, | ||
* auto-generated spans. | ||
* | ||
* @param name The name of the event. | ||
* @param attributes Any {@link Attributes} to associate with the event. | ||
*/ | ||
fun trackCustomEvent(name: String, attributes: Attributes) { | ||
val tracer = getTracer() ?: return | ||
tracer.spanBuilder(name).setAllAttributes(attributes).startSpan().end() | ||
} | ||
|
||
/** | ||
* Start a Span to track a named workflow. | ||
* | ||
* @param workflowName The name of the workflow to start. | ||
* @return A {@link Span} that has been started. | ||
*/ | ||
fun trackWorkflow(workflowName: String): Span? { | ||
val tracer = getTracer() ?: return null | ||
return tracer.spanBuilder(workflowName) | ||
.setAttribute(RumConstants.WORKFLOW_NAME_KEY, workflowName) | ||
.startSpan() | ||
} | ||
|
||
|
||
/** | ||
* Retrieves the Tracer instance for the application. | ||
* | ||
* @return A Tracer instance if available, or null if the OpenTelemetry instance is null. | ||
*/ | ||
private fun getTracer(): Tracer? { | ||
return OpenTelemetry.instance?.sdkTracerProvider?.get(RumConstants.RUM_TRACER_NAME).also { | ||
if (it == null) { | ||
Logger.e( | ||
TAG, | ||
"Opentelemetry instance is null. Cannot track custom events/workflow." | ||
) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
private const val TAG = "CustomTracking" | ||
|
||
/** | ||
* The instance of [CustomTracking]. | ||
*/ | ||
@JvmStatic | ||
val instance by lazy { CustomTracking() } | ||
} | ||
} |
Oops, something went wrong.