-
Notifications
You must be signed in to change notification settings - Fork 15
LLMO-1023: add trace ID propagation for SQS messages and HTTP headers #1097
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5b9a450
feat(LLMO-1023): add trace ID support to log wrapper
HollywoodTonight 41dcdf4
feat: add trace ID propagation for SQS messages and HTTP headers
HollywoodTonight 5ab92c6
Merge branch 'main' into LLMO-1023-atudoran
HollywoodTonight f870b34
fix: resolve linting errors - trailing spaces and line length
HollywoodTonight d54af4e
fix: remove trailing spaces in enrich-path-info-wrapper.js
HollywoodTonight 11c8f7b
test: add comprehensive tests for trace ID propagation features
HollywoodTonight 7f37b6f
test: fix SQS traceId tests to set AWS_EXECUTION_ENV
HollywoodTonight 99a6077
fix: resolve variable shadowing in SQS tests
HollywoodTonight 23172f2
fix: remove extra blank lines at end of test file
HollywoodTonight a99af94
test: add coverage for X-Ray auto-add traceId and silence X-Ray warnings
HollywoodTonight 39927cd
Merge branch 'main' into LLMO-1023-atudoran
HollywoodTonight bd29d7f
Merge branch 'main' into LLMO-1023-atudoran
HollywoodTonight df777e6
Merge branch 'main' into LLMO-1023-atudoran
HollywoodTonight cad0607
feat: add Jobs Dispatcher opt-out for trace propagation
HollywoodTonight 2685cf3
fix: remove trailing spaces in JSDoc comments
HollywoodTonight ec85750
feat(LLMO-1023): enhance context.log directly for automatic trace ID …
HollywoodTonight 5c9d66e
fix: remove padded blank line in log-wrapper test
HollywoodTonight 3e645b5
Merge remote-tracking branch 'origin/main' into LLMO-1023-atudoran
HollywoodTonight fa7a984
Merge branch 'main' into LLMO-1023-atudoran
HollywoodTonight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
packages/spacecat-shared-http-utils/test/enrich-path-info-wrapper.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * Copyright 2025 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| /* eslint-env mocha */ | ||
| import { expect } from 'chai'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| import { enrichPathInfo } from '../src/enrich-path-info-wrapper.js'; | ||
|
|
||
| describe('enrichPathInfo', () => { | ||
| let mockRequest; | ||
| let mockContext; | ||
| let mockFn; | ||
|
|
||
| beforeEach(() => { | ||
| mockFn = sinon.stub().resolves({ status: 200 }); | ||
|
|
||
| mockRequest = { | ||
| method: 'POST', | ||
| headers: { | ||
| plain: () => ({ | ||
| 'content-type': 'application/json', | ||
| 'user-agent': 'test-agent', | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| mockContext = { | ||
| pathInfo: { | ||
| suffix: '/api/test', | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| it('should enrich context with pathInfo including method, headers, and route', async () => { | ||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.pathInfo).to.deep.include({ | ||
| method: 'POST', | ||
| route: 'api', | ||
| }); | ||
| expect(mockContext.pathInfo.headers).to.deep.equal({ | ||
| 'content-type': 'application/json', | ||
| 'user-agent': 'test-agent', | ||
| }); | ||
| }); | ||
|
|
||
| it('should extract traceId from x-trace-id header and store in context', async () => { | ||
| mockRequest.headers.plain = () => ({ | ||
| 'content-type': 'application/json', | ||
| 'x-trace-id': '1-5e8e8e8e-5e8e8e8e5e8e8e8e5e8e8e8e', | ||
| }); | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.traceId).to.equal('1-5e8e8e8e-5e8e8e8e5e8e8e8e5e8e8e8e'); | ||
| }); | ||
|
|
||
| it('should not set traceId in context when x-trace-id header is missing', async () => { | ||
| mockRequest.headers.plain = () => ({ | ||
| 'content-type': 'application/json', | ||
| }); | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.traceId).to.be.undefined; | ||
| }); | ||
|
|
||
| it('should handle case-sensitive x-trace-id header', async () => { | ||
| mockRequest.headers.plain = () => ({ | ||
| 'content-type': 'application/json', | ||
| 'X-Trace-Id': '1-different-case', | ||
| }); | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| // Header keys should be lowercase | ||
| expect(mockContext.traceId).to.be.undefined; | ||
| }); | ||
|
|
||
| it('should call the wrapped function with request and context', async () => { | ||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockFn.calledOnce).to.be.true; | ||
| expect(mockFn.firstCall.args[0]).to.equal(mockRequest); | ||
| expect(mockFn.firstCall.args[1]).to.equal(mockContext); | ||
| }); | ||
|
|
||
| it('should return the result from the wrapped function', async () => { | ||
| mockFn.resolves({ status: 201, body: 'created' }); | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| const result = await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(result).to.deep.equal({ status: 201, body: 'created' }); | ||
| }); | ||
|
|
||
| it('should handle empty pathInfo suffix', async () => { | ||
| mockContext.pathInfo.suffix = ''; | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.pathInfo.route).to.be.undefined; | ||
| }); | ||
|
|
||
| it('should handle missing pathInfo suffix', async () => { | ||
| mockContext.pathInfo = {}; | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.pathInfo.route).to.be.undefined; | ||
| }); | ||
|
|
||
| it('should convert method to uppercase', async () => { | ||
| mockRequest.method = 'get'; | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.pathInfo.method).to.equal('GET'); | ||
| }); | ||
|
|
||
| it('should handle complex route extraction', async () => { | ||
| mockContext.pathInfo.suffix = '/api/v1/users/123'; | ||
|
|
||
| const wrapper = enrichPathInfo(mockFn); | ||
| await wrapper(mockRequest, mockContext); | ||
|
|
||
| expect(mockContext.pathInfo.route).to.equal('api'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.