Skip to content

Conversation

@HollywoodTonight
Copy link
Contributor

Overview

Integrates logWrapper to enable automatic trace ID logging in the SpaceCat API Service, supporting end-to-end distributed tracing across all SpaceCat services.

Changes

1. Add logWrapper Integration

  • Import logWrapper from @adobe/spacecat-shared-utils
  • Add logWrapper to the wrapper chain after enrichPathInfo
  • Logs will now automatically include trace IDs from:
    • AWS X-Ray trace context
    • HTTP x-trace-id request headers

2. Version Updates

  • Bump @adobe/spacecat-shared-utils to ^1.76.0

How It Works

The API service now captures trace IDs from incoming HTTP requests:

  1. Incoming requests with x-trace-id header → trace ID is extracted by enrichPathInfo and stored in context.traceId
  2. logWrapper automatically includes the trace ID in all log messages
  3. Outgoing SQS messages (via sqs wrapper) automatically propagate the trace ID
  4. If no x-trace-id header is present, AWS X-Ray trace ID is used automatically

Benefits

✅ Complete visibility into request flows across services
✅ Correlation of logs across HTTP → API → Worker chains
✅ Easier debugging of distributed workflows
✅ No code changes needed in controllers - automatic propagation

Testing

  • Existing tests pass without modification
  • Trace IDs are automatically included in logs when present
  • No breaking changes to existing functionality

Related

API Enhancements:
- Add sortBy and sortOrder query parameters to all listing endpoints
- Support sorting by: rank, traffic, url, createdAt, updatedAt
- Add rank and traffic fields to add/update operations
- Update OpenAPI documentation with new parameters and fields

Performance Improvements:
- Refactor bulk operations to use Promise.allSettled for parallel processing
- Replace sequential for-loops with parallel map operations
- Improve response time for bulk add/update/delete operations

Code Quality:
- Fix all 15 pre-existing linting errors
- Remove unused encodeUrlToBase64 function
- Eliminate no-continue statements (7 instances)
- Eliminate no-await-in-loop violations (7 instances)
- Fix trailing spaces and OpenAPI YAML syntax errors
- All linting now passing (0 errors)
- Resolved conflicts in src/index.js and src/routes/index.js
- Kept both URL Store Controller and PTA2 Controller features
Add REST API endpoints to manage and query offsite brand presence URLs
(Wikipedia, YouTube, social media, etc.) alongside primary site URLs.

New Endpoints:
- GET /sites/{siteId}/url-store/by-platform/{platformType}
  Query URLs by specific platform type with sorting/pagination
- GET /sites/{siteId}/url-store/offsite
  Get all offsite URLs with sorting/pagination

Controller Changes:
- Add listUrlsByPlatform() endpoint handler
- Add listOffsiteUrls() endpoint handler
- Update addUrls() to accept and validate platformType
- Update updateUrls() to accept and validate platformType
- Import PLATFORM_TYPES from data access layer

OpenAPI Documentation:
- Document new endpoints with full specifications
- Add platformType field to all URL schemas
- Include sorting parameters (rank, traffic, etc.)
- Add platform type enum validation

Testing:
- Add 13 comprehensive controller tests
- Test platform type validation
- Test sorting and pagination
- Test default value behavior

All endpoints support sorting by rank, traffic, url, createdAt, updatedAt
with asc/desc ordering and cursor-based pagination.

Note: OpenAPI validation warnings for nullable fields are pre-existing
and tracked separately.
@iuliag
Copy link
Contributor

iuliag commented Nov 20, 2025

The changes are a mix of URL store implementation and the trace id one.

@github-actions
Copy link

This PR will trigger a minor release when merged.

@HollywoodTonight HollywoodTonight deleted the LLMO-1023-trace-id branch November 21, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants