/// <inheritdoc/> public ISpan Start() { Trace.ISpan span = null; SpanCreationOptions options = null; if (this.explicitStartTime != null || this.links != null) { options = new SpanCreationOptions { StartTimestamp = this.explicitStartTime ?? default, Links = this.links, }; } // If specified, this takes precedence. if (this.ignoreActiveSpan) { span = this.tracer.StartRootSpan(this.spanName, this.spanKind, options); } else if (this.parentSpan != null) { span = this.tracer.StartSpan(this.spanName, this.parentSpan, this.spanKind, options); } else if (this.parentSpanContext != null && this.parentSpanContext.IsValid) { span = this.tracer.StartSpan(this.spanName, this.parentSpanContext, this.spanKind, options); } else if (this.parentSpan == null && (this.parentSpanContext == null || !this.parentSpanContext.IsValid) && (this.tracer.CurrentSpan == null || this.tracer.CurrentSpan == Trace.BlankSpan.Instance)) { // We need to know if we should inherit an existing Activity-based context or start a new one. if (System.Diagnostics.Activity.Current != null && System.Diagnostics.Activity.Current.IdFormat == System.Diagnostics.ActivityIdFormat.W3C) { var currentActivity = System.Diagnostics.Activity.Current; if (this.rootOperationNamesForActivityBasedAutoCollectors.Contains(currentActivity.OperationName)) { this.tracer.StartSpanFromActivity(this.spanName, currentActivity, this.spanKind, this.links); span = this.tracer.CurrentSpan; } } } if (span == null) { span = this.tracer.StartSpan(this.spanName, null, this.spanKind, options); } foreach (var kvp in this.attributes) { span.SetAttribute(kvp); } if (this.error) { span.Status = Trace.Status.Unknown; } return(new SpanShim(span)); }
public SpanShim(Trace.ISpan span) { this.Span = span ?? throw new ArgumentNullException(nameof(span)); if (this.Span.Context == null) { throw new ArgumentNullException(nameof(this.Span.Context)); } this.spanContextShim = new SpanContextShim(this.Span.Context); }
/// <inheritdoc/> public ISpanBuilder AsChildOf(ISpan parent) { if (parent == null) { return(this); } if (!this.ParentSet) { this.parentSpan = GetOpenTelemetrySpan(parent); return(this); } return(this.AsChildOf(parent.Context)); }
public ScopeAdapter(Trace.ISpan span, Action disposeAction = null) { this.Span = new SpanShim(span); this.disposeAction = disposeAction; }