Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 04f7649

Browse files
danielkhanjustindsmith
authored andcommitted
refactor(perf): Use one long random buffer and slice them [propagation-tracecontext] (#198)
1 parent 526023e commit 04f7649

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/opencensus-propagation-tracecontext/src/tracecontext-format.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ export class TraceContextFormat implements Propagation {
132132
* Context parts are based on section 2.2.2 of TraceContext spec.
133133
*/
134134
generate(): SpanContext {
135+
const buff = crypto.randomBytes(24).toString('hex');
135136
return {
136-
traceId: crypto.randomBytes(16).toString('hex'),
137-
spanId: crypto.randomBytes(8).toString('hex'),
137+
traceId: buff.slice(0, 32),
138+
spanId: buff.slice(32, 48),
138139
options: DEFAULT_OPTIONS,
139140
traceState: undefined
140141
};

0 commit comments

Comments
 (0)