예제 #1
0
        internal static bool SendEndInvocation(ILambdaExtensionRequest requestBuilder, Scope scope, bool isError, string data)
        {
            var request = requestBuilder.GetEndInvocationRequest(scope, isError);

            WriteRequestPayload(request, data);
            return(ValidateOKStatus((HttpWebResponse)request.GetResponse()));
        }
예제 #2
0
        internal static CallTargetState StartInvocationOneParameter <TArg>(ILambdaExtensionRequest requestBuilder, TArg eventOrContext)
        {
            var dict = GetTraceContext(eventOrContext);

            if (dict != null)
            {
                return(StartInvocation(requestBuilder, DefaultJson, dict));
            }

            return(StartInvocation(requestBuilder, eventOrContext, null));
        }
예제 #3
0
        internal static bool SendStartInvocation(ILambdaExtensionRequest requestBuilder, string data)
        {
            var request   = requestBuilder.GetStartInvocationRequest();
            var byteArray = Encoding.UTF8.GetBytes(data ?? DefaultJson);

            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            return(ValidateOKStatus((HttpWebResponse)request.GetResponse()));
        }
예제 #4
0
 private static void NotifyExtensionEnd(ILambdaExtensionRequest requestBuilder, Scope scope, bool isError, string json = DefaultJson)
 {
     try
     {
         if (!SendEndInvocation(requestBuilder, scope, isError, json))
         {
             Serverless.Debug("Extension does not send a status 200 OK");
         }
     }
     catch (Exception ex)
     {
         Serverless.Error("Could not send payload to the extension", ex);
     }
 }
예제 #5
0
 internal static void NotifyExtensionStart(ILambdaExtensionRequest requestBuilder, string json)
 {
     try
     {
         if (!SendStartInvocation(requestBuilder, json))
         {
             Serverless.Debug("Extension does not send a status 200 OK");
         }
     }
     catch (Exception ex)
     {
         Serverless.Error("Could not send payload to the extension", ex);
     }
 }
예제 #6
0
 internal static void NotifyExtensionEnd(ILambdaExtensionRequest requestBuilder, bool isError)
 {
     try
     {
         if (!SendEndInvocation(requestBuilder, isError))
         {
             Serverless.Debug("Extension does not send a status 200 OK");
         }
     }
     catch (Exception ex)
     {
         Serverless.Error("Could not send payload to the extension", ex);
     }
 }
예제 #7
0
        internal static CallTargetState StartInvocation <TArg>(TArg payload, ILambdaExtensionRequest requestBuilder)
        {
            var json = DefaultJson;

            try
            {
                json = JsonConvert.SerializeObject(payload);
            }
            catch (Exception)
            {
                Serverless.Debug("Could not serialize input");
            }

            NotifyExtensionStart(requestBuilder, json);
            return(new CallTargetState(CreatePlaceholderScope(Tracer.Instance, requestBuilder)));
        }
예제 #8
0
        internal static Scope SendStartInvocation(ILambdaExtensionRequest requestBuilder, string data, IDictionary <string, string> context)
        {
            var request = requestBuilder.GetStartInvocationRequest();

            WriteRequestPayload(request, data);
            WriteRequestHeaders(request, context);
            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            var             traceId          = response.Headers.Get(DDHttpHeaderNames.TraceId);
            var             samplingPriority = response.Headers.Get(DDHttpHeaderNames.SamplingPriority);

            if (ValidateOKStatus(response))
            {
                return(CreatePlaceholderScope(Tracer.Instance, traceId, samplingPriority));
            }

            return(null);
        }
예제 #9
0
        private static Scope NotifyExtensionStart(ILambdaExtensionRequest requestBuilder, string json, IDictionary <string, string> context)
        {
            Scope scope = null;

            try
            {
                scope = SendStartInvocation(requestBuilder, json, context);
                if (scope == null)
                {
                    Serverless.Debug("Error while creating the scope");
                }
            }
            catch (Exception ex)
            {
                Serverless.Error("Could not send payload to the extension", ex);
            }

            return(scope);
        }
예제 #10
0
        internal static Scope CreatePlaceholderScope(Tracer tracer, ILambdaExtensionRequest requestBuilder)
        {
            Scope scope = null;

            try
            {
                var request = requestBuilder.GetTraceContextRequest();
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    var traceId = response.Headers.Get(HttpHeaderNames.TraceId);
                    // need to set the exact same spanId so nested spans (auto-instrumentation or manual) will have the correct parent-id
                    var spanId = response.Headers.Get(HttpHeaderNames.SpanId);
                    Serverless.Debug($"received traceId = {traceId} and spanId = {spanId}");
                    var span = tracer.StartSpan(PlaceholderOperationName, null, serviceName: PlaceholderServiceName, traceId: Convert.ToUInt64(traceId), spanId: Convert.ToUInt64(spanId), addToTraceContext: false);
                    scope = tracer.TracerManager.ScopeManager.Activate(span, false);
                }
            }
            catch (Exception ex)
            {
                Serverless.Error("Error creating the placeholder scope", ex);
            }

            return(scope);
        }
예제 #11
0
        internal static CallTargetState StartInvocationTwoParameters <TArg1, TArg2>(ILambdaExtensionRequest requestBuilder, TArg1 payload, TArg2 context)
        {
            var dict = GetTraceContext(context);

            return(StartInvocation(requestBuilder, payload, dict));
        }
예제 #12
0
 internal static CallTargetState StartInvocationWithoutEvent(ILambdaExtensionRequest requestBuilder)
 {
     return(StartInvocation(requestBuilder, DefaultJson, null));
 }
예제 #13
0
        internal static CallTargetState StartInvocation <TArg>(ILambdaExtensionRequest requestBuilder, TArg payload, IDictionary <string, string> context)
        {
            var json = SerializeObject(payload);

            return(new CallTargetState(NotifyExtensionStart(requestBuilder, json, context)));
        }
예제 #14
0
 internal static TReturn EndInvocationAsync <TReturn>(TReturn returnValue, Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder)
 {
     scope?.Dispose();
     Flush();
     NotifyExtensionEnd(requestBuilder, exception != null);
     return(returnValue);
 }
예제 #15
0
        internal static TReturn EndInvocationAsync <TReturn>(TReturn returnValue, Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder)
        {
            var json = SerializeObject(returnValue);

            Flush();
            NotifyExtensionEnd(requestBuilder, scope, exception != null, json);
            scope?.Dispose();
            return(returnValue);
        }
예제 #16
0
 internal static CallTargetReturn EndInvocationVoid(Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder)
 {
     scope?.Dispose();
     Flush();
     NotifyExtensionEnd(requestBuilder, scope, exception != null);
     return(CallTargetReturn.GetDefault());
 }
예제 #17
0
        internal static bool SendEndInvocation(ILambdaExtensionRequest requestBuilder, bool isError)
        {
            var request = requestBuilder.GetEndInvocationRequest(isError);

            return(ValidateOKStatus((HttpWebResponse)request.GetResponse()));
        }