public void CaptureException()

in src/Elastic.Apm/Model/Span.cs [691:864]


		public void CaptureException(Exception exception, string culprit = null, bool isHandled = false, string parentId = null,
			Dictionary<string, Label> labels = null
		)
			=> ExecutionSegmentCommon.CaptureException(
				exception,
				_logger,
				_payloadSender,
				this,
				Configuration,
				_enclosingTransaction,
				_apmServerInfo,
				culprit,
				isHandled,
				parentId ?? (ShouldBeSentToApmServer ? null : _enclosingTransaction.Id),
				labels
			);

		public void CaptureSpan(string name, string type, Action<ISpan> capturedAction, string subType = null, string action = null,
			bool isExitSpan = false, IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links),
				capturedAction);

		public void CaptureSpan(string name, string type, Action capturedAction, string subType = null, string action = null, bool isExitSpan = false,
			IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links),
				capturedAction);

		public T CaptureSpan<T>(string name, string type, Func<ISpan, T> func, string subType = null, string action = null, bool isExitSpan = false,
			IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public T CaptureSpan<T>(string name, string type, Func<T> func, string subType = null, string action = null, bool isExitSpan = false,
			IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public Task CaptureSpan(string name, string type, Func<Task> func, string subType = null, string action = null, bool isExitSpan = false,
			IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public Task CaptureSpan(string name, string type, Func<ISpan, Task> func, string subType = null, string action = null,
			bool isExitSpan = false, IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public Task<T> CaptureSpan<T>(string name, string type, Func<Task<T>> func, string subType = null, string action = null,
			bool isExitSpan = false, IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public Task<T> CaptureSpan<T>(string name, string type, Func<ISpan, Task<T>> func, string subType = null, string action = null,
			bool isExitSpan = false, IEnumerable<SpanLink> links = null
		)
			=> ExecutionSegmentCommon.CaptureSpan(StartSpanInternal(name, type, subType, action, isExitSpan: isExitSpan, links: links), func);

		public void CaptureError(string message, string culprit, StackFrame[] frames, string parentId = null, Dictionary<string, Label> labels = null)
			=> ExecutionSegmentCommon.CaptureError(
				message,
				culprit,
				frames,
				_payloadSender,
				_logger,
				this,
				Configuration,
				_enclosingTransaction,
				_apmServerInfo,
				parentId ?? (ShouldBeSentToApmServer ? null : _enclosingTransaction.Id),
				labels
			);

		private void DeduceServiceTarget()
		{
			if (!IsExitSpan)
				return;

			// In order to avoid the creation of Context, set target and resource
			// on the top level DroppedSpanStatCache and return.
			if (!_context.IsValueCreated && !IsExitSpan && _isDropped)
			{
				if (DroppedSpanStatCache == null)
				{
					var type = !string.IsNullOrEmpty(Subtype) ? Subtype : Type;
					DroppedSpanStatCache = new DroppedSpanStatCacheStruct(Target.TargetWithType(type), type);
					return;
				}
			}

			if (Context.Http != null)
			{
				var destination = DeduceHttpDestination();
				if (destination == null)
					// In case of invalid destination just return
					return;

				CopyMissingProperties(destination);
			}

			FillDestinationService();

			// Fills Context.Destination.Service
			void FillDestinationService()
			{
				if (!IsExitSpan)
					return;

				if (_context.IsValueCreated && !string.IsNullOrEmpty(_context.Value.Destination?.Service?.Resource))
					return;

				if (_context.IsValueCreated && _context.Value.Service?.Target != null)
				{
					// Nothing to do here.
					// If "Service.Target" is already set, the inference mechanism should not override it.
					// We need to make sure though to set "Destination.Service.Resource" before exiting.
				}
				else
				{
					var type = !string.IsNullOrEmpty(Subtype) ? Subtype : Type;

					if (Context.Db != null)
					{
						Context.Service = Context.Db.Instance != null
							? new SpanService(new Target(type, Context.Db.Instance))
							: new SpanService(Target.TargetWithType(type));
					}
					else if (Context.Message != null)
					{
						Context.Service = !string.IsNullOrEmpty(Context.Message.Queue?.Name)
							? new SpanService(new Target(type, Context.Message.Queue.Name))
							: new SpanService(Target.TargetWithType(type));
					}
					else if (Context.Http?.Url != null)
					{
						if (!string.IsNullOrEmpty(_context?.Value?.Http?.Url))
						{
							try
							{
								var uri = Context.Http.OriginalUrl ?? new Uri(Context.Http.Url);
								Context.Service =
									new SpanService(new Target(type, UrlUtils.ExtractService(uri, this), true));
							}
							catch
							{
								Context.Service = new SpanService(Target.TargetWithType(type));
							}
						}
						else
							Context.Service = new SpanService(Target.TargetWithType(type));
					}
					else
						Context.Service = new SpanService(Target.TargetWithType(type));
				}

				Context.Destination ??= new Destination();
				Context.Destination.Service = new Destination.DestinationService
				{
					Resource = Context.Service.Target.ToDestinationServiceResource()
				};
			}

			void CopyMissingProperties(Destination src)
			{
				if (src == null)
					return;

				if (Context.Destination == null)
					Context.Destination = src;
				else
					Context.Destination.CopyMissingPropertiesFrom(src);
			}
		}