Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions firebase-perf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Unreleased

- [feature] Made custom attribute methods (`putAttribute`, `removeAttribute`, `getAttribute`,
`getAttributes`) and related constants (`MAX_TRACE_CUSTOM_ATTRIBUTES`, `MAX_ATTRIBUTE_KEY_LENGTH`,
`MAX_ATTRIBUTE_VALUE_LENGTH`) public on `FirebasePerformance`. Custom attributes set via these
methods are attached to all traces — automatic and manual. [#6664]

# 22.0.5

- [changed] Bumped internal dependencies.
Expand Down
4 changes: 4 additions & 0 deletions firebase-perf/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
package com.google.firebase.perf {

@javax.inject.Singleton public class FirebasePerformance {
method public String? getAttribute(String);
method public java.util.Map<java.lang.String!,java.lang.String!> getAttributes();
method public static com.google.firebase.perf.FirebasePerformance getInstance();
method public boolean isPerformanceCollectionEnabled();
method public com.google.firebase.perf.metrics.HttpMetric newHttpMetric(String, @com.google.firebase.perf.FirebasePerformance.HttpMethod String);
method public com.google.firebase.perf.metrics.HttpMetric newHttpMetric(java.net.URL, @com.google.firebase.perf.FirebasePerformance.HttpMethod String);
method public com.google.firebase.perf.metrics.Trace newTrace(String);
method public void putAttribute(String, String);
method public void removeAttribute(String);
method public void setPerformanceCollectionEnabled(boolean);
method public static com.google.firebase.perf.metrics.Trace startTrace(String);
field public static final int MAX_ATTRIBUTE_KEY_LENGTH = 40; // 0x28
Expand Down
2 changes: 1 addition & 1 deletion firebase-perf/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
#

version=22.0.6
version=22.1.0
latestReleasedVersion=22.0.5
android.enableUnitTestBinaryResources=true

Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public class FirebasePerformance implements FirebasePerformanceAttributable {

/** Maximum allowed number of attributes allowed in a trace. */
@SuppressWarnings("unused") // Used in Javadoc.
private static final int MAX_TRACE_CUSTOM_ATTRIBUTES = Constants.MAX_TRACE_CUSTOM_ATTRIBUTES;
public static final int MAX_TRACE_CUSTOM_ATTRIBUTES = Constants.MAX_TRACE_CUSTOM_ATTRIBUTES;

/** Maximum allowed length of the Key of the {@link Trace} attribute */
@SuppressWarnings("unused") // Used in Javadoc.
private static final int MAX_ATTRIBUTE_KEY_LENGTH = Constants.MAX_ATTRIBUTE_KEY_LENGTH;
public static final int MAX_ATTRIBUTE_KEY_LENGTH = Constants.MAX_ATTRIBUTE_KEY_LENGTH;

/** Maximum allowed length of the Value of the {@link Trace} attribute */
@SuppressWarnings("unused") // Used in Javadoc.
private static final int MAX_ATTRIBUTE_VALUE_LENGTH = Constants.MAX_ATTRIBUTE_VALUE_LENGTH;
public static final int MAX_ATTRIBUTE_VALUE_LENGTH = Constants.MAX_ATTRIBUTE_VALUE_LENGTH;

/** Maximum allowed length of the name of the {@link Trace} */
@SuppressWarnings("unused") // Used in Javadoc.
Expand Down Expand Up @@ -332,7 +332,6 @@ public boolean isPerformanceCollectionEnabled() {
* length is limited to {@link #MAX_ATTRIBUTE_KEY_LENGTH}
* @param value value of the attribute. The max length is limited to {@link
* #MAX_ATTRIBUTE_VALUE_LENGTH}
* @hide
*/
@Override
public void putAttribute(@NonNull String attribute, @NonNull String value) {
Expand Down Expand Up @@ -371,7 +370,6 @@ private void checkAttribute(@Nullable String key, @Nullable String value) {
* Removes the attribute from the global list of attributes.
*
* @param attribute name of the attribute to be removed from the global pool.
* @hide
*/
@Override
public void removeAttribute(@NonNull String attribute) {
Expand All @@ -383,7 +381,6 @@ public void removeAttribute(@NonNull String attribute) {
*
* @param attribute name of the attribute to fetch the value for
* @return the value of the attribute if it exists or null otherwise.
* @hide
*/
@Override
@Nullable
Expand All @@ -395,7 +392,6 @@ public String getAttribute(@NonNull String attribute) {
* Returns the map of all the attributes currently added in the global pool.
*
* @return map of attributes and its values currently added to the running Traces
* @hide
*/
@Override
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,48 @@ public void syncLogForGaugeMetric_performanceDisabled_noInteractionWithFirebaseI

// region Global Custom Attributes Behaviour

@Test
public void logBuiltInTraces_globalCustomAttributesAreAdded() {
FirebasePerformance.getInstance().removeAttribute("experiment_id");
FirebasePerformance.getInstance().removeAttribute("user_tier");
FirebasePerformance.getInstance().putAttribute("experiment_id", "exp_123");
FirebasePerformance.getInstance().putAttribute("user_tier", "gold");

// 1. App Start Trace (_as)
TraceMetric appStartTrace = createValidTraceMetric().toBuilder().setName("_as").build();
testTransportManager.log(appStartTrace);
fakeExecutorService.runAll();
PerfMetric loggedAppStart = getLastLoggedEvent(times(1));
assertThat(loggedAppStart.getApplicationInfo().getCustomAttributesMap())
.containsEntry("experiment_id", "exp_123");
clearLastLoggedEvents();

// 2. Screen Trace (_st_MainActivity)
TraceMetric screenTrace =
createValidTraceMetric().toBuilder()
.setName("_st_MainActivity")
.putCounters(Constants.CounterNames.FRAMES_TOTAL.toString(), 100L)
.build();
testTransportManager.log(screenTrace);
fakeExecutorService.runAll();
PerfMetric loggedScreenTrace = getLastLoggedEvent(times(1));
assertThat(loggedScreenTrace.getApplicationInfo().getCustomAttributesMap())
.containsEntry("user_tier", "gold");
clearLastLoggedEvents();

// 3. Network Request
NetworkRequestMetric networkMetric = createValidNetworkRequestMetric();
testTransportManager.log(networkMetric);
fakeExecutorService.runAll();
PerfMetric loggedNetworkMetric = getLastLoggedEvent(times(1));
assertThat(loggedNetworkMetric.getApplicationInfo().getCustomAttributesMap())
.containsEntry("experiment_id", "exp_123");

// Cleanup
FirebasePerformance.getInstance().removeAttribute("experiment_id");
FirebasePerformance.getInstance().removeAttribute("user_tier");
}

@Test
public void logTraceMetric_globalCustomAttributesAreAdded() {
FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
Expand Down
Loading