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())); }
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)); }
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())); }
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); } }
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); } }
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); } }
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))); }
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); }
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); }
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); }
internal static CallTargetState StartInvocationTwoParameters <TArg1, TArg2>(ILambdaExtensionRequest requestBuilder, TArg1 payload, TArg2 context) { var dict = GetTraceContext(context); return(StartInvocation(requestBuilder, payload, dict)); }
internal static CallTargetState StartInvocationWithoutEvent(ILambdaExtensionRequest requestBuilder) { return(StartInvocation(requestBuilder, DefaultJson, null)); }
internal static CallTargetState StartInvocation <TArg>(ILambdaExtensionRequest requestBuilder, TArg payload, IDictionary <string, string> context) { var json = SerializeObject(payload); return(new CallTargetState(NotifyExtensionStart(requestBuilder, json, context))); }
internal static TReturn EndInvocationAsync <TReturn>(TReturn returnValue, Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder) { scope?.Dispose(); Flush(); NotifyExtensionEnd(requestBuilder, exception != null); return(returnValue); }
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); }
internal static CallTargetReturn EndInvocationVoid(Exception exception, Scope scope, ILambdaExtensionRequest requestBuilder) { scope?.Dispose(); Flush(); NotifyExtensionEnd(requestBuilder, scope, exception != null); return(CallTargetReturn.GetDefault()); }
internal static bool SendEndInvocation(ILambdaExtensionRequest requestBuilder, bool isError) { var request = requestBuilder.GetEndInvocationRequest(isError); return(ValidateOKStatus((HttpWebResponse)request.GetResponse())); }