Skip to content

Commit

Permalink
refactor(performance): rename property
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Dec 16, 2024
1 parent cabf5ac commit 5f65c61
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions packages/performance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,66 @@ const isEnabled = async () => {
const result = await FirebasePerformance.isEnabled();
return result.enabled;
};

const putAttribute = async () => {
await FirebasePerformance.putAttribute({
traceName: 'test_trace',
attribute: 'user_id',
value: '123',
});
};

const getAttribute = async () => {
const result = await FirebasePerformance.getAttribute({
traceName: 'test_trace',
attribute: 'user_id',
});
return result.attributes;
};

const getAttributes = async () => {
const result = await FirebasePerformance.getAttributes({ traceName: 'test_trace' });
return result.attributes;
};

const removeAttribute = async () => {
await FirebasePerformance.removeAttribute({
traceName: 'test_trace',
attribute: 'user_id',
});
};

const putMetric = async () => {
await FirebasePerformance.putMetric({
traceName: 'test_trace',
metricName: 'item_cache_hit',
num: 1,
});
};

const getMetric = async () => {
const result = await FirebasePerformance.getMetric({
traceName: 'test_trace',
metricName: 'item_cache_hit',
});
return result.value;
};

const record = async () => {
await FirebasePerformance.record({
traceName: 'test_trace',
startTime: Date.now(),
duration: 1000,
options: {
metrics: {
item_cache_hit: 1,
},
attributes: {
user_id: '123',
},
},
});
};
```

## API
Expand Down
2 changes: 1 addition & 1 deletion packages/performance/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export interface GetAttributesResult {
*
* @since 6.3.0
*/
result: { [key: string]: string };
attributes: { [key: string]: string };
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/performance/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export class FirebasePerformanceWeb
}: GetAttributesOptions): Promise<GetAttributesResult> {
const trace = this.traces[traceName];
if (!trace) {
return { result: {} };
return { attributes: {} };
}
return { result: trace.getAttributes() };
return { attributes: trace.getAttributes() };
}

public async removeAttribute({
Expand Down

0 comments on commit 5f65c61

Please sign in to comment.