private void AfterWrappedMethod(IScope scope, object output = null, Exception handlerException = null)
        {
            try
            {
                if (output != null && scope != null)
                {
                    var tags = IOParser.ParseResponse(output);
                    tags.Remove("newrelic");
                    AddTagsToActiveSpan(scope.Span, "response", tags);
                }

                if (handlerException != null && scope != null)
                {
                    scope.Span.SetException(handlerException);
                }
            }
            catch (Exception exception)
            {
                Logger.Log(message: exception.ToString(), level: "ERROR");
            }
            if (scope != null)
            {
                scope.Dispose();
            }
        }
        private IScope BeforeWrappedMethod(string name, ILambdaContext lambdaContext, ISpanContext distributedTraceContext, object input = null)
        {
            // Should we use  _tracer.ScopeManager.Active instead?  It returns null if none is active;
            IScope scope = null;

            try
            {
                var tags           = IOParser.ParseRequest(input);
                var extractAdapter = new TextMapExtractAdapter(tags);
                var spanContext    = distributedTraceContext ?? _tracer.Extract(BuiltinFormats.TextMap, extractAdapter);
                tags.Remove("newrelic");
                scope = _tracer
                        .BuildSpan(name)
                        .AsChildOf(spanContext)
                        .WithTag("aws.requestId", lambdaContext.AwsRequestId ?? string.Empty)
                        .WithTag("aws.arn", lambdaContext.InvokedFunctionArn ?? string.Empty)
                        .StartActive();

                DetectColdStart(scope, ref _isColdStart);

                if (input != null)
                {
                    AddTagsToActiveSpan(scope.Span, "request", tags);
                }
            }
            catch (Exception exception)
            {
                Logger.Log(message: exception.ToString(), level: "ERROR");
            }

            return(scope);
        }