private static void Flush() { try { // here we need a sync flush, since the lambda environment can be destroy after each invocation // 3 seconds is enough to send payload to the extension (via localhost) Tracer.Instance.TracerManager.AgentWriter.FlushTracesAsync().Wait(TimeSpan.FromSeconds(ServerlessMaxWaitingFlushTime)); } catch (Exception ex) { Serverless.Error("Could not flush 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); } }
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); } }
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); }
/// <summary> /// Initializes global instrumentation values. /// </summary> public static void Initialize() { if (Interlocked.Exchange(ref _firstInitialization, 0) != 1) { // Initialize() was already called before return; } Log.Debug("Initialization started."); try { Log.Debug("Enabling by ref instrumentation."); NativeMethods.EnableByRefInstrumentation(); Log.Information("ByRef instrumentation enabled."); } catch (Exception ex) { Log.Error(ex, "ByRef instrumentation cannot be enabled: "); } try { Log.Debug("Enabling calltarget state by ref."); NativeMethods.EnableCallTargetStateByRef(); Log.Information("CallTarget State ByRef enabled."); } catch (Exception ex) { Log.Error(ex, "CallTarget state ByRef cannot be enabled: "); } try { Log.Debug("Sending CallTarget integration definitions to native library."); var payload = InstrumentationDefinitions.GetAllDefinitions(); NativeMethods.InitializeProfiler(payload.DefinitionsId, payload.Definitions); foreach (var def in payload.Definitions) { def.Dispose(); } Log.Information <int>("The profiler has been initialized with {count} definitions.", payload.Definitions.Length); } catch (Exception ex) { Log.Error(ex, ex.Message); } try { Serverless.InitIfNeeded(); } catch (Exception ex) { Serverless.Error("Error while loading Serverless definitions", ex); } try { Log.Debug("Sending CallTarget derived integration definitions to native library."); var payload = InstrumentationDefinitions.GetDerivedDefinitions(); NativeMethods.AddDerivedInstrumentations(payload.DefinitionsId, payload.Definitions); foreach (var def in payload.Definitions) { def.Dispose(); } Log.Information <int>("The profiler has been initialized with {count} derived definitions.", payload.Definitions.Length); } catch (Exception ex) { Log.Error(ex, ex.Message); } InitializeNoNativeParts(); Log.Debug("Initialization finished."); }
/// <summary> /// Initializes global instrumentation values. /// </summary> public static void Initialize() { if (Interlocked.Exchange(ref _firstInitialization, 0) != 1) { // Initialize() was already called before return; } Log.Debug("Initialization started."); try { Log.Debug("Enabling by ref instrumentation."); NativeMethods.EnableByRefInstrumentation(); Log.Information("ByRef instrumentation enabled."); } catch (Exception ex) { Log.Error(ex, "ByRef instrumentation cannot be enabled: "); } try { Log.Debug("Enabling calltarget state by ref."); NativeMethods.EnableCallTargetStateByRef(); Log.Information("CallTarget State ByRef enabled."); } catch (Exception ex) { Log.Error(ex, "CallTarget state ByRef cannot be enabled: "); } try { Log.Debug("Sending CallTarget integration definitions to native library."); var payload = InstrumentationDefinitions.GetAllDefinitions(); NativeMethods.InitializeProfiler(payload.DefinitionsId, payload.Definitions); foreach (var def in payload.Definitions) { def.Dispose(); } Log.Information <int>("The profiler has been initialized with {count} definitions.", payload.Definitions.Length); } catch (Exception ex) { Log.Error(ex, ex.Message); } try { Serverless.InitIfNeeded(); } catch (Exception ex) { Serverless.Error("Error while loading Serverless definitions", ex); } try { Log.Debug("Sending CallTarget derived integration definitions to native library."); var payload = InstrumentationDefinitions.GetDerivedDefinitions(); NativeMethods.AddDerivedInstrumentations(payload.DefinitionsId, payload.Definitions); foreach (var def in payload.Definitions) { def.Dispose(); } Log.Information <int>("The profiler has been initialized with {count} derived definitions.", payload.Definitions.Length); } catch (Exception ex) { Log.Error(ex, ex.Message); } try { Log.Debug("Initializing TraceAttribute instrumentation."); var payload = InstrumentationDefinitions.GetTraceAttributeDefinitions(); NativeMethods.AddTraceAttributeInstrumentation(payload.DefinitionsId, payload.AssemblyName, payload.TypeName); Log.Information("TraceAttribute instrumentation enabled with Assembly={AssemblyName} and Type={TypeName}.", payload.AssemblyName, payload.TypeName); } catch (Exception ex) { Log.Error(ex, ex.Message); } InitializeNoNativeParts(); var tracer = Tracer.Instance; // before this line you should not call anything related to TracerManager.Instance // otherwise you can have multiple instances of Tracer if (tracer is null) { Log.Debug("Skipping TraceMethods initialization because Tracer.Instance was null after InitializeNoNativeParts was invoked"); } else { try { Log.Debug("Initializing TraceMethods instrumentation."); var traceMethodsConfiguration = tracer.Settings.TraceMethods; var payload = InstrumentationDefinitions.GetTraceMethodDefinitions(); NativeMethods.InitializeTraceMethods(payload.DefinitionsId, payload.AssemblyName, payload.TypeName, traceMethodsConfiguration); Log.Information("TraceMethods instrumentation enabled with Assembly={AssemblyName}, Type={TypeName}, and Configuration={}.", payload.AssemblyName, payload.TypeName, traceMethodsConfiguration); } catch (Exception ex) { Log.Error(ex, ex.Message); } } InitializeThreadSampling(); Log.Debug("Initialization finished."); }