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

Commit

Permalink
Fixed handler.ts to load user handler over Thundra core library ins…
Browse files Browse the repository at this point in the history
…tead of loading itself
  • Loading branch information
Serkan ÖZAL committed Jun 1, 2020
1 parent 7b1ef3b commit 59a7a21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/config/ConfigMetadata.ts
Expand Up @@ -59,6 +59,9 @@ export const ConfigMetadata: {[key: string]: { type: string, defaultValue?: any
type: 'boolean',
defaultValue: false,
},
[ConfigNames.THUNDRA_LAMBDA_HANDLER]: {
type: 'string',
},
[ConfigNames.THUNDRA_LAMBDA_WARMUP_WARMUPAWARE]: {
type: 'boolean',
defaultValue: false,
Expand Down
3 changes: 3 additions & 0 deletions src/config/ConfigNames.ts
Expand Up @@ -45,6 +45,9 @@ class ConfigNames {

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

public static readonly THUNDRA_LAMBDA_HANDLER: string =
'thundra.agent.lambda.handler';

public static readonly THUNDRA_LAMBDA_WARMUP_WARMUPAWARE: string =
'thundra.agent.lambda.warmup.warmupaware';

Expand Down
18 changes: 5 additions & 13 deletions src/handler.ts
@@ -1,19 +1,11 @@
'use strict';

import { loadHandler } from './runtime/RuntimeSupport';
import Utils from './plugins/utils/Utils';
import { EnvVariableKeys } from './Constants';
const thundra = require('@thundra/core');
const thundraWrapper = thundra();

const HANDLER_ENV_VAR = 'thundra_agent_lambda_handler';

const thundra = require('@thundra/core')();
const userHandler = loadHandler(
Utils.getEnvVar(EnvVariableKeys.LAMBDA_TASK_ROOT),
Utils.getEnvVar(HANDLER_ENV_VAR),
);

const wrappedUserFunc = thundra(userHandler);
const userHandler = thundra.loadUserHandler();
const wrappedUserHandler = thundraWrapper(userHandler);

exports.wrapper = (event: any, context: any, callback: any) => {
return wrappedUserFunc(event, context, callback);
return wrappedUserHandler(event, context, callback);
};
11 changes: 11 additions & 0 deletions src/index.ts
Expand Up @@ -33,6 +33,7 @@ import ErrorAwareSampler from './opentracing/sampler/ErrorAwareSampler';
import TimeAwareSampler from './opentracing/sampler/TimeAwareSampler';
import { SamplerCompositionOperator } from './opentracing/sampler/CompositeSampler';
import ConfigNames from './config/ConfigNames';
import { loadHandler } from './runtime/RuntimeSupport';

const ThundraWarmup = require('@thundra/warmup');
const get = require('lodash.get');
Expand Down Expand Up @@ -198,3 +199,13 @@ module.exports.listeners = {
CompositeSpanFilter,
StandardSpanFilterer,
};

/**
* Must be called after "ConfigProvider" is initialized either
* - by calling directly "ConfigProvider.init(...)"
* - or by calling indirectly default exported function of this module
*/
module.exports.loadUserHandler = () => loadHandler(
Utils.getEnvVar(EnvVariableKeys.LAMBDA_TASK_ROOT),
ConfigProvider.get(ConfigNames.THUNDRA_LAMBDA_HANDLER),
);

0 comments on commit 59a7a21

Please sign in to comment.