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: activity id to chain id quote injector and lambda handler event #622

Merged

Conversation

jsy1218
Copy link
Member

@jsy1218 jsy1218 commented Apr 22, 2024

During container injector, we instantiate a new global logger with injector-sor, without request id, or any identifier that can identifier which request it's part of:

    const log: Logger = bunyan.createLogger({
      name: this.injectorName,
      serializers: bunyan.stdSerializers,
      level: bunyan.INFO,
    })
    setGlobalLogger(log)

The reason for this is because, buildContainerInjected() is called as part of QuoteHandlerInjector('quoteInjector').build(), but we only start to get the request id from the lambda event within new QuoteHandler('quote', quoteInjectorPromise)
, within injector:

  public async getRequestInjected(
    containerInjected: ContainerInjected,
    _requestBody: void,
    requestQueryParams: QuoteQueryParams,
    _event: APIGatewayProxyEvent,
    context: Context,
    log: Logger,
    metricsLogger: MetricsLogger
  ): Promise<RequestInjected<IRouter<AlphaRouterConfig | LegacyRoutingConfig>>> {
    const requestId = context.awsRequestId
  ...

log = log.child({
      serializers: bunyan.stdSerializers,
      level: logLevel,
      requestId,
      quoteId,
      tokenInAddress,
      chainId: tokenInChainId,
      tokenOutAddress,
      amount,
      type,
      algorithm,
      gasToken,
    })
    setGlobalLogger(log)
}

So this means we need to manually generate a new random identifier within injector-sor activityId, and pass into injector, so that we have the way to identify which request is this container injection from. In addition, because not every request needs the container injection, the activity id has to be optional. I verified in my local and can now see activityId popping up and tieing up the loggings within the same request:

Screenshot 2024-04-22 at 4 55 27 PM
Screenshot 2024-04-22 at 4 55 35 PM

I also tested non-cold start scenario, and can see there's no activity id, only request id:

Screenshot 2024-04-22 at 5.04.40 PM.png

@jsy1218 jsy1218 self-assigned this Apr 22, 2024
Copy link
Member Author

jsy1218 commented Apr 23, 2024

Merge activity

  • Apr 22, 8:06 PM EDT: @jsy1218 started a stack merge that includes this pull request via Graphite.
  • Apr 22, 8:07 PM EDT: @jsy1218 merged this pull request with Graphite.

@jsy1218 jsy1218 merged commit a17a698 into main Apr 23, 2024
5 checks passed
@jsy1218 jsy1218 deleted the jsy1218/chain-container-injected-logging-with-custom-activity-id branch April 23, 2024 00:07
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.

2 participants