-
Notifications
You must be signed in to change notification settings - Fork 81
RUM-16564: Create and register stub for client stats feature if enabled #3523
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
Merged
abrooksv
merged 1 commit into
feature/client-side-stats
from
abrooks/client-side-stats-feature-registration
Jun 11, 2026
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
...dk-android-trace/src/main/kotlin/com/datadog/android/trace/internal/ClientStatsFeature.kt
This file contains hidden or 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,39 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2016-Present Datadog, Inc. | ||
| */ | ||
|
|
||
| package com.datadog.android.trace.internal | ||
|
|
||
| import android.content.Context | ||
| import com.datadog.android.api.feature.Feature | ||
| import com.datadog.android.api.feature.StorageBackedFeature | ||
| import com.datadog.android.api.storage.FeatureStorageConfiguration | ||
| import com.datadog.android.trace.internal.net.ClientStatsRequestFactory | ||
| import com.datadog.trace.common.metrics.NoOpMetricsAggregator | ||
|
|
||
| internal class ClientStatsFeature( | ||
| customEndpointUrl: String? | ||
| ) : StorageBackedFeature { | ||
| override val name = Feature.TRACING_CLIENT_STATS_FEATURE_NAME | ||
|
|
||
| override val storageConfiguration = FeatureStorageConfiguration( | ||
| // 512 KB | ||
| maxItemSize = 512L * 1024, | ||
| maxItemsPerBatch = 4000, | ||
| // 15 MB | ||
| maxBatchSize = 15L * 1024 * 1024, | ||
| // 18 hours | ||
| oldBatchThreshold = 18L * 60L * 60L * 1000L | ||
| ) | ||
|
|
||
| // TODO RUM-16565 Implement stats aggregator | ||
| internal val aggregator = NoOpMetricsAggregator() | ||
|
|
||
| override val requestFactory = ClientStatsRequestFactory(customEndpointUrl) | ||
|
|
||
| override fun onInitialize(appContext: Context) {} | ||
|
|
||
| override fun onStop() {} | ||
| } |
63 changes: 63 additions & 0 deletions
63
...trace/src/main/kotlin/com/datadog/android/trace/internal/net/ClientStatsRequestFactory.kt
This file contains hidden or 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,63 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2016-Present Datadog, Inc. | ||
| */ | ||
|
|
||
| package com.datadog.android.trace.internal.net | ||
|
|
||
| import com.datadog.android.api.context.DatadogContext | ||
| import com.datadog.android.api.net.Request | ||
| import com.datadog.android.api.net.RequestExecutionContext | ||
| import com.datadog.android.api.net.RequestFactory | ||
| import com.datadog.android.api.storage.RawBatchEvent | ||
| import com.datadog.android.trace.internal.domain.metrics.StatsPayload | ||
| import java.util.UUID | ||
|
|
||
| internal class ClientStatsRequestFactory( | ||
| internal val customStatsEndpointUrl: String? | ||
| ) : RequestFactory { | ||
|
|
||
| override fun create( | ||
| context: DatadogContext, | ||
| executionContext: RequestExecutionContext, | ||
| batchData: List<RawBatchEvent>, | ||
| batchMetadata: ByteArray? | ||
| ): Request { | ||
| val requestId = UUID.randomUUID().toString() | ||
|
|
||
| val baseUrl = customStatsEndpointUrl ?: (context.site.intakeEndpoint + "/api/v0.2/stats") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it indeed like that -
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Batches can't be split currently due to we can't create more than 1 Request in this class, | ||
| // nor can the batch building system report back when a batch will be filled before writing it, | ||
| // so we cant set a splitPayload flag in the batch's metadata. | ||
| val payload = StatsPayload(batchData.map { it.data }, splitPayload = false) | ||
|
|
||
| return Request( | ||
| id = requestId, | ||
| description = "Client Stats Request", | ||
| url = baseUrl, | ||
| headers = buildHeaders( | ||
| requestId, | ||
| context.clientToken, | ||
| context.source, | ||
| context.sdkVersion | ||
| ), | ||
| body = payload.toMsgPackPayload(), | ||
| contentType = "application/msgpack" | ||
| ) | ||
| } | ||
|
|
||
| private fun buildHeaders( | ||
| requestId: String, | ||
| clientToken: String, | ||
| source: String, | ||
| sdkVersion: String | ||
| ): Map<String, String> { | ||
| return mapOf( | ||
| RequestFactory.HEADER_API_KEY to clientToken, | ||
| RequestFactory.HEADER_EVP_ORIGIN to source, | ||
| RequestFactory.HEADER_EVP_ORIGIN_VERSION to sdkVersion, | ||
| RequestFactory.HEADER_REQUEST_ID to requestId | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Adding
customStatsEndpointUrlto the primary constructor of this publicdata classchanges the generatedcopy(...)andcopy$default(...)JVM signatures, as reflected in the API diff. Apps compiled against the previous SDK that callTraceConfiguration.copy(...)can then fail withNoSuchMethodErrorafter upgrading the runtime artifact, even though their source still compiles; keep the generated data-class constructor/copy shape stable and store the new internal value outside the primary constructor or behind an overload.Useful? React with 👍 / 👎.