Skip to content

docs(batch): add section on how to trace batch processing #1673

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 2 commits into from
Sep 13, 2023

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

This PR introduces a new section to the Batch Processing docs that details how to create dedicated subsegments for each record processed in a batch. I decided to include a dedicated section since the operation might not immediately be straightforward due to the presence of an iteration.

// ... imports omitted for brevity see docs/snippets/batch/advancedTracingRecordHandler.ts for full snippet

const processor = new BatchProcessor(EventType.SQS);
const tracer = new Tracer({ serviceName: 'serverlessAirline' });

const recordHandler = (record: SQSRecord): void => {
  const subsegment = tracer.getSegment()?.addNewSubsegment('### recordHandler'); 
  subsegment?.addAnnotation('messageId', record.messageId); 

  const payload = record.body;
  if (payload) {
    try {
      const item = JSON.parse(payload);
      // do something with the item
      subsegment?.addMetadata('item', item);
    } catch (error) {
      subsegment?.addError(error);
      throw error;
    }
  }

  subsegment?.close(); 
};

export const handler = middy(
  async (event: SQSEvent, context: Context): Promise<SQSBatchResponse> => {
    return processPartialResponse(event, recordHandler, processor, {
      context,
    });
  }
).use(captureLambdaHandler(tracer));

Additionally, the PR also addresses a two housekeeping items related to documentation:

  • Fix warnings related to relative links during docs build (example)
  • Restore original menu/nav positioning to align with Python

Related issues, RFCs

Issue number: #471

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi requested a review from a team September 13, 2023 10:57
@dreamorosi dreamorosi self-assigned this Sep 13, 2023
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Sep 13, 2023
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Sep 13, 2023
@dreamorosi dreamorosi requested a review from am29d September 13, 2023 10:57
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dreamorosi dreamorosi merged commit e1a3452 into main Sep 13, 2023
@dreamorosi dreamorosi deleted the 471-docs-tracing-batches branch September 13, 2023 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation size/L PRs between 100-499 LOC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: correctly create segments for parallel processing (i.e. Promise.all[])
2 participants