Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Inject appsync trace
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhan721 committed Nov 25, 2021
1 parent 36d1615 commit de17311
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ exports.handler = thundra((event, context) => {
});
```

### NOTES

- In order to activate *AWS Step Functions* trace, `THUNDRA_AGENT_LAMBDA_AWS_STEPFUNCTIONS` environment variable should be set `true`.
- In order to activate *AWS AppSync* trace, `THUNDRA_AGENT_LAMBDA_AWS_APPSYNC` environment variable should be set `true`.
- For other integrations' configuration, please take a look environment variables table at the end.

## Frameworks

The following frameworks are supported by Thundra:
Expand Down Expand Up @@ -332,6 +338,7 @@ Check out [this part](https://thundra.readme.io/docs/how-to-warmup) in our docs
| THUNDRA_AGENT_LAMBDA_TRACE_FIREHOSE_REQUEST_ENABLE | bool | false |
| THUNDRA_AGENT_LAMBDA_TRACE_CLOUDWATCHLOG_REQUEST_ENABLE | bool | false |
| THUNDRA_AGENT_LAMBDA_AWS_STEPFUNCTIONS | bool | false |
| THUNDRA_AGENT_LAMBDA_AWS_APPSYNC | bool | false |
| THUNDRA_AGENT_APPLICATION_ID | string | - |
| THUNDRA_AGENT_APPLICATION_INSTANCEID | string | - |
| THUNDRA_AGENT_APPLICATION_REGION | string | - |
Expand Down
4 changes: 4 additions & 0 deletions src/config/ConfigMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export const ConfigMetadata: {[key: string]: { type: string, defaultValue?: any
type: 'boolean',
defaultValue: false,
},
[ConfigNames.THUNDRA_LAMBDA_AWS_APPSYNC]: {
type: 'boolean',
defaultValue: false,
},
[ConfigNames.THUNDRA_TRACE_INTEGRATIONS_HTTP_BODY_MASK]: {
type: 'boolean',
defaultValue: false,
Expand Down
2 changes: 2 additions & 0 deletions src/config/ConfigNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ConfigNames {
'thundra.agent.lambda.trace.cloudwatchlog.request.enable';
public static readonly THUNDRA_LAMBDA_AWS_STEPFUNCTIONS: string =
'thundra.agent.lambda.aws.stepfunctions';
public static readonly THUNDRA_LAMBDA_AWS_APPSYNC: string =
'thundra.agent.lambda.aws.appsync';

/////////////////////////////////////////////////////////////////////////////

Expand Down
32 changes: 32 additions & 0 deletions src/wrappers/lambda/LambdaExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ export function finishInvocation(pluginContext: PluginContext, execContext: Exec

// Inject step functions trace links
injectStepFunctionInfo(originalEvent, response, execContext);
// Inject appsync trace id
injectAppsyncInfo(originalEvent, response, execContext);

invocationData.finishTimestamp = finishTimestamp;
invocationData.duration = finishTimestamp - startTimestamp;
Expand Down Expand Up @@ -333,6 +335,36 @@ function injectTriggerTags(span: ThundraSpan, pluginContext: PluginContext, exec
}
}

function injectAppsyncInfo(request: any, response: any, execContext: ExecutionContext): any {
try {
const isAppsync = ConfigProvider.get<boolean>(ConfigNames.THUNDRA_LAMBDA_AWS_APPSYNC);
ThundraLogger.debug(
'<LambdaExecutor> Checked whether AWS Appsync support is enabled for transaction',
execContext.transactionId, ':', isAppsync);
if (isAppsync) {
const traceId = execContext.traceId;
if (typeof response === 'object' && response !== null) {
const thundraTraceKey = {
trace_id: traceId,
};
ThundraLogger.debug(
'<LambdaExecutor> Injected Thundra AppSync trace key for transaction',
execContext.transactionId, ':', thundraTraceKey);
response[THUNDRA_TRACE_KEY] = thundraTraceKey;
} else {
ThundraLogger.debug(
'<LambdaExecutor> Since response is not object, \
skipped Thundra AppSync trace key injection for transaction',
execContext.transactionId);
}

InvocationTraceSupport.addOutgoingTraceLink(traceId);
}
} catch (error) {
ThundraLogger.error('<LambdaExecutor> Failed to inject appsync trace id:', error);
}
}

function injectStepFunctionInfo(request: any, response: any, execContext: ExecutionContext): any {
try {
const isStepFunction = ConfigProvider.get<boolean>(ConfigNames.THUNDRA_LAMBDA_AWS_STEPFUNCTIONS);
Expand Down

0 comments on commit de17311

Please sign in to comment.