Skip to content

Commit e221a50

Browse files
Add console URL logging. (#7871)
* Created a console URL logging prototype. * Fix style. * Add loggings to console URL. * Fix style. * Fix style. * Fix bool to BOOL. * Address comments. * Fix format. * Fix format. * Add tests and update logging message. * Move logging to startWithConfiguration * Cleanup. * Correct log tag.
1 parent f510350 commit e221a50

File tree

5 files changed

+206
-2
lines changed

5 files changed

+206
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#import <Foundation/Foundation.h>
16+
17+
/** This class generated the console URLs for a project or a metric.*/
18+
@interface FPRConsoleURLGenerator : NSObject
19+
20+
/**
21+
* Generates the console URL for the dashboard page of the project.
22+
*
23+
* @param projectID The Firebase project ID.
24+
* @param bundleID The bundle ID of this project.
25+
* @return The console URL for the dashboard page.
26+
*/
27+
+ (NSString *)generateDashboardURLWithProjectID:(NSString *)projectID bundleID:(NSString *)bundleID;
28+
29+
/**
30+
* Generates the console URL for the custom trace page.
31+
*
32+
* @param projectID The Firebase project ID.
33+
* @param bundleID The bundle ID of this project.
34+
* @return The console URL for the custom trace page.
35+
*/
36+
+ (NSString *)generateCustomTraceURLWithProjectID:(NSString *)projectID
37+
bundleID:(NSString *)bundleID
38+
traceName:(NSString *)traceName;
39+
40+
/**
41+
* Generates the console URL for the screen trace page.
42+
*
43+
* @param projectID The Firebase project ID.
44+
* @param bundleID The bundle ID of this project.
45+
* @return The console URL for the custom trace page.
46+
*/
47+
+ (NSString *)generateScreenTraceURLWithProjectID:(NSString *)projectID
48+
bundleID:(NSString *)bundleID
49+
traceName:(NSString *)traceName;
50+
51+
@end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#import "FirebasePerformance/Sources/Common/FPRConsoleURLGenerator.h"
16+
17+
NSString *const URL_BASE_PATH = @"https://console.firebase.google.com";
18+
NSString *const UTM_MEDIUM = @"ios-ide";
19+
NSString *const UTM_SOURCE = @"perf-ios-sdk";
20+
21+
@implementation FPRConsoleURLGenerator
22+
23+
/** This is a class method to generate the console URL for the project's dashboard page.*/
24+
+ (NSString *)generateDashboardURLWithProjectID:(NSString *)projectID
25+
bundleID:(NSString *)bundleID {
26+
NSString *rootUrl = [FPRConsoleURLGenerator getRootURLWithProjectID:projectID bundleID:bundleID];
27+
return [NSString
28+
stringWithFormat:@"%@/trends?utm_source=%@&utm_medium=%@", rootUrl, UTM_SOURCE, UTM_MEDIUM];
29+
}
30+
31+
/** This is a class method to generate the console URL for the custom trace.*/
32+
+ (NSString *)generateCustomTraceURLWithProjectID:(NSString *)projectID
33+
bundleID:(NSString *)bundleID
34+
traceName:(NSString *)traceName {
35+
NSString *rootUrl = [FPRConsoleURLGenerator getRootURLWithProjectID:projectID bundleID:bundleID];
36+
return [NSString stringWithFormat:@"%@/metrics/trace/"
37+
@"DURATION_TRACE/%@?utm_source=%@&utm_medium=%@",
38+
rootUrl, traceName, UTM_SOURCE, UTM_MEDIUM];
39+
}
40+
41+
/** This is a class method to generate the console URL for the screen trace.*/
42+
+ (NSString *)generateScreenTraceURLWithProjectID:(NSString *)projectID
43+
bundleID:(NSString *)bundleID
44+
traceName:(NSString *)traceName {
45+
NSString *rootUrl = [FPRConsoleURLGenerator getRootURLWithProjectID:projectID bundleID:bundleID];
46+
return [NSString stringWithFormat:@"%@/metrics/trace/"
47+
@"SCREEN_TRACE/%@?utm_source=%@&utm_medium=%@",
48+
rootUrl, traceName, UTM_SOURCE, UTM_MEDIUM];
49+
}
50+
51+
/** This is a class method to get the root URL for the console .*/
52+
+ (NSString *)getRootURLWithProjectID:(NSString *)projectID bundleID:(NSString *)bundleID {
53+
return [NSString
54+
stringWithFormat:@"%@/project/%@/performance/app/ios:%@", URL_BASE_PATH, projectID, bundleID];
55+
}
56+
@end

FirebasePerformance/Sources/FPRClient+Private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
/** Firebase Installations object for FPRClient. */
4343
@property(nonatomic) FIRInstallations *installations;
4444

45+
/** The Firebase Project ID of the project. */
46+
@property(nonatomic, readonly) NSString *projectID;
47+
48+
/** The bundle ID of the project*/
49+
@property(nonatomic, readonly) NSString *bundleID;
4550
/**
4651
* Determines the log directory path in the caches directory.
4752
*

FirebasePerformance/Sources/FPRClient.m

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#import "FirebasePerformance/Sources/FPRClient+Private.h"
1717

1818
#import "FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h"
19+
#import "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker+Private.h"
1920
#import "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker.h"
2021
#import "FirebasePerformance/Sources/AppActivity/FPRSessionManager+Private.h"
2122
#import "FirebasePerformance/Sources/AppActivity/FPRTraceBackgroundActivityTracker.h"
23+
#import "FirebasePerformance/Sources/Common/FPRConsoleURLGenerator.h"
2224
#import "FirebasePerformance/Sources/Common/FPRConstants.h"
2325
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
2426
#import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"
@@ -29,6 +31,8 @@
2931
#import "FirebasePerformance/Sources/Timer/FIRTrace+Internal.h"
3032
#import "FirebasePerformance/Sources/Timer/FIRTrace+Private.h"
3133

34+
#import "FirebasePerformance/Sources/Public/FIRPerformance.h"
35+
3236
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
3337

3438
#import "FirebasePerformance/ProtoSupport/PerfMetric.pbobjc.h"
@@ -107,6 +111,8 @@ - (instancetype)init {
107111
_eventsQueue = dispatch_queue_create("com.google.perf.FPREventsQueue", DISPATCH_QUEUE_SERIAL);
108112
_eventsQueueGroup = dispatch_group_create();
109113
_configuration = [FPRConfigurations sharedInstance];
114+
_projectID = [FIROptions defaultOptions].projectID;
115+
_bundleID = [FIROptions defaultOptions].bundleID;
110116
}
111117
return self;
112118
}
@@ -135,6 +141,15 @@ - (BOOL)startWithConfiguration:(FPRConfiguration *)config error:(NSError *__auto
135141

136142
self.configured = YES;
137143

144+
static dispatch_once_t onceToken;
145+
dispatch_once(&onceToken, ^{
146+
FPRLogInfo(kFPRClientInitialize,
147+
@"Firebase Performance Monitoring is successfully initialized! In a minute, visit "
148+
@"the Firebase console to view your data: %@",
149+
[FPRConsoleURLGenerator generateDashboardURLWithProjectID:self.projectID
150+
bundleID:self.bundleID]);
151+
});
152+
138153
return YES;
139154
}
140155

@@ -161,8 +176,25 @@ - (void)logTrace:(FIRTrace *)trace {
161176
metric.traceMetric = FPRGetTraceMetric(trace);
162177
metric.applicationInfo.applicationProcessState =
163178
FPRApplicationProcessState(trace.backgroundTraceState);
164-
FPRLogDebug(kFPRClientMetricLogged, @"Logging trace metric - %@ %.4fms",
165-
metric.traceMetric.name, metric.traceMetric.durationUs / 1000.0);
179+
180+
// Log the trace metric with its console URL.
181+
if ([trace.name hasPrefix:kFPRPrefixForScreenTraceName]) {
182+
FPRLogDebug(kFPRClientMetricLogged,
183+
@"Logging trace metric - %@ %.4fms. In a minute, visit the Firebase console to "
184+
@"view your data: %@",
185+
metric.traceMetric.name, metric.traceMetric.durationUs / 1000.0,
186+
[FPRConsoleURLGenerator generateScreenTraceURLWithProjectID:self.projectID
187+
bundleID:self.bundleID
188+
traceName:trace.name]);
189+
} else {
190+
FPRLogDebug(kFPRClientMetricLogged,
191+
@"Logging trace metric - %@ %.4fms. In a minute, visit the Firebase console to "
192+
@"view your data: %@",
193+
metric.traceMetric.name, metric.traceMetric.durationUs / 1000.0,
194+
[FPRConsoleURLGenerator generateCustomTraceURLWithProjectID:self.projectID
195+
bundleID:self.bundleID
196+
traceName:trace.name]);
197+
}
166198
[self processAndLogEvent:metric];
167199
});
168200
} else {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#import <XCTest/XCTest.h>
16+
17+
#import "FirebasePerformance/Sources/Common/FPRConsoleURLGenerator.h"
18+
19+
@interface FPRConsoleURLGeneratorTest : XCTestCase
20+
21+
@end
22+
23+
@implementation FPRConsoleURLGeneratorTest
24+
25+
static NSString *const PROJECT_ID = @"test-project";
26+
static NSString *const BUNDLE_ID = @"test-bundle";
27+
static NSString *const TRACE_NAME = @"test-trace";
28+
29+
/** Tests that the dashboard URL is correctly generated. */
30+
- (void)testDashboardURL {
31+
NSString *url = [FPRConsoleURLGenerator generateDashboardURLWithProjectID:PROJECT_ID
32+
bundleID:BUNDLE_ID];
33+
NSString *expectedURL = @"https://console.firebase.google.com/project/test-project/performance/"
34+
@"app/ios:test-bundle/trends?utm_source=perf-ios-sdk&utm_medium=ios-ide";
35+
XCTAssertEqualObjects(url, expectedURL);
36+
}
37+
38+
/** Tests that the custom trace URL is correctly generated. */
39+
- (void)testCustomTraceURL {
40+
NSString *url = [FPRConsoleURLGenerator generateCustomTraceURLWithProjectID:PROJECT_ID
41+
bundleID:BUNDLE_ID
42+
traceName:TRACE_NAME];
43+
NSString *expectedURL =
44+
@"https://console.firebase.google.com/project/test-project/performance/app/ios:test-bundle/"
45+
@"metrics/trace/DURATION_TRACE/test-trace?utm_source=perf-ios-sdk&utm_medium=ios-ide";
46+
XCTAssertEqualObjects(url, expectedURL);
47+
}
48+
49+
/** Tests that the screen trace URL is correctly generated. */
50+
- (void)testScreenTraceURL {
51+
NSString *url = [FPRConsoleURLGenerator generateScreenTraceURLWithProjectID:PROJECT_ID
52+
bundleID:BUNDLE_ID
53+
traceName:TRACE_NAME];
54+
NSString *expectedURL =
55+
@"https://console.firebase.google.com/project/test-project/performance/app/ios:test-bundle/"
56+
@"metrics/trace/SCREEN_TRACE/test-trace?utm_source=perf-ios-sdk&utm_medium=ios-ide";
57+
XCTAssertEqualObjects(url, expectedURL);
58+
}
59+
60+
@end

0 commit comments

Comments
 (0)