Skip to content
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

fix(fastly) provide service version and other contextual information #608

Closed
wants to merge 8 commits into from

Conversation

bosschaert
Copy link
Collaborator

Description

Provide additional contextual details in the context parameter passed to the main function for services running in Fastly Compute@Edge.

The following fields (which were previously null) are now set:

  • context.func.name: the service ID
  • context.func.fqn: A globally unique function identifier which includes the service ID and version
  • context.func.version: the fastly service version - typically a whole number that automatically increases with every deploy
  • context.invocation.requestId: An ID uniquely associated with the current request
  • context.invocation.transactionId: The x-transaction-id header from the request or otherwise a unique ID associated with the current request.
  • context.runtime.region: The region as 3-letter point-of-present code where the service is executed, see here for codes: https://developer.fastly.com/learning/concepts/pop

Usage example:

module.exports.main = async function main(req, context) {
  return new Response(`Executed in version: ${context?.func?.version}
      Region: ${context?.runtime?.region}
      Func Name: ${context?.func?.name}
      Func FQN: ${context?.func?.fqn}
      TxID: ${context?.invocation?.transactionId}
      ReqID: ${context?.invocation?.requestId}`);
}

Related Issue

Fixes: #598

Motivation and Context

It allows to determine with certainty what version of the function is being invoked (sometimes an update can take a while) and provides additional information which can be useful for tracing and debugging.

How Has This Been Tested?

A new unit test has been added: fastly-adapter.test.js.

Types of changes

As the fields for this information were there but not filled in I consider this a bug fix.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Moveid to ES-style import (instead of require) to keep Mocha happy for the
unit tests.
@bosschaert bosschaert marked this pull request as draft October 26, 2023 14:53
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #608 (d9b5f78) into main (63991db) will decrease coverage by 1.26%.
Report is 5 commits behind head on main.
The diff coverage is 15.78%.

@@            Coverage Diff             @@
##             main     #608      +/-   ##
==========================================
- Coverage   73.83%   72.57%   -1.26%     
==========================================
  Files          24       25       +1     
  Lines        5751     5878     +127     
  Branches        1        1              
==========================================
+ Hits         4246     4266      +20     
- Misses       1505     1612     +107     
Files Coverage Δ
src/bundler/EdgeBundler.js 92.12% <100.00%> (+0.06%) ⬆️
src/deploy/ComputeAtEdgeDeployer.js 97.95% <100.00%> (ø)
src/template/fastly-adapter.js 15.07% <11.11%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

This PR will trigger no release when merged.

@bosschaert bosschaert closed this Oct 27, 2023
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.

[c@e] Report currently running service version in context
1 participant