public void TransformSpans(LambdaRootSpan rootSpan) { lock (_spanReservoirLock) { // Record errors after root span has finished. By now, txn name has been set foreach (LambdaSpan lambdaSpan in _spanReservoir) { _errors.RecordErrors(lambdaSpan); } var arnTag = rootSpan.GetTag("aws.arn"); var arn = (arnTag as string) ?? ""; LinkedList <Event> spans; // Do not collect Spans if sampled=false, clear reservoir and set spans to empty list if (rootSpan.PrioritySamplingState.Sampled) { spans = _spanReservoir; } else { spans = new LinkedList <Event>(); } _spanReservoir = new LinkedList <Event>(); TransactionEvent txnEvent = new TransactionEvent(rootSpan); var errorEvents = _errors.GetAndClearEvents(); var errorTraces = _errors.GetAndClearTraces(); WriteData(arn, _executionEnv, spans.ToList(), txnEvent, errorEvents, errorTraces); } }
public ISpan StartManual() { LambdaTracer tracer = LambdaTracer.Instance as LambdaTracer; ISpan activeSpan = tracer.ActiveSpan; ISpanContext parentSpanContext = null; if (!_ignoreActiveSpan && _parent == null && activeSpan != null) { AddReference(References.ChildOf, activeSpan.Context); parentSpanContext = activeSpan.Context; } else if (_parent != null) { parentSpanContext = _parent; } LambdaSpan parentSpan = null; if (parentSpanContext is LambdaSpanContext) { parentSpan = ((LambdaSpanContext)parentSpanContext).GetSpan(); } var guid = GuidGenerator.GenerateNewRelicGuid(); LambdaSpan newSpan; if (parentSpan != null) { newSpan = new LambdaSpan(_operationName, DateTimeOffset.UtcNow, _tags, parentSpan, guid); } else { var rootSpan = new LambdaRootSpan(_operationName, DateTimeOffset.UtcNow, _tags, guid, new DataCollector(_logger, tracer.DebugMode), new TransactionState(), new PrioritySamplingState(), new DistributedTracingState()); if (parentSpanContext is LambdaPayloadContext payloadContext) { rootSpan.ApplyLambdaPayloadContext(payloadContext); } else { rootSpan.ApplyAdaptiveSampling(tracer.AdaptiveSampler); } newSpan = rootSpan; } LambdaSpanContext spanContext = new LambdaSpanContext(newSpan); newSpan.SetContext(spanContext); return(newSpan); }
public LambdaSpan(string operationName, DateTimeOffset timestamp, IDictionary <string, object> tags, LambdaSpan parentSpan, string guid) { _type = "Span"; _operationName = operationName; TimeStamp = timestamp; Tags = tags; _guid = guid; SpanLog = new Dictionary <string, LogEntry>(); if (parentSpan != null) { _parentId = parentSpan.Guid(); RootSpan = parentSpan.RootSpan; } else { //This is the root span _parentId = null; RootSpan = (LambdaRootSpan)this; } }
public void TransformSpans(LambdaRootSpan rootSpan) { lock (_spanReservoirLock) { // Record errors after root span has finished. By now, txn name has been set foreach (LambdaSpan lambdaSpan in _spanReservoir) { _errors.RecordErrors(lambdaSpan); } var arnTag = rootSpan.GetTag("aws.arn"); var arn = (arnTag as string) ?? ""; LinkedList <Event> spans; // Do not collect Spans if sampled=false, clear reservoir and set spans to empty list if (rootSpan.PrioritySamplingState.Sampled) { spans = _spanReservoir; } else { spans = new LinkedList <Event>(); } _spanReservoir = new LinkedList <Event>(); TransactionEvent txnEvent = new TransactionEvent(rootSpan); var errorEvents = _errors.GetAndClearEvents(); var errorTraces = _errors.GetAndClearTraces(); var(payload, data) = PreparePayload(arn, _executionEnv, spans.ToList(), txnEvent, errorEvents, errorTraces); // If named pipe exists we want to send the payload there instead of writing to standard out, overwriting any previous data. if (_fileSystemManager.Exists(_namedPipePath)) { _fileSystemManager.WriteAllText(_namedPipePath, payload); return; } WriteData(payload, data); } }