-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add custom tracking module #1168
Merged
surbhiia
merged 5 commits into
signalfx:feature/next-gen
from
surbhiia:feature/custom-monitoring
Feb 10, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e8c34c
Add custom tracking module
surbhiia 597cdfc
Minor corrections
surbhiia a91f97f
Merge branch 'feature/next-gen' into feature/custom-monitoring
surbhiia 3f53863
Improve MenuFragment code
surbhiia 8f8f4d3
Merge branch 'feature/custom-monitoring' of https://github.com/surbhi…
surbhiia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...customtracking/src/main/java/com/splunk/rum/customtracking/extension/SplunkRUMAgentExt.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,27 @@ | ||
/* | ||
* 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.extension | ||
|
||
import com.splunk.rum.customtracking.CustomTracking | ||
import com.splunk.rum.integration.agent.api.SplunkRUMAgent | ||
|
||
/** | ||
* Extension property to access the [CustomTracking] instance via [SplunkRUMAgent]. | ||
*/ | ||
@Suppress("UnusedReceiverParameter") | ||
val SplunkRUMAgent.customTracking: CustomTracking | ||
get() = CustomTracking.instance |
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 |
---|---|---|
|
@@ -22,3 +22,4 @@ include ':app' | |
|
||
// Main entry point | ||
include ':agent' | ||
include ':instrumentation:runtime:customtracking' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed the context here but how come we're removing the 'otel' part of this name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the what PR covers bullet points - The published library name was earlier - rum-common-otel-otel which was changed to rum-common-otel