Skip to content

Commit 518dd73

Browse files
authored
fix trace context pattern and delete trace id.
1 parent a40b32a commit 518dd73

File tree

6 files changed

+1
-16
lines changed

6 files changed

+1
-16
lines changed

src/async_local_storage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {AsyncLocalStorage} from 'node:async_hooks';
66

77
export interface ExecutionContext {
88
executionId?: string;
9-
traceId?: string;
109
spanId?: string;
1110
}
1211

@@ -32,7 +31,6 @@ export async function asyncLocalStorageMiddleware(
3231
asyncLocalStorage.run(
3332
{
3433
executionId: req.executionId,
35-
traceId: req.traceId,
3634
spanId: req.spanId,
3735
},
3836
() => {

src/execution_context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const FUNCTION_EXECUTION_ID_HEADER_KEY = 'function-execution-id';
55
const TRACE_CONTEXT_HEADER_KEY = 'X-Cloud-Trace-Context';
66

77
const TRACE_CONTEXT_PATTERN =
8-
/^(?<traceId>\w+)\/(?<spanId>\d+);o=(?<options>.+)$/;
8+
/^(?<traceId>\w+)\/(?<spanId>\d+)(?:;o=(?<options>.+))?$/;
99

1010
function generateExecutionId() {
1111
const timestampPart = Date.now().toString(36).slice(-6);
@@ -29,7 +29,6 @@ export const executionContextMiddleware = (
2929
const match = cloudTraceContext.match(TRACE_CONTEXT_PATTERN);
3030
if (match?.groups) {
3131
const {traceId, spanId} = match.groups;
32-
req.traceId = traceId;
3332
req.spanId = spanId;
3433
}
3534
}

src/logger.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {getCurrentContext, ExecutionContext} from './async_local_storage';
1818
import {Buffer} from 'buffer';
1919

2020
export const EXECUTION_CONTEXT_LABELS_KEY = 'logging.googleapis.com/labels';
21-
export const EXECUTION_CONTEXT_TRACE_KEY = 'logging.googleapis.com/trace';
2221
export const EXECUTION_CONTEXT_SPAN_ID_KEY = 'logging.googleapis.com/spanId';
2322
const SEVERITY = 'severity';
2423

@@ -132,7 +131,6 @@ export function getModifiedData(
132131
let dataWithContext: {
133132
message: string | Uint8Array;
134133
'logging.googleapis.com/labels': {execution_id: string | undefined};
135-
'logging.googleapis.com/trace': string | undefined;
136134
'logging.googleapis.com/spanId': string | undefined;
137135
severity?: string | undefined;
138136
};
@@ -155,7 +153,6 @@ function getTextWithContext(
155153
return {
156154
message: data,
157155
[EXECUTION_CONTEXT_LABELS_KEY]: {execution_id: context.executionId},
158-
[EXECUTION_CONTEXT_TRACE_KEY]: context.traceId,
159156
[EXECUTION_CONTEXT_SPAN_ID_KEY]: context.spanId,
160157
};
161158
}
@@ -169,7 +166,6 @@ function getJSONWithContext(json: any, context: ExecutionContext) {
169166
}
170167
return {
171168
...json,
172-
[EXECUTION_CONTEXT_TRACE_KEY]: context.traceId,
173169
[EXECUTION_CONTEXT_SPAN_ID_KEY]: context.spanId,
174170
};
175171
}

test/async_local_storage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe('asyncLocalStorageMiddleware', () => {
1515
const req = {
1616
body: 'test body',
1717
executionId: 'testExecutionId',
18-
traceId: 'testtrace',
1918
spanId: 'testSpanId',
2019
};
2120
let executionContext;
@@ -25,7 +24,6 @@ describe('asyncLocalStorageMiddleware', () => {
2524
assert(executionContext);
2625
assert.strictEqual(executionContext.executionId, req.executionId);
2726
assert.strictEqual(executionContext.spanId, req.spanId);
28-
assert.strictEqual(executionContext.traceId, req.traceId);
2927
};
3028

3129
await asyncLocalStorageMiddleware(

test/execution_context.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('executionContextMiddleware', () => {
3131

3232
assert.strictEqual(req.executionId, validExecutionId);
3333
assert.strictEqual(req.spanId, testSpanId);
34-
assert.strictEqual(req.traceId, testTrace);
3534
});
3635

3736
it('generates execution ID if not in header', () => {
@@ -41,7 +40,6 @@ describe('executionContextMiddleware', () => {
4140

4241
assert(req.executionId);
4342
assert.strictEqual(req.spanId, testSpanId);
44-
assert.strictEqual(req.traceId, testTrace);
4543
});
4644

4745
it('req trace undefined if not in header', () => {
@@ -51,6 +49,5 @@ describe('executionContextMiddleware', () => {
5149

5250
assert(req.executionId);
5351
assert.strictEqual(req.spanId, undefined);
54-
assert.strictEqual(req.traceId, undefined);
5552
});
5653
});

test/logger.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ describe('getModifiedData', () => {
4747
const sampleUint8Arr = new Uint8Array(Buffer.from(sampleText));
4848
const expectedExecutionContext = {
4949
executionId: 'testExecutionId',
50-
traceId: 'testTraceId',
5150
spanId: 'testSpanId',
5251
};
5352
const expectedMetadata = {
5453
'logging.googleapis.com/labels': {
5554
execution_id: 'testExecutionId',
5655
},
57-
'logging.googleapis.com/trace': 'testTraceId',
5856
'logging.googleapis.com/spanId': 'testSpanId',
5957
};
6058
const expectedTextOutput =
@@ -102,7 +100,6 @@ describe('getModifiedData', () => {
102100
user_label_1: 'value_1',
103101
execution_id: 'testExecutionId',
104102
},
105-
'logging.googleapis.com/trace': 'testTraceId',
106103
'logging.googleapis.com/spanId': 'testSpanId',
107104
}) + '\n';
108105
const modifiedData = getModifiedData(data);

0 commit comments

Comments
 (0)