-
Notifications
You must be signed in to change notification settings - Fork 212
@W-18760780 Integrate opentelemetry into performance.js #2722
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
Changes from 20 commits
20eb9b4
7b349b6
07b1206
3326746
051ea73
f801b5b
ce666ec
ef27e9c
02cbb52
bb36629
1e905cf
0dd809d
1e586d9
48ff1b9
299039c
dfb8812
20b8c96
1d9a905
fc1f8f5
7171b8f
943a40c
4072966
6c5430d
24b37e0
6c301c5
5a0f754
e8dc896
894549b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |||||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||||||
| */ | ||||||
| import logger from './logger-instance' | ||||||
| import {createChildSpan, endSpan, logPerformanceMetric} from './opentelemetry' | ||||||
|
|
||||||
| export const PERFORMANCE_MARKS = { | ||||||
| total: 'ssr.total', | ||||||
| renderToString: 'ssr.render-to-string', | ||||||
|
|
@@ -32,11 +34,10 @@ export default class PerformanceTimer { | |||||
| } | ||||||
| constructor(options = {}) { | ||||||
| this.enabled = options.enabled || false | ||||||
| this.marks = { | ||||||
| start: new Map(), | ||||||
| end: new Map() | ||||||
| } | ||||||
| this.metrics = [] | ||||||
| this.spans = new Map() | ||||||
| this.spanTimeouts = new Map() | ||||||
| this.maxSpanDuration = options.maxSpanDuration || 30000 // 30 seconds default | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -61,15 +62,13 @@ export default class PerformanceTimer { | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * A utility function to format and log the performance metrics. | ||||||
| * | ||||||
| * @function | ||||||
| * @private | ||||||
| * Logs all performance metrics | ||||||
| */ | ||||||
| log() { | ||||||
| // Log each metric once with the standardized format | ||||||
| this.metrics.forEach((metric) => { | ||||||
| logger.info(`${metric.name} - ${metric.duration}ms ${metric.detail || ''}`, { | ||||||
| namespace: 'performance' | ||||||
| logPerformanceMetric(metric.name, metric.duration, { | ||||||
| 'performance.detail': metric.detail || '' | ||||||
| }) | ||||||
| }) | ||||||
| } | ||||||
|
|
@@ -78,50 +77,151 @@ export default class PerformanceTimer { | |||||
| * This is a utility function to create performance marks. | ||||||
| * The data will be used in console logs and the http response header `server-timing`. | ||||||
| * | ||||||
| * @function | ||||||
| * @private | ||||||
| * @param {string} name - Unique identifier for the performance measurement. | ||||||
| * Must be the same for both start and end marks of a pair. E.g. 'ssr.render-to-string' | ||||||
| * | ||||||
| * @param {string} type - Mark type, either 'start' or 'end'. 'start' creates spans and browser marks, | ||||||
| * 'end' completes measurement and cleanup. | ||||||
| * | ||||||
| * @param {Object} [options={}] - Optional configuration object | ||||||
| * @param {string|Object} [options.detail=''] - Additional metadata for the mark | ||||||
| * included in logs and tracing attributes. | ||||||
| */ | ||||||
| mark(name, type, options = {}) { | ||||||
| if (!this.enabled) { | ||||||
| const {detail = ''} = options | ||||||
| if (!name || !type || !this.enabled) { | ||||||
|
||||||
| if (!name || !type || !this.enabled) { | |
| if (!this.enabled || !name || !type) { |
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.
Should we log a warning in case we attempt to create a duplicate span name?
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.
Should we also call cleanup in case of catching an error?
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.
The timed out automatic cleanup made for each span on creation would clean them up eventually. Even when endSpan logs an error within itself.
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.
Following the steps to test the changes I see in the logs we have a few "No parent span found" warnings and it looks like each span is using a different
traceIdinstead of all spans sharing the same traceId.Are we missing wrapping the render function with a root span? Is this something we plan to do in a separated ticket?
https://github.com/SalesforceCommerceCloud/pwa-kit/blob/W-18129479-spike-o11y/packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.js#L136
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.
Yeah that will be done in this ticket: https://gus.lightning.force.com/lightning/_classic/%2Fa07EE00002G04HYYAZ