private void OnStop()
        {
            var activity = Activity.Current;

            if (activity is null)
            {
                Logger.Trace()?.Log("Current activity is null - exiting");
                return;
            }

            if (!_processingSegments.TryRemove(activity.Id, out var span))
            {
                Logger.Trace()
                ?.Log(
                    "Could not find segment for activity {ActivityId} in tracked segments",
                    activity.Id);
                return;
            }

            if (span.Context.Destination is null)
            {
                var urlTag = activity.Tags.FirstOrDefault(t => t.Key == "url").Value;
                if (FileShareUrl.TryCreate(urlTag, out var fileShareUrl))
                {
                    span.Name += $" {fileShareUrl.ResourceName}";
                    SetDestination(span, fileShareUrl);
                }
            }

            span.Outcome = Outcome.Success;
            span.End();
        }
 private static void SetDestination(ISpan span, FileShareUrl fileShareUrl) =>
 span.Context.Destination = new Destination
 {
     Address = fileShareUrl.FullyQualifiedNamespace,
     Service = new Destination.DestinationService {
         Resource = $"{AzureFileStorage.SubType}/{fileShareUrl.StorageAccountName}"
     }
 };
Example #3
0
        public static bool TryCreate(string url, out FileShareUrl fileShareUrl)
        {
            if (Uri.TryCreate(url, UriKind.Absolute, out var uri))
            {
                fileShareUrl = new FileShareUrl(uri);
                return(true);
            }

            fileShareUrl = null;
            return(false);
        }
Example #4
0
        private void OnStart(KeyValuePair <string, object> kv, string action)
        {
            var currentSegment = ApmAgent.GetCurrentExecutionSegment();

            if (currentSegment is null)
            {
                Logger.Trace()?.Log("No current transaction or span - exiting");
                return;
            }

            if (!(kv.Value is Activity activity))
            {
                Logger.Trace()?.Log("Value is not an activity - exiting");
                return;
            }

            var urlTag       = activity.Tags.FirstOrDefault(t => t.Key == "url").Value;
            var fileShareUrl = new FileShareUrl(new Uri(urlTag));
            var spanName     = $"{AzureFileStorage.SpanName} {action} {fileShareUrl.ResourceName}";

            var span = currentSegment.StartSpan(spanName, ApiConstants.TypeStorage, AzureFileStorage.SubType, action);

            if (span is Span realSpan)
            {
                realSpan.InstrumentationFlag = InstrumentationFlag.Azure;
            }

            span.Context.Destination = new Destination
            {
                Address = fileShareUrl.FullyQualifiedNamespace,
                Service = new Destination.DestinationService
                {
                    Name     = AzureFileStorage.SubType,
                    Resource = $"{AzureFileStorage.SubType}/{fileShareUrl.StorageAccountName}",
                    Type     = ApiConstants.TypeStorage
                }
            };

            if (!_processingSegments.TryAdd(activity.Id, span))
            {
                Logger.Trace()
                ?.Log(
                    "Could not add {Action} span {SpanId} for activity {ActivityId} to tracked spans",
                    action,
                    span.Id,
                    activity.Id);
            }
        }
        private void OnStart(KeyValuePair <string, object> kv, string action)
        {
            var currentSegment = ApmAgent.GetCurrentExecutionSegment();

            if (currentSegment is null)
            {
                Logger.Trace()?.Log("No current transaction or span - exiting");
                return;
            }

            if (!(kv.Value is Activity activity))
            {
                Logger.Trace()?.Log("Value is not an activity - exiting");
                return;
            }

            var urlTag   = activity.Tags.FirstOrDefault(t => t.Key == "url").Value;
            var spanName = FileShareUrl.TryCreate(urlTag, out var fileShareUrl)
                                ? $"{AzureFileStorage.SpanName} {action} {fileShareUrl.ResourceName}"
                                : $"{AzureFileStorage.SpanName} {action}";

            var span = currentSegment.StartSpan(spanName, ApiConstants.TypeStorage, AzureFileStorage.SubType, action, true);

            if (span is Span realSpan)
            {
                realSpan.InstrumentationFlag = InstrumentationFlag.Azure;
            }

            if (fileShareUrl != null)
            {
                SetDestination(span, fileShareUrl);
            }

            if (!_processingSegments.TryAdd(activity.Id, span))
            {
                Logger.Trace()
                ?.Log(
                    "Could not add {Action} span {SpanId} for activity {ActivityId} to tracked spans",
                    action,
                    span.Id,
                    activity.Id);
            }
        }