[FR] Allow custom attributes on built-in traces via global attribute API#8031
[FR] Allow custom attributes on built-in traces via global attribute API#8031jrodiz wants to merge 1 commit intofirebase:mainfrom
Conversation
Resolves firebase#6664. FirebasePerformance already had putAttribute/getAttribute/removeAttribute/ getAttributes backed by a ConcurrentHashMap, but they were @hide and not wired into built-in trace serialization. This change makes them public and ensures global attributes are included on all traces (built-in and custom). Changes: - Make global attribute methods (putAttribute, removeAttribute, getAttribute, getAttributes) public on FirebasePerformance - Expose MAX_TRACE_CUSTOM_ATTRIBUTES, MAX_ATTRIBUTE_KEY_LENGTH, MAX_ATTRIBUTE_VALUE_LENGTH as public constants on FirebasePerformance - Update api.txt with the expanded public API surface - Merge global attributes in TraceMetricBuilder (screen + custom Trace objects) - Add global attributes to AppStartTrace (_app_start) - Add global attributes to AppStateMonitor.sendSessionLog() (_fs, _bs) - Merge global attributes in NetworkRequestMetricBuilder (auto + manual HTTP) - Trace/request-level attributes take precedence over global on key conflicts Test coverage (TraceMetric.custom_attributes): - AppStartTraceTest: global attrs on _app_start - AppStateMonitorTest: global attrs on _app_in_foreground, _app_in_background, and screen traces (_st_*) - TraceMetricBuilderTest: global attrs merged, trace-level overrides global - NetworkRequestMetricBuilderTest: global attrs on network requests, per-request overrides global - TransportManagerTest: global attrs on built-in traces at ApplicationInfo level
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
[FR] Allow custom attributes on built-in traces (#6664)
Summary
Resolves #6664
Firebase Performance already had
putAttribute/getAttribute/removeAttribute/getAttributesonFirebasePerformancebacked by aConcurrentHashMap, but these were@hideand not wired into built-in trace serialization. This change makes them public and ensures global attributes are included on all traces and network requests — built-in and custom alike.Changes
FirebasePerformance.java— Made 4 global attribute methods (putAttribute,removeAttribute,getAttribute,getAttributes) and 3 constants (MAX_TRACE_CUSTOM_ATTRIBUTES,MAX_ATTRIBUTE_KEY_LENGTH,MAX_ATTRIBUTE_VALUE_LENGTH) publicapi.txt— Added the 4 methods to the publicFirebasePerformanceAPI surfaceTraceMetricBuilder.java— Merges global attributes into allTrace-based metrics (screen traces, custom traces); trace-level attributes override global on key conflictAppStartTrace.java— Applies global attributes to the_app_starttrace metricAppStateMonitor.java— Applies global attributes to foreground (_fs) and background (_bs) session tracesNetworkRequestMetricBuilder.java— Merges global attributes into all network request metrics (auto-instrumented OkHttp and manualHttpMetric); per-request attributes override global on key conflictUsage
These attributes will appear on
_app_start,_app_in_foreground,_app_in_background, screen traces (_st_*), network requests, and all custom traces automatically.Design Notes
checkAttribute()logicmCustomAttributesis aConcurrentHashMap;getAttributes()returns a defensive copy_app_start: global attributes must be set before the first activity resumes (e.g., inApplication.onCreate())Test Coverage
_app_start—AppStartTraceTest_app_in_foreground(_fs) —AppStateMonitorTest_app_in_background(_bs) —AppStateMonitorTest_st_*) —AppStateMonitorTestNetworkRequestMetricBuilderTestApplicationInfo—TransportManagerTest